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 36165309bd464..2ca75d385cc41 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 @@ -209,6 +209,14 @@ public void testDefaultSearchModeIsAny() { .verifyComplete(); } + @Override + public void testCanGetResultCountInSearch() { + Flux> results = client.search("*", new SearchParameters().includeTotalResultCount(true), new SearchRequestOptions()).byPage(); + StepVerifier.create(results) + .assertNext(res -> Assert.assertEquals(hotels.size(), ((SearchPagedResponse) res).count().intValue())) + .verifyComplete(); + } + private void assertResponse(SearchPagedResponse response, List> actualResults) { Assert.assertNull(response.count()); Assert.assertNull(response.coverage()); 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 efcb01e491841..8a1c1e356b1f6 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 @@ -209,6 +209,16 @@ public void testDefaultSearchModeIsAny() { } + @Override + public void testCanGetResultCountInSearch() { + PagedIterable results = client.search("*", new SearchParameters().includeTotalResultCount(true), new SearchRequestOptions()); + Assert.assertNotNull(results); + Iterator> resultsIterator = results.iterableByPage().iterator(); + + Assert.assertEquals(hotels.size(), ((SearchPagedResponse) resultsIterator.next()).count().intValue()); + Assert.assertFalse(resultsIterator.hasNext()); + } + private List> getSearchResults(PagedIterable results) { Iterator> iterator = results.iterableByPage().iterator(); List> searchResults = new ArrayList<>(); 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 4df3e9264f20d..857a67f0b1c3d 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 @@ -174,6 +174,9 @@ public void searchThrowsWhenRequestIsMalformed() { @Test public abstract void testDefaultSearchModeIsAny(); + @Test + public abstract void testCanGetResultCountInSearch(); + 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/testCanGetResultCountInSearch.json b/sdk/search/azure-search-data/src/test/resources/session-records/testCanGetResultCountInSearch.json new file mode 100644 index 0000000000000..6deff970b2f9e --- /dev/null +++ b/sdk/search/azure-search-data/src/test/resources/session-records/testCanGetResultCountInSearch.json @@ -0,0 +1,48 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdkd2343250d024.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" : "1e70364e-9fff-4a9b-909d-38b09f415f7c", + "StatusCode" : "200", + "Date" : "Wed, 21 Aug 2019 14:34:45 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "150", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "795", + "Body" : "{\"@odata.context\":\"https://azs-sdkd2343250d024.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-sdkd2343250d024.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" : "1d9f4f93-2d72-4e35-8526-af2daa862d21", + "StatusCode" : "200", + "Date" : "Wed, 21 Aug 2019 14:34:46 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "22", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "7210", + "Body" : "{\"@odata.context\":\"https://azs-sdkd2343250d024.search.windows.net/indexes('hotels')/$metadata#docs(*)\",\"@odata.count\":10,\"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" : [ ] +} \ No newline at end of file