diff --git a/sdk/search/azure-search-data/src/main/java/com/azure/search/data/SearchIndexAsyncClient.java b/sdk/search/azure-search-data/src/main/java/com/azure/search/data/SearchIndexAsyncClient.java index ce0b202dd7e30..206039ab69719 100644 --- a/sdk/search/azure-search-data/src/main/java/com/azure/search/data/SearchIndexAsyncClient.java +++ b/sdk/search/azure-search-data/src/main/java/com/azure/search/data/SearchIndexAsyncClient.java @@ -5,8 +5,8 @@ import com.azure.core.http.rest.PagedFlux; import com.azure.search.data.customization.Document; +import com.azure.search.data.generated.models.AutocompleteItem; import com.azure.search.data.generated.models.AutocompleteParameters; -import com.azure.search.data.generated.models.AutocompleteResult; import com.azure.search.data.generated.models.DocumentIndexResult; import com.azure.search.data.generated.models.IndexBatch; import com.azure.search.data.generated.models.SearchParameters; @@ -148,7 +148,7 @@ public interface SearchIndexAsyncClient { * @param suggesterName suggester name * @return auto complete result */ - Mono autocomplete(String searchText, String suggesterName); + PagedFlux autocomplete(String searchText, String suggesterName); /** * Autocompletes incomplete query terms based on input text and matching terms in the Azure Search index. @@ -159,5 +159,5 @@ public interface SearchIndexAsyncClient { * @param autocompleteParameters auto complete parameters * @return auto complete result */ - Mono autocomplete(String searchText, String suggesterName, SearchRequestOptions searchRequestOptions, AutocompleteParameters autocompleteParameters); + PagedFlux autocomplete(String searchText, String suggesterName, SearchRequestOptions searchRequestOptions, AutocompleteParameters autocompleteParameters); } diff --git a/sdk/search/azure-search-data/src/main/java/com/azure/search/data/SearchIndexClient.java b/sdk/search/azure-search-data/src/main/java/com/azure/search/data/SearchIndexClient.java index 04303705c556d..448d8d168624d 100644 --- a/sdk/search/azure-search-data/src/main/java/com/azure/search/data/SearchIndexClient.java +++ b/sdk/search/azure-search-data/src/main/java/com/azure/search/data/SearchIndexClient.java @@ -5,8 +5,8 @@ import com.azure.core.http.rest.PagedIterable; import com.azure.search.data.customization.Document; +import com.azure.search.data.generated.models.AutocompleteItem; import com.azure.search.data.generated.models.AutocompleteParameters; -import com.azure.search.data.generated.models.AutocompleteResult; import com.azure.search.data.generated.models.DocumentIndexResult; import com.azure.search.data.generated.models.IndexBatch; import com.azure.search.data.generated.models.SearchParameters; @@ -146,7 +146,7 @@ public interface SearchIndexClient { * @param suggesterName suggester name * @return auto complete result */ - AutocompleteResult autocomplete(String searchText, String suggesterName); + PagedIterable autocomplete(String searchText, String suggesterName); /** * Autocompletes incomplete query terms based on input text and matching terms in the Azure Search index. @@ -157,5 +157,5 @@ public interface SearchIndexClient { * @param autocompleteParameters auto complete parameters * @return auto complete result */ - AutocompleteResult autocomplete(String searchText, String suggesterName, SearchRequestOptions searchRequestOptions, AutocompleteParameters autocompleteParameters); + PagedIterable autocomplete(String searchText, String suggesterName, SearchRequestOptions searchRequestOptions, AutocompleteParameters autocompleteParameters); } diff --git a/sdk/search/azure-search-data/src/main/java/com/azure/search/data/common/AutoCompletePagedResponse.java b/sdk/search/azure-search-data/src/main/java/com/azure/search/data/common/AutoCompletePagedResponse.java new file mode 100644 index 0000000000000..84cbc6ae080d7 --- /dev/null +++ b/sdk/search/azure-search-data/src/main/java/com/azure/search/data/common/AutoCompletePagedResponse.java @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.search.data.common; + +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.implementation.http.PagedResponseBase; +import com.azure.search.data.generated.models.AutocompleteItem; +import com.azure.search.data.generated.models.AutocompleteResult; + +import java.util.stream.Collectors; + +public class AutoCompletePagedResponse extends PagedResponseBase { + + /** + * Constructor + * + * @param autoCompleteResponse an http response with the results + */ + public AutoCompletePagedResponse(SimpleResponse autoCompleteResponse) { + super(autoCompleteResponse.request(), + autoCompleteResponse.statusCode(), + autoCompleteResponse.headers(), + autoCompleteResponse.value().results(), + null, + deserializeHeaders(autoCompleteResponse.headers())); + } + + private static String deserializeHeaders(HttpHeaders headers) { + return headers.toMap().entrySet().stream().map((entry) -> + entry.getKey() + "," + entry.getValue() + ).collect(Collectors.joining(",")); + } +} diff --git a/sdk/search/azure-search-data/src/main/java/com/azure/search/data/customization/SearchIndexAsyncClientImpl.java b/sdk/search/azure-search-data/src/main/java/com/azure/search/data/customization/SearchIndexAsyncClientImpl.java index 21a9b233ca806..f9e816bcfde17 100644 --- a/sdk/search/azure-search-data/src/main/java/com/azure/search/data/customization/SearchIndexAsyncClientImpl.java +++ b/sdk/search/azure-search-data/src/main/java/com/azure/search/data/customization/SearchIndexAsyncClientImpl.java @@ -9,13 +9,15 @@ import com.azure.core.http.rest.PagedFlux; import com.azure.core.http.rest.PagedResponse; import com.azure.search.data.SearchIndexAsyncClient; +import com.azure.search.data.common.AutoCompletePagedResponse; import com.azure.search.data.common.DocumentResponseConversions; import com.azure.search.data.common.SearchPagedResponse; import com.azure.search.data.common.SuggestPagedResponse; import com.azure.search.data.generated.SearchIndexRestClient; import com.azure.search.data.generated.implementation.SearchIndexRestClientBuilder; +import com.azure.search.data.generated.models.AutocompleteItem; import com.azure.search.data.generated.models.AutocompleteParameters; -import com.azure.search.data.generated.models.AutocompleteResult; +import com.azure.search.data.generated.models.AutocompleteRequest; import com.azure.search.data.generated.models.DocumentIndexResult; import com.azure.search.data.generated.models.IndexBatch; import com.azure.search.data.generated.models.SearchParameters; @@ -75,9 +77,9 @@ public class SearchIndexAsyncClientImpl extends SearchIndexBaseClient implements * Package private constructor to be used by {@link SearchIndexClientBuilder} */ SearchIndexAsyncClientImpl( - String searchServiceName, String searchDnsSuffix, String indexName, String apiVersion, - HttpClient httpClient, - List policies) { + String searchServiceName, String searchDnsSuffix, String indexName, String apiVersion, + HttpClient httpClient, + List policies) { if (StringUtils.isBlank(searchServiceName)) { throw new IllegalArgumentException("Invalid searchServiceName"); } @@ -110,14 +112,14 @@ public class SearchIndexAsyncClientImpl extends SearchIndexBaseClient implements private void initialize() { restClient = new SearchIndexRestClientBuilder() - .searchServiceName(searchServiceName) - .indexName(indexName) - .searchDnsSuffix(searchDnsSuffix) - .apiVersion(apiVersion) - .pipeline(new HttpPipelineBuilder() - .httpClient(httpClient) - .policies(policies.toArray(new HttpPipelinePolicy[0])).build()) - .build(); + .searchServiceName(searchServiceName) + .indexName(indexName) + .searchDnsSuffix(searchDnsSuffix) + .apiVersion(apiVersion) + .pipeline(new HttpPipelineBuilder() + .httpClient(httpClient) + .policies(policies.toArray(new HttpPipelinePolicy[0])).build()) + .build(); } @Override @@ -161,13 +163,13 @@ public Mono countDocuments() { public PagedFlux search() { SearchRequest searchRequest = new SearchRequest(); Mono> first = restClient.documents() - .searchPostWithRestResponseAsync(searchRequest) - .map(res -> { - if (res.value().nextPageParameters() != null) { - skip = res.value().nextPageParameters().skip(); - } - return new SearchPagedResponse(res); - }); + .searchPostWithRestResponseAsync(searchRequest) + .map(res -> { + if (res.value().nextPageParameters() != null) { + skip = res.value().nextPageParameters().skip(); + } + return new SearchPagedResponse(res); + }); return new PagedFlux<>(() -> first, nextLink -> searchPostNextWithRestResponseAsync(searchRequest, (String) nextLink)); } @@ -175,38 +177,38 @@ public PagedFlux search() { public PagedFlux search(String searchText, SearchParameters searchParameters, SearchRequestOptions searchRequestOptions) { SearchRequest searchRequest = createSearchRequest(searchText, searchParameters); Mono> first = restClient.documents() - .searchPostWithRestResponseAsync(searchRequest, searchRequestOptions) - .map(res -> { - if (res.value().nextPageParameters() != null) { - skip = res.value().nextPageParameters().skip(); - } - return new SearchPagedResponse(res); - }); + .searchPostWithRestResponseAsync(searchRequest, searchRequestOptions) + .map(res -> { + if (res.value().nextPageParameters() != null) { + skip = res.value().nextPageParameters().skip(); + } + return new SearchPagedResponse(res); + }); return new PagedFlux(() -> first, nextLink -> searchPostNextWithRestResponseAsync(searchRequest, (String) nextLink)); } @Override public Mono getDocument(String key) { return restClient - .documents() - .getAsync(key) - .map(DocumentResponseConversions::cleanupDocument) - .onErrorMap(DocumentResponseConversions::exceptionMapper) - .doOnSuccess(s -> System.out.println("Document with key: " + key + " was retrieved successfully")) - .doOnError(e -> System.out.println("An error occurred in getDocument(key): " + e.getMessage())); + .documents() + .getAsync(key) + .map(DocumentResponseConversions::cleanupDocument) + .onErrorMap(DocumentResponseConversions::exceptionMapper) + .doOnSuccess(s -> System.out.println("Document with key: " + key + " was retrieved successfully")) + .doOnError(e -> System.out.println("An error occurred in getDocument(key): " + e.getMessage())); } @Override public Mono getDocument( - String key, List selectedFields, - SearchRequestOptions searchRequestOptions) { + String key, List selectedFields, + SearchRequestOptions searchRequestOptions) { return restClient - .documents() - .getAsync(key, selectedFields, searchRequestOptions) - .map(DocumentResponseConversions::cleanupDocument) - .onErrorMap(DocumentResponseConversions::exceptionMapper) - .doOnSuccess(s -> System.out.println("Document with key: " + key + "and selectedFields: " + selectedFields.toString() + " was retrieved successfully")) - .doOnError(e -> System.out.println("An error occurred in getDocument(key, selectedFields, searchRequestOptions): " + e.getMessage())); + .documents() + .getAsync(key, selectedFields, searchRequestOptions) + .map(DocumentResponseConversions::cleanupDocument) + .onErrorMap(DocumentResponseConversions::exceptionMapper) + .doOnSuccess(s -> System.out.println("Document with key: " + key + "and selectedFields: " + selectedFields.toString() + " was retrieved successfully")) + .doOnError(e -> System.out.println("An error occurred in getDocument(key, selectedFields, searchRequestOptions): " + e.getMessage())); } @Override @@ -216,10 +218,10 @@ public PagedFlux suggest(String searchText, String suggesterName) @Override public PagedFlux suggest( - String searchText, - String suggesterName, - SuggestParameters suggestParameters, - SearchRequestOptions searchRequestOptions) { + String searchText, + String suggesterName, + SuggestParameters suggestParameters, + SearchRequestOptions searchRequestOptions) { SuggestRequest suggestRequest = createSuggestRequest(searchText, suggesterName, suggestParameters); Mono> first = restClient.documents() .suggestPostWithRestResponseAsync(suggestRequest) @@ -236,21 +238,24 @@ public Mono index(IndexBatch batch) { } @Override - public Mono autocomplete(String searchText, String suggesterName) { - return restClient.documents().autocompleteGetAsync(searchText, suggesterName); + public PagedFlux autocomplete(String searchText, String suggesterName) { + return autocomplete(searchText, suggesterName, null, null); } @Override - public Mono autocomplete( - String searchText, - String suggesterName, - SearchRequestOptions searchRequestOptions, - AutocompleteParameters autocompleteParameters) { - return restClient.documents().autocompleteGetAsync( - searchText, - suggesterName, - searchRequestOptions, - autocompleteParameters); + public PagedFlux autocomplete( + String searchText, + String suggesterName, + SearchRequestOptions searchRequestOptions, + AutocompleteParameters autocompleteParameters) { + + AutocompleteRequest autocompleteRequest = createAutoCompleteRequest(searchText, suggesterName, autocompleteParameters); + Mono> first = restClient.documents() + .autocompletePostWithRestResponseAsync(autocompleteRequest) + .map(res -> { + return new AutoCompletePagedResponse(res); + }); + return new PagedFlux<>(() -> first, nextLink -> Mono.empty()); } /** @@ -268,15 +273,15 @@ private Mono> searchPostNextWithRestResponseAsync(Se return Mono.empty(); } return restClient.documents() - .searchPostWithRestResponseAsync(searchRequest.skip(skip)) - .map(res -> { - if (res.value().nextPageParameters() == null || res.value().nextPageParameters().skip() == null) { - skip = null; - } else { - skip = res.value().nextPageParameters().skip(); - } - return new SearchPagedResponse(res); - }); + .searchPostWithRestResponseAsync(searchRequest.skip(skip)) + .map(res -> { + if (res.value().nextPageParameters() == null || res.value().nextPageParameters().skip() == null) { + skip = null; + } else { + skip = res.value().nextPageParameters().skip(); + } + return new SearchPagedResponse(res); + }); } @@ -291,18 +296,18 @@ private SearchRequest createSearchRequest(String searchText, SearchParameters se SearchRequest searchRequest = new SearchRequest().searchText(searchText); if (searchParameters != null) { searchRequest. - searchMode(searchParameters.searchMode()). - facets(searchParameters.facets()). - filter(searchParameters.filter()). - highlightPostTag(searchParameters.highlightPostTag()). - highlightPreTag(searchParameters.highlightPreTag()). - includeTotalResultCount(searchParameters.includeTotalResultCount()). - minimumCoverage(searchParameters.minimumCoverage()). - queryType(searchParameters.queryType()). - scoringParameters(searchParameters.scoringParameters()). - scoringProfile(searchParameters.scoringProfile()). - skip(searchParameters.skip()). - top(searchParameters.top()); + searchMode(searchParameters.searchMode()). + facets(searchParameters.facets()). + filter(searchParameters.filter()). + highlightPostTag(searchParameters.highlightPostTag()). + highlightPreTag(searchParameters.highlightPreTag()). + includeTotalResultCount(searchParameters.includeTotalResultCount()). + minimumCoverage(searchParameters.minimumCoverage()). + queryType(searchParameters.queryType()). + scoringParameters(searchParameters.scoringParameters()). + scoringProfile(searchParameters.scoringProfile()). + skip(searchParameters.skip()). + top(searchParameters.top()); if (searchParameters.highlightFields() != null) { searchRequest.highlightFields(String.join(",", searchParameters.highlightFields())); } @@ -338,6 +343,7 @@ private SuggestRequest createSuggestRequest(String searchText, String suggesterN highlightPreTag(suggestParameters.highlightPreTag()). minimumCoverage(suggestParameters.minimumCoverage()). top(suggestParameters.top()); + List searchFields = suggestParameters.searchFields(); if (searchFields != null) { suggestRequest.searchFields(String.join(",", searchFields)); @@ -356,4 +362,32 @@ private SuggestRequest createSuggestRequest(String searchText, String suggesterN return suggestRequest; } + + /** + * Create Autocomplete request from search text, suggester name, and parameters + * + * @param searchText search text + * @param suggesterName search text + * @param autocompleteParameters autocomplete parameters + * @return AutocompleteRequest + */ + private AutocompleteRequest createAutoCompleteRequest(String searchText, String suggesterName, AutocompleteParameters autocompleteParameters) { + AutocompleteRequest autoCompleteRequest = new AutocompleteRequest().searchText(searchText).suggesterName(suggesterName); + if (autocompleteParameters != null) { + autoCompleteRequest. + filter(autocompleteParameters.filter()). + useFuzzyMatching(autocompleteParameters.useFuzzyMatching()). + highlightPostTag(autocompleteParameters.highlightPostTag()). + highlightPreTag(autocompleteParameters.highlightPreTag()). + minimumCoverage(autocompleteParameters.minimumCoverage()). + top(autocompleteParameters.top()). + autocompleteMode(autocompleteParameters.autocompleteMode()); + List searchFields = autocompleteParameters.searchFields(); + if (searchFields != null) { + autoCompleteRequest.searchFields(String.join(",", searchFields)); + } + } + + return autoCompleteRequest; + } } diff --git a/sdk/search/azure-search-data/src/main/java/com/azure/search/data/customization/SearchIndexClientImpl.java b/sdk/search/azure-search-data/src/main/java/com/azure/search/data/customization/SearchIndexClientImpl.java index 90fc2267061f4..75a96bfaa774c 100644 --- a/sdk/search/azure-search-data/src/main/java/com/azure/search/data/customization/SearchIndexClientImpl.java +++ b/sdk/search/azure-search-data/src/main/java/com/azure/search/data/customization/SearchIndexClientImpl.java @@ -7,8 +7,8 @@ import com.azure.core.http.rest.PagedIterable; import com.azure.search.data.SearchIndexAsyncClient; import com.azure.search.data.SearchIndexClient; +import com.azure.search.data.generated.models.AutocompleteItem; import com.azure.search.data.generated.models.AutocompleteParameters; -import com.azure.search.data.generated.models.AutocompleteResult; import com.azure.search.data.generated.models.DocumentIndexResult; import com.azure.search.data.generated.models.IndexBatch; import com.azure.search.data.generated.models.SearchParameters; @@ -116,13 +116,15 @@ public DocumentIndexResult index(IndexBatch batch) { } @Override - public AutocompleteResult autocomplete(String searchText, String suggesterName) { - return null; + public PagedIterable autocomplete(String searchText, String suggesterName) { + PagedFlux result = asyncClient.autocomplete(searchText, suggesterName, null, null); + return new PagedIterable<>(result); } @Override - public AutocompleteResult autocomplete(String searchText, String suggesterName, SearchRequestOptions searchRequestOptions, AutocompleteParameters autocompleteParameters) { - return null; + public PagedIterable autocomplete(String searchText, String suggesterName, SearchRequestOptions searchRequestOptions, AutocompleteParameters autocompleteParameters) { + PagedFlux result = asyncClient.autocomplete(searchText, suggesterName, searchRequestOptions, autocompleteParameters); + return new PagedIterable<>(result); } private T blockWithOptionalTimeout(Mono response, @Nullable Duration timeout) { diff --git a/sdk/search/azure-search-data/src/test/java/com/azure/search/data/tests/AutocompleteAsyncTests.java b/sdk/search/azure-search-data/src/test/java/com/azure/search/data/tests/AutocompleteAsyncTests.java new file mode 100644 index 0000000000000..5fd82dca5cc7a --- /dev/null +++ b/sdk/search/azure-search-data/src/test/java/com/azure/search/data/tests/AutocompleteAsyncTests.java @@ -0,0 +1,140 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +package com.azure.search.data.tests; + +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.rest.PagedFlux; +import com.azure.search.data.SearchIndexAsyncClient; +import com.azure.search.data.generated.models.AutocompleteItem; +import com.azure.search.data.generated.models.AutocompleteMode; +import com.azure.search.data.generated.models.AutocompleteParameters; +import io.netty.handler.codec.http.HttpResponseStatus; +import org.junit.Assert; +import reactor.test.StepVerifier; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static com.azure.search.data.tests.SearchTestBase.HOTELS_INDEX_NAME; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class AutocompleteAsyncTests extends AutocompleteTestBase { + + private SearchIndexAsyncClient client; + + @Override + protected void initializeClient() { + client = builderSetup().indexName(HOTELS_INDEX_NAME).buildAsyncClient(); + uploadDocumentsJson(client, HOTELS_INDEX_NAME, HOTELS_DATA_JSON); + } + + @Override + public void autocompleteThrowsWhenGivenBadSuggesterName() throws Exception { + AutocompleteParameters params = new AutocompleteParameters(); + params.autocompleteMode(AutocompleteMode.ONE_TERM); + + PagedFlux results = client.autocomplete("very po", "Invalid suggester", null, params); + StepVerifier + .create(results) + .verifyErrorSatisfies(error -> { + assertEquals(HttpResponseException.class, error.getClass()); + assertEquals(HttpResponseStatus.BAD_REQUEST.code(), ((HttpResponseException) error).response().statusCode()); + assertTrue(error.getMessage().contains("The specified suggester name 'Invalid suggester' does not exist in this index definition.\\r\\nParameter name: name")); + }); + } + + @Override + public void autocompleteDefaultsToOneTermMode() throws Exception { + List expectedText = Arrays.asList("point", "police", "polite", "pool", "popular"); + List expectedQueryPlusText = Arrays.asList("point", "police", "polite", "pool", "popular"); + + PagedFlux results = client.autocomplete("po", "sg"); + validateResults(expectedText, expectedQueryPlusText, results); + } + + @Override + public void autocompleteExcludesFieldsNotInSuggester() throws Exception { + AutocompleteParameters params = new AutocompleteParameters(); + params.autocompleteMode(AutocompleteMode.ONE_TERM); + params.searchFields(Arrays.asList("HotelName")); + + PagedFlux results = client.autocomplete("luxu", "sg", null, params); + Assert.assertNotNull(results); + + StepVerifier.create(results.byPage()).assertNext(pageResult -> { + Assert.assertEquals(0, pageResult.items().size()); + }).verifyComplete(); + } + + @Override + public void autocompleteFuzzyIsOffByDefault() throws Exception { + AutocompleteParameters params = new AutocompleteParameters(); + params.autocompleteMode(AutocompleteMode.ONE_TERM); + + PagedFlux results = client.autocomplete("pi", "sg", null, params); + Assert.assertNotNull(results); + StepVerifier.create(results.byPage()).assertNext(pageResult -> { + Assert.assertEquals(0, pageResult.items().size()); + }).verifyComplete(); + } + + @Override + public void autocompleteOneTerm() throws Exception { + List expectedText = Arrays.asList("point", "police", "polite", "pool", "popular"); + List expectedQueryPlusText = Arrays.asList("point", "police", "polite", "pool", "popular"); + + AutocompleteParameters params = new AutocompleteParameters(); + params.autocompleteMode(AutocompleteMode.ONE_TERM); + + PagedFlux results = client.autocomplete("po", "sg", null, params); + validateResults(expectedText, expectedQueryPlusText, results); + } + + @Override + public void autocompleteStaticallyTypedDocuments() throws Exception { + List expectedText = Arrays.asList("point", "police", "polite", "pool", "popular"); + List expectedQueryPlusText = Arrays.asList("very point", "very police", "very polite", "very pool", "very popular"); + + AutocompleteParameters params = new AutocompleteParameters(); + params.autocompleteMode(AutocompleteMode.ONE_TERM); + params.useFuzzyMatching(false); + + PagedFlux results = client.autocomplete("very po", "sg", null, params); + validateResults(expectedText, expectedQueryPlusText, results); + } + + @Override + public void autocompleteThrowsWhenRequestIsMalformed() throws Exception { + PagedFlux results = client.autocomplete("very po", ""); + StepVerifier + .create(results) + .verifyErrorSatisfies(error -> { + assertEquals(HttpResponseException.class, error.getClass()); + assertEquals(HttpResponseStatus.BAD_REQUEST.code(), ((HttpResponseException) error).response().statusCode()); + assertTrue(error.getMessage().contains("Cannot find fields enabled for suggestions. Please provide a value for 'suggesterName' in the query.\\r\\nParameter name: suggestions")); + }); + } + + /** + * Validate the text and query plus text results + * @param expectedText + * @param expectedQueryPlusText + * @param results + */ + private void validateResults(List expectedText, List expectedQueryPlusText, PagedFlux results) { + StepVerifier.create(results.byPage()).assertNext(pageResult -> { + Assert.assertEquals(5, pageResult.items().size()); + List textResults = new ArrayList<>(); + List queryPlusTextResults = new ArrayList<>(); + pageResult.items() + .forEach(res -> { + textResults.add(res.text()); + queryPlusTextResults.add(res.queryPlusText()); + }); + Assert.assertEquals(expectedText, textResults); + Assert.assertEquals(expectedQueryPlusText, queryPlusTextResults); + }).verifyComplete(); + } +} diff --git a/sdk/search/azure-search-data/src/test/java/com/azure/search/data/tests/AutocompleteSyncTests.java b/sdk/search/azure-search-data/src/test/java/com/azure/search/data/tests/AutocompleteSyncTests.java new file mode 100644 index 0000000000000..4365007e55474 --- /dev/null +++ b/sdk/search/azure-search-data/src/test/java/com/azure/search/data/tests/AutocompleteSyncTests.java @@ -0,0 +1,149 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +package com.azure.search.data.tests; + +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.rest.PagedIterable; +import com.azure.search.data.SearchIndexClient; +import com.azure.search.data.common.AutoCompletePagedResponse; +import com.azure.search.data.generated.models.AutocompleteItem; +import com.azure.search.data.generated.models.AutocompleteMode; +import com.azure.search.data.generated.models.AutocompleteParameters; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + +import static com.azure.search.data.tests.SearchTestBase.HOTELS_INDEX_NAME; + +public class AutocompleteSyncTests extends AutocompleteTestBase { + + private SearchIndexClient client; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Override + protected void initializeClient() { + client = builderSetup().indexName(HOTELS_INDEX_NAME).buildClient(); + + uploadDocumentsJson(client, HOTELS_INDEX_NAME, HOTELS_DATA_JSON); + } + + @Test + public void autocompleteThrowsWhenGivenBadSuggesterName() { + thrown.expect(HttpResponseException.class); + thrown.expectMessage("The specified suggester name 'Invalid suggester' does not exist in this index definition.\\r\\nParameter name: name"); + + AutocompleteParameters params = new AutocompleteParameters(); + params.autocompleteMode(AutocompleteMode.ONE_TERM); + + PagedIterable results = client.autocomplete("very po", "Invalid suggester", null, params); + results.iterableByPage().iterator().next(); + } + + @Test + public void autocompleteDefaultsToOneTermMode() { + List expectedText = Arrays.asList("point", "police", "polite", "pool", "popular"); + List expectedQueryPlusText = Arrays.asList("point", "police", "polite", "pool", "popular"); + + PagedIterable results = client.autocomplete("po", "sg"); + results.iterableByPage().iterator().next(); + + Assert.assertNotNull(results); + validateResults(results, expectedText, expectedQueryPlusText); + } + + @Test + public void autocompleteExcludesFieldsNotInSuggester() throws Exception { + AutocompleteParameters params = new AutocompleteParameters(); + params.autocompleteMode(AutocompleteMode.ONE_TERM); + params.searchFields(Arrays.asList("HotelName")); + + PagedIterable results = client.autocomplete("luxu", "sg", null, params); + Assert.assertNotNull(results); + Assert.assertNotNull(results.iterableByPage().iterator().next()); + List allItems = results.streamByPage().collect(Collectors.toList()); + // One page, with 0 items + Assert.assertEquals(allItems.size(), 1); + Assert.assertEquals(((AutoCompletePagedResponse) allItems.get(0)).items().size(), 0); + } + + @Test + public void autocompleteFuzzyIsOffByDefault() throws Exception { + AutocompleteParameters params = new AutocompleteParameters(); + params.autocompleteMode(AutocompleteMode.ONE_TERM); + + PagedIterable results = client.autocomplete("pi", "sg", null, params); + Assert.assertNotNull(results); + Assert.assertNotNull(results.iterableByPage().iterator().next()); + List allItems = results.streamByPage().collect(Collectors.toList()); + // One page, with 0 items + Assert.assertEquals(allItems.size(), 1); + Assert.assertEquals(((AutoCompletePagedResponse) allItems.get(0)).items().size(), 0); + } + + @Test + public void autocompleteOneTerm() throws Exception { + List expectedText = Arrays.asList("point", "police", "polite", "pool", "popular"); + List expectedQueryPlusText = Arrays.asList("point", "police", "polite", "pool", "popular"); + + AutocompleteParameters params = new AutocompleteParameters(); + params.autocompleteMode(AutocompleteMode.ONE_TERM); + + PagedIterable results = client.autocomplete("po", "sg", null, params); + results.iterableByPage().iterator().next(); + + Assert.assertNotNull(results); + validateResults(results, expectedText, expectedQueryPlusText); + } + + @Test + public void autocompleteStaticallyTypedDocuments() throws Exception { + List expectedText = Arrays.asList("point", "police", "polite", "pool", "popular"); + List expectedQueryPlusText = Arrays.asList("very point", "very police", "very polite", "very pool", "very popular"); + + AutocompleteParameters params = new AutocompleteParameters(); + params.autocompleteMode(AutocompleteMode.ONE_TERM); + params.useFuzzyMatching(false); + + PagedIterable results = client.autocomplete("very po", "sg", null, params); + results.iterableByPage().iterator().next(); + + Assert.assertNotNull(results); + validateResults(results, expectedText, expectedQueryPlusText); + } + + @Test + public void autocompleteThrowsWhenRequestIsMalformed() throws Exception { + thrown.expect(HttpResponseException.class); + thrown.expectMessage("Cannot find fields enabled for suggestions. Please provide a value for 'suggesterName' in the query.\\r\\nParameter name: suggestions"); + + PagedIterable results = client.autocomplete("very po", ""); + results.iterableByPage().iterator().next(); + } + + + /** + * Compare the autocomplete results with the expected strings + * + * @param results + * @param expectedText + * @param expectedQueryPlusText + */ + private void validateResults(PagedIterable results, List expectedText, List expectedQueryPlusText) { + int index = 0; + Iterator it = results.stream().iterator(); + while (it.hasNext()) { + AutocompleteItem item = it.next(); + Assert.assertEquals(expectedText.get(index), item.text()); + Assert.assertEquals(expectedQueryPlusText.get(index), item.queryPlusText()); + index++; + } + } +} diff --git a/sdk/search/azure-search-data/src/test/java/com/azure/search/data/tests/AutocompleteTestBase.java b/sdk/search/azure-search-data/src/test/java/com/azure/search/data/tests/AutocompleteTestBase.java new file mode 100644 index 0000000000000..7d5b4a5fb192b --- /dev/null +++ b/sdk/search/azure-search-data/src/test/java/com/azure/search/data/tests/AutocompleteTestBase.java @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +package com.azure.search.data.tests; + +import com.azure.search.data.env.SearchIndexClientTestBase; +import org.junit.Test; + +public abstract class AutocompleteTestBase extends SearchIndexClientTestBase { + + static final String HOTELS_DATA_JSON = "HotelsDataArray.json"; + + @Override + protected void beforeTest() { + super.beforeTest(); + initializeClient(); + } + + protected abstract void initializeClient(); + + @Test + public abstract void autocompleteThrowsWhenGivenBadSuggesterName() throws Exception; + + @Test + public abstract void autocompleteDefaultsToOneTermMode() throws Exception; + + @Test + public abstract void autocompleteExcludesFieldsNotInSuggester() throws Exception; + + @Test + public abstract void autocompleteFuzzyIsOffByDefault() throws Exception; + + @Test + public abstract void autocompleteOneTerm() throws Exception; + + @Test + public abstract void autocompleteStaticallyTypedDocuments() throws Exception; + + @Test + public abstract void autocompleteThrowsWhenRequestIsMalformed() throws Exception; + +} diff --git a/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteDefaultsToOneTermMode.json b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteDefaultsToOneTermMode.json new file mode 100644 index 0000000000000..298723dad90be --- /dev/null +++ b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteDefaultsToOneTermMode.json @@ -0,0 +1,70 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdk2e25755714c5.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" : "14e54b1f-07e6-4270-bf05-9fe83ea168a8", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:29:29 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "120", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "795", + "Body" : "{\"@odata.context\":\"https://azs-sdk2e25755714c5.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-sdk2e25755714c5.search.windows.net/indexes('hotels')/docs/search.post.autocomplete?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "b93c1866-5265-4300-8343-2bd4a4ff7d83", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:29:31 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "7", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "380", + "Body" : "{\"@odata.context\":\"https://azs-sdk2e25755714c5.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.AutocompleteItem)\",\"value\":[{\"text\":\"point\",\"queryPlusText\":\"point\"},{\"text\":\"police\",\"queryPlusText\":\"police\"},{\"text\":\"polite\",\"queryPlusText\":\"polite\"},{\"text\":\"pool\",\"queryPlusText\":\"pool\"},{\"text\":\"popular\",\"queryPlusText\":\"popular\"}]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + }, { + "Method" : "POST", + "Uri" : "https://azs-sdk2e25755714c5.search.windows.net/indexes('hotels')/docs/search.post.autocomplete?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "3d23cfbb-c802-4faa-aca6-173d2abf8aad", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:29:31 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "6", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "380", + "Body" : "{\"@odata.context\":\"https://azs-sdk2e25755714c5.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.AutocompleteItem)\",\"value\":[{\"text\":\"point\",\"queryPlusText\":\"point\"},{\"text\":\"police\",\"queryPlusText\":\"police\"},{\"text\":\"polite\",\"queryPlusText\":\"polite\"},{\"text\":\"pool\",\"queryPlusText\":\"pool\"},{\"text\":\"popular\",\"queryPlusText\":\"popular\"}]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteExcludesFieldsNotInSuggester.json b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteExcludesFieldsNotInSuggester.json new file mode 100644 index 0000000000000..490e412b0369c --- /dev/null +++ b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteExcludesFieldsNotInSuggester.json @@ -0,0 +1,70 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdk3a5954111b16.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" : "a6228565-adf8-40ab-a449-f6330dbb4ab4", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:28:42 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "151", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "795", + "Body" : "{\"@odata.context\":\"https://azs-sdk3a5954111b16.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-sdk3a5954111b16.search.windows.net/indexes('hotels')/docs/search.post.autocomplete?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "8bacaee1-e78f-4a50-8b5d-04758c999d9d", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:28:45 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "12", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "170", + "Body" : "{\"@odata.context\":\"https://azs-sdk3a5954111b16.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.AutocompleteItem)\",\"value\":[]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + }, { + "Method" : "POST", + "Uri" : "https://azs-sdk3a5954111b16.search.windows.net/indexes('hotels')/docs/search.post.autocomplete?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "f24c2bcf-eb3a-4741-8a9b-05c6ccedf4f5", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:28:45 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "4", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "170", + "Body" : "{\"@odata.context\":\"https://azs-sdk3a5954111b16.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.AutocompleteItem)\",\"value\":[]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteFuzzyIsOffByDefault.json b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteFuzzyIsOffByDefault.json new file mode 100644 index 0000000000000..1cb31851cf446 --- /dev/null +++ b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteFuzzyIsOffByDefault.json @@ -0,0 +1,70 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdkbb670738249e.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" : "059497a9-401c-42de-a1bd-e2c54638d7e7", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:28:27 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "85", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "795", + "Body" : "{\"@odata.context\":\"https://azs-sdkbb670738249e.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-sdkbb670738249e.search.windows.net/indexes('hotels')/docs/search.post.autocomplete?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "768092a5-5b99-4c0d-a0f1-edb459f2dc82", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:28:30 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "6", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "170", + "Body" : "{\"@odata.context\":\"https://azs-sdkbb670738249e.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.AutocompleteItem)\",\"value\":[]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + }, { + "Method" : "POST", + "Uri" : "https://azs-sdkbb670738249e.search.windows.net/indexes('hotels')/docs/search.post.autocomplete?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "6e08c781-3d2a-434b-a16b-f5c360c4f47b", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:28:30 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "6", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "170", + "Body" : "{\"@odata.context\":\"https://azs-sdkbb670738249e.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.AutocompleteItem)\",\"value\":[]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteOneTerm.json b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteOneTerm.json new file mode 100644 index 0000000000000..76089f561f640 --- /dev/null +++ b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteOneTerm.json @@ -0,0 +1,70 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdk06527431335f.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" : "0e646ad4-c25a-4358-9c7f-6517d6c71e1d", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:28:15 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "92", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "795", + "Body" : "{\"@odata.context\":\"https://azs-sdk06527431335f.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-sdk06527431335f.search.windows.net/indexes('hotels')/docs/search.post.autocomplete?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "2cba72d5-ddda-46c0-8c7f-9298033929ad", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:28:18 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "7", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "380", + "Body" : "{\"@odata.context\":\"https://azs-sdk06527431335f.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.AutocompleteItem)\",\"value\":[{\"text\":\"point\",\"queryPlusText\":\"point\"},{\"text\":\"police\",\"queryPlusText\":\"police\"},{\"text\":\"polite\",\"queryPlusText\":\"polite\"},{\"text\":\"pool\",\"queryPlusText\":\"pool\"},{\"text\":\"popular\",\"queryPlusText\":\"popular\"}]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + }, { + "Method" : "POST", + "Uri" : "https://azs-sdk06527431335f.search.windows.net/indexes('hotels')/docs/search.post.autocomplete?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "d6d5825e-a306-40d3-96bf-356c7c8feb2f", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:28:18 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "6", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "380", + "Body" : "{\"@odata.context\":\"https://azs-sdk06527431335f.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.AutocompleteItem)\",\"value\":[{\"text\":\"point\",\"queryPlusText\":\"point\"},{\"text\":\"police\",\"queryPlusText\":\"police\"},{\"text\":\"polite\",\"queryPlusText\":\"polite\"},{\"text\":\"pool\",\"queryPlusText\":\"pool\"},{\"text\":\"popular\",\"queryPlusText\":\"popular\"}]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteStaticallyTypedDocuments.json b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteStaticallyTypedDocuments.json new file mode 100644 index 0000000000000..ce3f7ed3a0f2c --- /dev/null +++ b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteStaticallyTypedDocuments.json @@ -0,0 +1,70 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdk65288003a371.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" : "0985726d-c607-4a67-8b22-c841a00844b8", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:29:13 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "104", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "795", + "Body" : "{\"@odata.context\":\"https://azs-sdk65288003a371.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-sdk65288003a371.search.windows.net/indexes('hotels')/docs/search.post.autocomplete?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "8ac0c440-a597-4fab-9606-7b5ad54a5a24", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:29:16 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "7", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "405", + "Body" : "{\"@odata.context\":\"https://azs-sdk65288003a371.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.AutocompleteItem)\",\"value\":[{\"text\":\"point\",\"queryPlusText\":\"very point\"},{\"text\":\"police\",\"queryPlusText\":\"very police\"},{\"text\":\"polite\",\"queryPlusText\":\"very polite\"},{\"text\":\"pool\",\"queryPlusText\":\"very pool\"},{\"text\":\"popular\",\"queryPlusText\":\"very popular\"}]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + }, { + "Method" : "POST", + "Uri" : "https://azs-sdk65288003a371.search.windows.net/indexes('hotels')/docs/search.post.autocomplete?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "5bf05e2e-ae5a-4aa3-9b44-6e6e2f14c9fd", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:29:16 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "6", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "405", + "Body" : "{\"@odata.context\":\"https://azs-sdk65288003a371.search.windows.net/indexes('hotels')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.AutocompleteItem)\",\"value\":[{\"text\":\"point\",\"queryPlusText\":\"very point\"},{\"text\":\"police\",\"queryPlusText\":\"very police\"},{\"text\":\"polite\",\"queryPlusText\":\"very polite\"},{\"text\":\"pool\",\"queryPlusText\":\"very pool\"},{\"text\":\"popular\",\"queryPlusText\":\"very popular\"}]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteThrowsWhenGivenBadSuggesterName.json b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteThrowsWhenGivenBadSuggesterName.json new file mode 100644 index 0000000000000..138012107cf8e --- /dev/null +++ b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteThrowsWhenGivenBadSuggesterName.json @@ -0,0 +1,49 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdk89d48617eae6.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" : "c7b2396d-0e63-410a-9776-d51312f48a2d", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:29:44 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "127", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "795", + "Body" : "{\"@odata.context\":\"https://azs-sdk89d48617eae6.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-sdk89d48617eae6.search.windows.net/indexes('hotels')/docs/search.post.autocomplete?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "fbf2c33f-2cf5-4a02-902b-4b03ea366e27", + "StatusCode" : "400", + "Date" : "Wed, 11 Sep 2019 11:29:46 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "2", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "147", + "Body" : "{\"error\":{\"code\":\"\",\"message\":\"The specified suggester name 'Invalid suggester' does not exist in this index definition.\\r\\nParameter name: name\"}}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Language" : "en", + "Content-Type" : "application/json; odata.metadata=minimal" + } + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteThrowsWhenRequestIsMalformed.json b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteThrowsWhenRequestIsMalformed.json new file mode 100644 index 0000000000000..c657196f7de7b --- /dev/null +++ b/sdk/search/azure-search-data/src/test/resources/session-records/autocompleteThrowsWhenRequestIsMalformed.json @@ -0,0 +1,49 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdkb06668908603.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" : "18c65259-dd97-4fc8-988e-3e575394e4e6", + "StatusCode" : "200", + "Date" : "Wed, 11 Sep 2019 11:28:58 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "140", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "795", + "Body" : "{\"@odata.context\":\"https://azs-sdkb06668908603.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-sdkb06668908603.search.windows.net/indexes('hotels')/docs/search.post.autocomplete?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "4da12863-0b3d-4723-a5b7-45c1e4e3d6ab", + "StatusCode" : "400", + "Date" : "Wed, 11 Sep 2019 11:29:00 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "5", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "165", + "Body" : "{\"error\":{\"code\":\"\",\"message\":\"Cannot find fields enabled for suggestions. Please provide a value for 'suggesterName' in the query.\\r\\nParameter name: suggestions\"}}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Language" : "en", + "Content-Type" : "application/json; odata.metadata=minimal" + } + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/search/azure-search-data/src/test/resources/session-records/testCanGetFuzzySuggestions.json b/sdk/search/azure-search-data/src/test/resources/session-records/testCanGetFuzzySuggestions.json new file mode 100644 index 0000000000000..2eebc32412d39 --- /dev/null +++ b/sdk/search/azure-search-data/src/test/resources/session-records/testCanGetFuzzySuggestions.json @@ -0,0 +1,48 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdka31737907e04.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" : "7e16acea-dba4-4eef-b226-5f24e192b06d", + "StatusCode" : "200", + "Date" : "Sun, 08 Sep 2019 07:08:54 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "116", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "795", + "Body" : "{\"@odata.context\":\"https://azs-sdka31737907e04.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-sdka31737907e04.search.windows.net/indexes('hotels')/docs/search.post.suggest?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "fb5b2215-1d4a-4102-bc5e-9ce7e694595c", + "StatusCode" : "200", + "Date" : "Sun, 08 Sep 2019 07:08:54 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "70", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "402", + "Body" : "{\"@odata.context\":\"https://azs-sdka31737907e04.search.windows.net/indexes('hotels')/$metadata#docs(*)\",\"value\":[{\"@search.text\":\"Countryside Hotel\",\"HotelId\":\"10\"},{\"@search.text\":\"Pretty good hotel\",\"HotelId\":\"4\"},{\"@search.text\":\"Another good hotel\",\"HotelId\":\"5\"},{\"@search.text\":\"Very popular hotel in town\",\"HotelId\":\"3\"},{\"@search.text\":\"Cheapest hotel in town. Infact, a motel.\",\"HotelId\":\"2\"}]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/search/azure-search-data/src/test/resources/session-records/testCanSuggestDynamicDocuments.json b/sdk/search/azure-search-data/src/test/resources/session-records/testCanSuggestDynamicDocuments.json new file mode 100644 index 0000000000000..25fd35c3c5992 --- /dev/null +++ b/sdk/search/azure-search-data/src/test/resources/session-records/testCanSuggestDynamicDocuments.json @@ -0,0 +1,70 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdk7ef58087b028.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" : "e7f6951e-b258-4c21-a583-5cb16b82f250", + "StatusCode" : "200", + "Date" : "Mon, 09 Sep 2019 06:41:26 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "128", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "795", + "Body" : "{\"@odata.context\":\"https://azs-sdk7ef58087b028.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-sdk7ef58087b028.search.windows.net/indexes('hotels')/docs/search.post.suggest?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "e9d6efe6-f690-4ca1-ba86-5da3c8859f5e", + "StatusCode" : "200", + "Date" : "Mon, 09 Sep 2019 06:41:26 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "93", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "436", + "Body" : "{\"@odata.context\":\"https://azs-sdk7ef58087b028.search.windows.net/indexes('hotels')/$metadata#docs(*)\",\"value\":[{\"@search.text\":\"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.\",\"HotelId\":\"10\"},{\"@search.text\":\"Has some road noise and is next to the very police station. Bathrooms had morel coverings.\",\"HotelId\":\"8\"}]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + }, { + "Method" : "POST", + "Uri" : "https://azs-sdk7ef58087b028.search.windows.net/indexes('hotels')/docs/search.post.suggest?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "48fc39eb-aab3-4b78-8811-d085f6bb8636", + "StatusCode" : "200", + "Date" : "Mon, 09 Sep 2019 06:41:27 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "9", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "436", + "Body" : "{\"@odata.context\":\"https://azs-sdk7ef58087b028.search.windows.net/indexes('hotels')/$metadata#docs(*)\",\"value\":[{\"@search.text\":\"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.\",\"HotelId\":\"10\"},{\"@search.text\":\"Has some road noise and is next to the very police station. Bathrooms had morel coverings.\",\"HotelId\":\"8\"}]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/search/azure-search-data/src/test/resources/session-records/testCanUseHitHighlighting.json b/sdk/search/azure-search-data/src/test/resources/session-records/testCanUseHitHighlighting.json new file mode 100644 index 0000000000000..2da1c5e0b503c --- /dev/null +++ b/sdk/search/azure-search-data/src/test/resources/session-records/testCanUseHitHighlighting.json @@ -0,0 +1,48 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdk1de059303fb4.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" : "6ea3e012-d5e3-4e6a-91d9-0a8fdb0dc4f8", + "StatusCode" : "200", + "Date" : "Sun, 08 Sep 2019 06:24:52 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "1215", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "795", + "Body" : "{\"@odata.context\":\"https://azs-sdk1de059303fb4.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-sdk1de059303fb4.search.windows.net/indexes('hotels')/docs/search.post.suggest?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "2e051c59-2431-43ad-a666-ce992b855901", + "StatusCode" : "200", + "Date" : "Sun, 08 Sep 2019 06:24:52 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "25", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "401", + "Body" : "{\"@odata.context\":\"https://azs-sdk1de059303fb4.search.windows.net/indexes('hotels')/$metadata#docs(*)\",\"value\":[{\"@search.text\":\"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.\",\"HotelId\":\"1\"}]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/search/azure-search-data/src/test/resources/session-records/testSearchFieldsExcludesFieldsFromSuggest.json b/sdk/search/azure-search-data/src/test/resources/session-records/testSearchFieldsExcludesFieldsFromSuggest.json new file mode 100644 index 0000000000000..244e84d3e6ddd --- /dev/null +++ b/sdk/search/azure-search-data/src/test/resources/session-records/testSearchFieldsExcludesFieldsFromSuggest.json @@ -0,0 +1,48 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://azs-sdkff4167679135.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" : "b012b280-d1e2-48b6-b1cd-e94c0a36a69d", + "StatusCode" : "200", + "Date" : "Sun, 08 Sep 2019 06:07:15 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "427", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "795", + "Body" : "{\"@odata.context\":\"https://azs-sdkff4167679135.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-sdkff4167679135.search.windows.net/indexes('hotels')/docs/search.post.suggest?api-version=2019-05-06", + "Headers" : { + "Content-Type" : "application/json; charset=utf-8" + }, + "Response" : { + "Pragma" : "no-cache", + "retry-after" : "0", + "request-id" : "3f3e62a8-b6ad-4119-851c-c061053c8043", + "StatusCode" : "200", + "Date" : "Sun, 08 Sep 2019 06:07:16 GMT", + "Strict-Transport-Security" : "max-age=15724800; includeSubDomains", + "Cache-Control" : "no-cache", + "elapsed-time" : "201", + "OData-Version" : "4.0", + "Expires" : "-1", + "Content-Length" : "114", + "Body" : "{\"@odata.context\":\"https://azs-sdkff4167679135.search.windows.net/indexes('hotels')/$metadata#docs(*)\",\"value\":[]}", + "Preference-Applied" : "odata.include-annotations=\"*\"", + "Content-Type" : "application/json; odata.metadata=minimal" + } + } ], + "variables" : [ ] +} \ No newline at end of file