Skip to content

Commit

Permalink
search with top and skip test (Azure#33)
Browse files Browse the repository at this point in the history
TestCanUseTopAndSkipForClientSidePaging
  • Loading branch information
navalev authored Aug 20, 2019
1 parent 91251e5 commit 8c3ec95
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
import org.junit.Assert;
import org.junit.Test;
import reactor.test.StepVerifier;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class AsyncSearchTests extends SearchIndexClientTestBase {

Expand Down Expand Up @@ -69,4 +72,29 @@ public void testCanSearchDynamicDocuments() {
Assert.assertEquals(nextPage.nextLink(), null);
}).verifyComplete();
}

@Test
public void testCanUseTopAndSkipForClientSidePaging() {
List<String> orderBy = Stream.of("HotelId").collect(Collectors.toList());
SearchParameters parameters = new SearchParameters().top(3).skip(0).orderBy(orderBy);

PagedFlux<SearchResult> results = asyncClient.search("*", parameters, new SearchRequestOptions());
assertKeySequenceEqual(results, Arrays.asList("1", "10", "100"));

parameters = parameters.skip(3);
results = asyncClient.search("*", parameters, new SearchRequestOptions());
assertKeySequenceEqual(results, Arrays.asList("11", "12", "13"));
}

private void assertKeySequenceEqual(PagedFlux<SearchResult> results, List<String> expectedKeys) {
Assert.assertNotNull(results);

List<String> actualKeys = results.log()
.filter(doc -> doc.additionalProperties().containsKey("HotelId"))
.map(doc -> (String) doc.additionalProperties().get("HotelId"))
.collectList()
.block();

Assert.assertEquals(expectedKeys, actualKeys);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"networkCallRecords": [
{
"Method": "POST",
"Uri": "https://azs-sdkdab542155648.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": "ac307865-5f47-40d9-82b4-e0de8354f59a",
"StatusCode": "200",
"Date": "Mon, 19 Aug 2019 12:44:49 GMT",
"Strict-Transport-Security": "max-age=15724800; includeSubDomains",
"Cache-Control": "no-cache",
"elapsed-time": "238",
"OData-Version": "4.0",
"Expires": "-1",
"Content-Length": "6556",
"Body": "{\"@odata.context\":\"https://azs-sdkdab542155648.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},{\"key\":\"11\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"12\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"13\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"14\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"15\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"16\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"17\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"18\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"19\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"20\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"21\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"22\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"23\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"24\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"25\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"26\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"27\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"28\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"29\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"30\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"31\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"32\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"33\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"34\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"35\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"36\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"37\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"38\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"39\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"40\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"41\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"42\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"43\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"44\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"45\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"46\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"47\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"48\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"49\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"50\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"51\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"52\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"53\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"54\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"55\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"56\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"57\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"58\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"59\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"60\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"61\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"62\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"63\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"64\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"65\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"66\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"67\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"68\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"69\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"70\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"71\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"72\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"73\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"74\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"75\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"76\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"77\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"78\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"79\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"80\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"81\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"82\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"83\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"84\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"85\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"86\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"87\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"88\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"89\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"90\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"91\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"92\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"93\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"94\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"95\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"96\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"97\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"98\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"99\",\"status\":true,\"errorMessage\":null,\"statusCode\":201},{\"key\":\"100\",\"status\":true,\"errorMessage\":null,\"statusCode\":201}]}",
"Preference-Applied": "odata.include-annotations=\"*\"",
"Content-Type": "application/json; odata.metadata=minimal"
}
},
{
"Method": "POST",
"Uri": "https://azs-sdkdab542155648.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": "893384ad-8a7b-4cb4-9e1e-df39d5651058",
"StatusCode": "200",
"Date": "Mon, 19 Aug 2019 12:45:01 GMT",
"Strict-Transport-Security": "max-age=15724800; includeSubDomains",
"Cache-Control": "no-cache",
"elapsed-time": "75",
"OData-Version": "4.0",
"Expires": "-1",
"Content-Length": "3936",
"Body": "{\"@odata.context\":\"https://azs-sdkdab542155648.search.windows.net/indexes('hotels')/$metadata#docs(*)\",\"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\":\"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\"]}]},{\"@search.score\":1.0,\"HotelId\":\"100\",\"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"
}
},
{
"Method": "POST",
"Uri": "https://azs-sdkdab542155648.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": "cd6defdf-3e60-4ea8-9b12-5ebcfed5b839",
"StatusCode": "200",
"Date": "Mon, 19 Aug 2019 12:45:07 GMT",
"Strict-Transport-Security": "max-age=15724800; includeSubDomains",
"Cache-Control": "no-cache",
"elapsed-time": "7",
"OData-Version": "4.0",
"Expires": "-1",
"Content-Length": "2017",
"Body": "{\"@odata.context\":\"https://azs-sdkdab542155648.search.windows.net/indexes('hotels')/$metadata#docs(*)\",\"value\":[{\"@search.score\":1.0,\"HotelId\":\"11\",\"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\":\"12\",\"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\":\"13\",\"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\":[]}]}",
"Preference-Applied": "odata.include-annotations=\"*\"",
"Content-Type": "application/json; odata.metadata=minimal"
}
}
],
"variables": []
}

0 comments on commit 8c3ec95

Please sign in to comment.