From 787a12b2fc52cd8051354eb15c009759587e0c82 Mon Sep 17 00:00:00 2001 From: Rabeea Abu-Saleh Date: Fri, 30 Aug 2019 09:04:58 +0300 Subject: [PATCH] Adding Scoring Profile search tests (#43) Adding test: searchWithScoringProfileBoostsScore() --- .../azure-search-data/src/test/README.md | 2 +- .../azure/search/data/SearchAsyncTests.java | 15 ++++++ .../azure/search/data/SearchSyncTests.java | 15 ++++++ .../com/azure/search/data/SearchTestBase.java | 3 ++ .../searchWithScoringProfileBoostsScore.json | 51 +++++++++++++++++++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 sdk/search/azure-search-data/src/test/resources/session-records/searchWithScoringProfileBoostsScore.json diff --git a/sdk/search/azure-search-data/src/test/README.md b/sdk/search/azure-search-data/src/test/README.md index ae47275b92a14..d299d9a41a98d 100644 --- a/sdk/search/azure-search-data/src/test/README.md +++ b/sdk/search/azure-search-data/src/test/README.md @@ -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 diff --git a/sdk/search/azure-search-data/src/test/java/com/azure/search/data/SearchAsyncTests.java b/sdk/search/azure-search-data/src/test/java/com/azure/search/data/SearchAsyncTests.java index 1c76b6fbe1efd..31b27106eae84 100644 --- a/sdk/search/azure-search-data/src/test/java/com/azure/search/data/SearchAsyncTests.java +++ b/sdk/search/azure-search-data/src/test/java/com/azure/search/data/SearchAsyncTests.java @@ -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 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> results = client.search("*", new SearchParameters().minimumCoverage(50.0), new SearchRequestOptions()).byPage(); diff --git a/sdk/search/azure-search-data/src/test/java/com/azure/search/data/SearchSyncTests.java b/sdk/search/azure-search-data/src/test/java/com/azure/search/data/SearchSyncTests.java index 85ec7f5f4b0c3..7d2eaa816510c 100644 --- a/sdk/search/azure-search-data/src/test/java/com/azure/search/data/SearchSyncTests.java +++ b/sdk/search/azure-search-data/src/test/java/com/azure/search/data/SearchSyncTests.java @@ -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> 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 results = client diff --git a/sdk/search/azure-search-data/src/test/java/com/azure/search/data/SearchTestBase.java b/sdk/search/azure-search-data/src/test/java/com/azure/search/data/SearchTestBase.java index f377bfb1dc397..56124f522fe38 100644 --- a/sdk/search/azure-search-data/src/test/java/com/azure/search/data/SearchTestBase.java +++ b/sdk/search/azure-search-data/src/test/java/com/azure/search/data/SearchTestBase.java @@ -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 indexActions); diff --git a/sdk/search/azure-search-data/src/test/resources/session-records/searchWithScoringProfileBoostsScore.json b/sdk/search/azure-search-data/src/test/resources/session-records/searchWithScoringProfileBoostsScore.json new file mode 100644 index 0000000000000..a4dc74c42d2b6 --- /dev/null +++ b/sdk/search/azure-search-data/src/test/resources/session-records/searchWithScoringProfileBoostsScore.json @@ -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": [] +}