Skip to content

Commit

Permalink
Adding a test for search with minimum coverage (Azure#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabee333 authored Aug 27, 2019
1 parent 1a4f15c commit 16e8861
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ public void canSearchWithEscapedSpecialCharsInRegex() {
Assert.assertEquals(0, searchResultsList.size());
}

@Override
public void canSearchWithMinimumCoverage() {
Flux<PagedResponse<SearchResult>> results = client.search("*", new SearchParameters().minimumCoverage(50.0), new SearchRequestOptions()).byPage();
Assert.assertNotNull(results);

StepVerifier.create(results)
.assertNext(res -> Assert.assertEquals(100.0, ((SearchPagedResponse) res).coverage(), 0))
.verifyComplete();
}

private void assertResponse(SearchPagedResponse response, List<Map<String, Object>> actualResults) {
Assert.assertNull(response.count());
Assert.assertNull(response.coverage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,16 @@ public void canSearchWithEscapedSpecialCharsInRegex() {
Assert.assertEquals(0, resultsList.size());
}

@Override
public void canSearchWithMinimumCoverage() {
PagedIterable<SearchResult> results = client
.search("*", new SearchParameters().minimumCoverage(50.0), new SearchRequestOptions());
Assert.assertNotNull(results);

Iterator<PagedResponse<SearchResult>> resultsIterator = results.iterableByPage().iterator();
Assert.assertEquals(100.0, ((SearchPagedResponse) resultsIterator.next()).coverage(), 0);
}

private List<Map<String, Object>> getSearchResults(PagedIterable<SearchResult> results) {
Iterator<PagedResponse<SearchResult>> iterator = results.iterableByPage().iterator();
List<Map<String, Object>> searchResults = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ public void searchThrowsWhenRequestIsMalformed() {
@Test
public abstract void canSearchWithEscapedSpecialCharsInRegex();

@Test
public abstract void canSearchWithMinimumCoverage();

@Test
public void searchThrowsWhenSpecialCharInRegexIsUnescaped() {
thrown.expect(HttpResponseException.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"networkCallRecords" : [ {
"Method" : "POST",
"Uri" : "https://azs-sdk86121831cd09.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" : "240e7a4b-6502-48f3-9188-a5efcb803a18",
"StatusCode" : "200",
"Date" : "Mon, 26 Aug 2019 11:05:47 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"elapsed-time" : "129",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "795",
"Body" : "{\"@odata.context\":\"https://azs-sdk86121831cd09.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-sdk86121831cd09.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" : "659f213c-3330-42ea-8cf2-eed50879d91f",
"StatusCode" : "200",
"Date" : "Mon, 26 Aug 2019 11:05:49 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"elapsed-time" : "38",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "7217",
"Body" : "{\"@odata.context\":\"https://azs-sdk86121831cd09.search.windows.net/indexes('hotels')/$metadata#docs(*)\",\"@search.coverage\":100.0,\"value\":[{\"@search.score\":1.0,\"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\":[]},{\"@search.score\":1.0,\"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\":1.0,\"HotelId\":\"3\",\"HotelName\":\"EconoStay\",\"Description\":\"Very popular hotel in town\",\"Description_fr\":\"H\\u00f4tel le plus populaire en ville\",\"Category\":\"Budget\",\"Tags\":[\"wifi\",\"budget\"],\"ParkingIncluded\":true,\"SmokingAllowed\":false,\"LastRenovationDate\":\"1995-07-01T00:00:00Z\",\"Rating\":4,\"Location\":{\"type\":\"Point\",\"coordinates\":[-122.131577,49.678581],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}},\"Address\":null,\"Rooms\":[]},{\"@search.score\":1.0,\"HotelId\":\"4\",\"HotelName\":\"Express Rooms\",\"Description\":\"Pretty good hotel\",\"Description_fr\":\"Assez bon h\\u00f4tel\",\"Category\":\"Budget\",\"Tags\":[\"wifi\",\"budget\"],\"ParkingIncluded\":true,\"SmokingAllowed\":false,\"LastRenovationDate\":\"1995-07-01T00:00:00Z\",\"Rating\":4,\"Location\":{\"type\":\"Point\",\"coordinates\":[-122.131577,48.678581],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}},\"Address\":null,\"Rooms\":[]},{\"@search.score\":1.0,\"HotelId\":\"5\",\"HotelName\":\"Comfy Place\",\"Description\":\"Another good hotel\",\"Description_fr\":\"Un autre bon h\\u00f4tel\",\"Category\":\"Budget\",\"Tags\":[\"wifi\",\"budget\"],\"ParkingIncluded\":true,\"SmokingAllowed\":false,\"LastRenovationDate\":\"2012-08-12T00:00:00Z\",\"Rating\":4,\"Location\":{\"type\":\"Point\",\"coordinates\":[-122.131577,48.678581],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}},\"Address\":null,\"Rooms\":[]},{\"@search.score\":1.0,\"HotelId\":\"6\",\"HotelName\":null,\"Description\":\"Surprisingly expensive. Model suites have an ocean-view.\",\"Description_fr\":null,\"Category\":null,\"Tags\":[],\"ParkingIncluded\":null,\"SmokingAllowed\":null,\"LastRenovationDate\":null,\"Rating\":null,\"Location\":null,\"Address\":null,\"Rooms\":[]},{\"@search.score\":1.0,\"HotelId\":\"7\",\"HotelName\":\"Modern Stay\",\"Description\":\"Modern architecture, very polite staff and very clean. Also very affordable.\",\"Description_fr\":\"Architecture moderne, personnel poli et tr\\u00e8s propre. Aussi tr\\u00e8s abordable.\",\"Category\":null,\"Tags\":[],\"ParkingIncluded\":null,\"SmokingAllowed\":null,\"LastRenovationDate\":null,\"Rating\":null,\"Location\":null,\"Address\":null,\"Rooms\":[]},{\"@search.score\":1.0,\"HotelId\":\"8\",\"HotelName\":null,\"Description\":\"Has some road noise and is next to the very police station. Bathrooms had morel coverings.\",\"Description_fr\":\"Il y a du bruit de la route et se trouve \\u00e0 c\\u00f4t\\u00e9 de la station de police. Les salles de bain avaient des rev\\u00eatements de morilles.\",\"Category\":null,\"Tags\":[],\"ParkingIncluded\":null,\"SmokingAllowed\":null,\"LastRenovationDate\":null,\"Rating\":null,\"Location\":null,\"Address\":null,\"Rooms\":[]},{\"@search.score\":1.0,\"HotelId\":\"9\",\"HotelName\":\"Secret Point Motel\",\"Description\":\"The hotel is ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Time's Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.\",\"Description_fr\":\"L'h\\u00f4tel est id\\u00e9alement situ\\u00e9 sur la principale art\\u00e8re commerciale de la ville en plein c\\u0153ur de New York. A quelques minutes se trouve la place du temps et le centre historique de la ville, ainsi que d'autres lieux d'int\\u00e9r\\u00eat qui font de New York l'une des villes les plus attractives et cosmopolites de l'Am\\u00e9rique.\",\"Category\":\"Boutique\",\"Tags\":[\"pool\",\"air conditioning\",\"concierge\"],\"ParkingIncluded\":false,\"SmokingAllowed\":null,\"LastRenovationDate\":\"1970-01-18T00:00:00Z\",\"Rating\":4,\"Location\":{\"type\":\"Point\",\"coordinates\":[-73.975403,40.760586],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}},\"Address\":{\"StreetAddress\":\"677 5th Ave\",\"City\":\"New York\",\"StateProvince\":\"NY\",\"PostalCode\":\"10022\",\"Country\":\"USA\"},\"Rooms\":[{\"Description\":\"Budget Room, 1 Queen Bed (Cityside)\",\"Description_fr\":\"Chambre \\u00c9conomique, 1 grand lit (c\\u00f4t\\u00e9 ville)\",\"Type\":\"Budget Room\",\"BaseRate\":9.69,\"BedOptions\":\"1 Queen Bed\",\"SleepsCount\":2,\"SmokingAllowed\":true,\"Tags\":[\"vcr/dvd\"]},{\"Description\":\"Budget Room, 1 King Bed (Mountain View)\",\"Description_fr\":\"Chambre \\u00c9conomique, 1 tr\\u00e8s grand lit (Mountain View)\",\"Type\":\"Budget Room\",\"BaseRate\":8.09,\"BedOptions\":\"1 King Bed\",\"SleepsCount\":2,\"SmokingAllowed\":true,\"Tags\":[\"vcr/dvd\",\"jacuzzi tub\"]}]},{\"@search.score\":1.0,\"HotelId\":\"10\",\"HotelName\":\"Countryside Hotel\",\"Description\":\"Save up to 50% off traditional hotels. Free WiFi, great location near downtown, full kitchen, washer & dryer, 24/7 support, bowling alley, fitness center and more.\",\"Description_fr\":\"\\u00c9conomisez jusqu'\\u00e0 50% sur les h\\u00f4tels traditionnels. WiFi gratuit, tr\\u00e8s bien situ\\u00e9 pr\\u00e8s du centre-ville, cuisine compl\\u00e8te, laveuse & s\\u00e9cheuse, support 24/7, bowling, centre de fitness et plus encore.\",\"Category\":\"Budget\",\"Tags\":[\"24-hour front desk service\",\"coffee in lobby\",\"restaurant\"],\"ParkingIncluded\":false,\"SmokingAllowed\":true,\"LastRenovationDate\":\"1999-09-06T00:00:00Z\",\"Rating\":3,\"Location\":{\"type\":\"Point\",\"coordinates\":[-78.940483,35.90416],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}},\"Address\":{\"StreetAddress\":\"6910 Fayetteville Rd\",\"City\":\"Durham\",\"StateProvince\":\"NC\",\"PostalCode\":\"27713\",\"Country\":\"USA\"},\"Rooms\":[{\"Description\":\"Suite, 1 King Bed (Amenities)\",\"Description_fr\":\"Suite, 1 tr\\u00e8s grand lit (Services)\",\"Type\":\"Suite\",\"BaseRate\":2.44,\"BedOptions\":\"1 King Bed\",\"SleepsCount\":2,\"SmokingAllowed\":true,\"Tags\":[\"coffee maker\"]},{\"Description\":\"Budget Room, 1 Queen Bed (Amenities)\",\"Description_fr\":\"Chambre \\u00c9conomique, 1 grand lit (Services)\",\"Type\":\"Budget Room\",\"BaseRate\":7.69,\"BedOptions\":\"1 Queen Bed\",\"SleepsCount\":2,\"SmokingAllowed\":false,\"Tags\":[\"coffee maker\"]}]}]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal"
}
} ],
"variables" : [ ]
}

0 comments on commit 16e8861

Please sign in to comment.