Skip to content

Commit

Permalink
Adding Scoring Profile search tests (Azure#43)
Browse files Browse the repository at this point in the history
Adding test: searchWithScoringProfileBoostsScore()
  • Loading branch information
rabee333 authored Aug 30, 2019
1 parent 16e8861 commit 787a12b
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sdk/search/azure-search-data/src/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Before running the tests on PLAYBACK mode, you need to run them on RECORD mode t

To run tests in Playback mode:

1. Set the value of the **AZURE_TEST_MODE** environment variable to *'RECORD'* (or delete it). You can also delete all other environment variables.
1. Set the value of the **AZURE_TEST_MODE** environment variable to *'PLAYBACK'* (or delete it). You can also delete all other environment variables.
2. Run the tests.

## Example of creating test environment in Azure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,21 @@ public void canSearchWithEscapedSpecialCharsInRegex() {
Assert.assertEquals(0, searchResultsList.size());
}

@Override
public void searchWithScoringProfileBoostsScore() {
SearchParameters searchParameters = new SearchParameters()
.scoringProfile("nearest")
.scoringParameters(Arrays.asList("myloc-'-122','49'"))
.filter("Rating eq 5 or Rating eq 1");

Flux<SearchResult> response = client.search("hotel", searchParameters, new SearchRequestOptions()).log();

StepVerifier.create(response)
.assertNext(res -> Assert.assertEquals("2", getSearchResultId(res, "HotelId")))
.assertNext(res -> Assert.assertEquals("1", getSearchResultId(res, "HotelId")))
.verifyComplete();
}

@Override
public void canSearchWithMinimumCoverage() {
Flux<PagedResponse<SearchResult>> results = client.search("*", new SearchParameters().minimumCoverage(50.0), new SearchRequestOptions()).byPage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,21 @@ public void canSearchWithEscapedSpecialCharsInRegex() {
Assert.assertEquals(0, resultsList.size());
}

@Override
public void searchWithScoringProfileBoostsScore() {
SearchParameters searchParameters = new SearchParameters()
.scoringProfile("nearest")
.scoringParameters(Arrays.asList("myloc-'-122','49'"))
.filter("Rating eq 5 or Rating eq 1");

List<Map<String, Object>> response = getSearchResults(
client.search("hotel", searchParameters, new SearchRequestOptions()));
Assert.assertEquals(2, response.size());
Assert.assertEquals(
Arrays.asList("2", "1"),
response.stream().map(res -> res.get("HotelId").toString()).collect(Collectors.toList()));
}

@Override
public void canSearchWithMinimumCoverage() {
PagedIterable<SearchResult> results = client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ public void searchThrowsWhenSpecialCharInRegexIsUnescaped() {
search("/.*/.*/", invalidSearchParameters, new SearchRequestOptions());
}

@Test
public abstract void searchWithScoringProfileBoostsScore();

abstract void search(String searchText, SearchParameters searchParameters, SearchRequestOptions searchRequestOptions);

abstract void indexDocuments(List<IndexAction> indexActions);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"networkCallRecords": [
{
"Method": "POST",
"Uri": "https://azs-sdk0dc45984d559.search.windows.net/indexes('hotels')/docs/search.index?api-version=2019-05-06",
"Headers": {
"Content-Type": "application/json; charset=utf-8"
},
"Response": {
"Pragma": "no-cache",
"retry-after": "0",
"request-id": "12df1dae-aa08-4d8d-bfcf-bf4eac0895b1",
"StatusCode": "200",
"Date": "Sun, 25 Aug 2019 09:52:54 GMT",
"Strict-Transport-Security": "max-age=15724800; includeSubDomains",
"Cache-Control": "no-cache",
"elapsed-time": "110",
"OData-Version": "4.0",
"Expires": "-1",
"Content-Length": "795",
"Body": "{\"@odata.context\":\"https://azs-sdk0dc45984d559.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.IndexResult)\",\"value\":[{\"key\":\"1\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"2\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"3\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"4\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"5\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"6\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"7\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"8\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"9\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"10\",\"status\":true,\"errorMessage\":null,\"statusCode\":201}]}",
"Preference-Applied": "odata.include-annotations=\"*\"",
"Content-Type": "application/json; odata.metadata=minimal"
}
},
{
"Method": "POST",
"Uri": "https://azs-sdk0dc45984d559.search.windows.net/indexes('hotels')/docs/search.post.search?api-version=2019-05-06",
"Headers": {
"Content-Type": "application/json; charset=utf-8"
},
"Response": {
"Pragma": "no-cache",
"retry-after": "0",
"request-id": "7512e13d-4676-47c6-9258-0d0bfc85c960",
"StatusCode": "200",
"Date": "Sun, 25 Aug 2019 09:53:21 GMT",
"Strict-Transport-Security": "max-age=15724800; includeSubDomains",
"Cache-Control": "no-cache",
"elapsed-time": "84",
"OData-Version": "4.0",
"Expires": "-1",
"Content-Length": "1574",
"Body": "{\"@odata.context\":\"https://azs-sdk0dc45984d559.search.windows.net/indexes('hotels')/$metadata#docs(*)\",\"value\":[{\"@search.score\":0.17984489,\"HotelId\":\"2\",\"HotelName\":\"Roach Motel\",\"Description\":\"Cheapest hotel in town. Infact, a motel.\",\"Description_fr\":\"H\\u00f4tel le moins cher en ville. Infact, un motel.\",\"Category\":\"Budget\",\"Tags\":[\"motel\",\"budget\"],\"ParkingIncluded\":true,\"SmokingAllowed\":true,\"LastRenovationDate\":\"1982-04-28T00:00:00Z\",\"Rating\":1,\"Location\":{\"type\":\"Point\",\"coordinates\":[-122.131577,49.678581],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}},\"Address\":null,\"Rooms\":[]},{\"@search.score\":0.11593714,\"HotelId\":\"1\",\"HotelName\":\"Fancy Stay\",\"Description\":\"Best hotel in town if you like luxury hotels. They have an amazing infinity pool, a spa, and a really helpful concierge. The location is perfect -- right downtown, close to all the tourist attractions. We highly recommend this hotel.\",\"Description_fr\":\"Meilleur h\\u00f4tel en ville si vous aimez les h\\u00f4tels de luxe. Ils ont une magnifique piscine \\u00e0 d\\u00e9bordement, un spa et un concierge tr\\u00e8s utile. L'emplacement est parfait \\u2013 en plein centre, \\u00e0 proximit\\u00e9 de toutes les attractions touristiques. Nous recommandons fortement cet h\\u00f4tel.\",\"Category\":\"Luxury\",\"Tags\":[\"pool\",\"view\",\"wifi\",\"concierge\"],\"ParkingIncluded\":false,\"SmokingAllowed\":false,\"LastRenovationDate\":\"2010-06-27T00:00:00Z\",\"Rating\":5,\"Location\":{\"type\":\"Point\",\"coordinates\":[-122.131577,47.678581],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}},\"Address\":null,\"Rooms\":[]}]}",
"Preference-Applied": "odata.include-annotations=\"*\"",
"Content-Type": "application/json; odata.metadata=minimal"
}
}
],
"variables": []
}

0 comments on commit 787a12b

Please sign in to comment.