-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Review Before Releasing Azure Cognitive Search #13033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
75aa0b0
ca487f5
6f6383f
e7574a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,10 @@ | |
| import static com.azure.core.util.FluxUtil.withContext; | ||
|
|
||
| /** | ||
| * Cognitive Search Asynchronous Client to query an index and upload, merge, or delete documents | ||
| * This class provides a client that contains the operations for querying an index and uploading, merging, or deleting | ||
| * documents in an Azure Cognitive Search service. | ||
| * | ||
| * @see SearchClientBuilder | ||
| */ | ||
| @ServiceClient(builder = SearchClientBuilder.class, isAsync = true) | ||
| public final class SearchAsyncClient { | ||
|
|
@@ -213,8 +216,7 @@ public Mono<Response<IndexDocumentsResult>> uploadDocumentsWithResponse(Iterable | |
|
|
||
| Mono<Response<IndexDocumentsResult>> uploadDocumentsWithResponse(Iterable<?> documents, | ||
| IndexDocumentsOptions options, Context context) { | ||
| return indexDocumentsWithResponse(buildIndexBatch(documents, IndexActionType.UPLOAD), options, | ||
| context); | ||
| return indexDocumentsWithResponse(buildIndexBatch(documents, IndexActionType.UPLOAD), options, context); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -283,8 +285,7 @@ public Mono<Response<IndexDocumentsResult>> mergeDocumentsWithResponse(Iterable< | |
|
|
||
| Mono<Response<IndexDocumentsResult>> mergeDocumentsWithResponse(Iterable<?> documents, | ||
| IndexDocumentsOptions options, Context context) { | ||
| return indexDocumentsWithResponse(buildIndexBatch(documents, IndexActionType.MERGE), options, | ||
| context); | ||
| return indexDocumentsWithResponse(buildIndexBatch(documents, IndexActionType.MERGE), options, context); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -411,8 +412,7 @@ public Mono<Response<IndexDocumentsResult>> deleteDocumentsWithResponse(Iterable | |
|
|
||
| Mono<Response<IndexDocumentsResult>> deleteDocumentsWithResponse(Iterable<?> documents, | ||
| IndexDocumentsOptions options, Context context) { | ||
| return indexDocumentsWithResponse(buildIndexBatch(documents, IndexActionType.DELETE), options, | ||
| context); | ||
| return indexDocumentsWithResponse(buildIndexBatch(documents, IndexActionType.DELETE), options, context); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -468,11 +468,9 @@ public Mono<Response<IndexDocumentsResult>> indexDocumentsWithResponse(IndexDocu | |
| Mono<Response<IndexDocumentsResult>> indexDocumentsWithResponse(IndexDocumentsBatch<?> batch, | ||
| IndexDocumentsOptions options, Context context) { | ||
| try { | ||
| IndexDocumentsOptions documentsOptions = (options == null) | ||
| ? new IndexDocumentsOptions() : options; | ||
| IndexDocumentsOptions documentsOptions = (options == null) ? new IndexDocumentsOptions() : options; | ||
| return restClient.getDocuments() | ||
| .indexWithResponseAsync(IndexBatchBaseConverter.map(batch), null, | ||
| context) | ||
| .indexWithResponseAsync(IndexBatchBaseConverter.map(batch), null, context) | ||
| .onErrorMap(MappingUtils::exceptionMapper) | ||
| .flatMap(response -> (response.getStatusCode() == MULTI_STATUS_CODE | ||
| && documentsOptions.throwOnAnyError()) | ||
|
|
@@ -527,22 +525,21 @@ public <T> Mono<T> getDocument(String key, Class<T> modelClass) { | |
| * @see <a href="https://docs.microsoft.com/rest/api/searchservice/Lookup-Document">Lookup document</a> | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.SINGLE) | ||
| public <T> Mono<Response<T>> getDocumentWithResponse(String key, Class<T> modelClass, | ||
| List<String> selectedFields) { | ||
| return withContext(context -> getDocumentWithResponse(key, modelClass, | ||
| selectedFields, context)); | ||
| public <T> Mono<Response<T>> getDocumentWithResponse(String key, Class<T> modelClass, List<String> selectedFields) { | ||
| return withContext(context -> getDocumentWithResponse(key, modelClass, selectedFields, context)); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| <T> Mono<Response<T>> getDocumentWithResponse(String key, Class<T> modelClass, | ||
| List<String> selectedFields, Context context) { | ||
| <T> Mono<Response<T>> getDocumentWithResponse(String key, Class<T> modelClass, List<String> selectedFields, | ||
| Context context) { | ||
| try { | ||
| return restClient.getDocuments() | ||
| .getWithResponseAsync(key, selectedFields, null, context) | ||
| .onErrorMap(DocumentResponseConversions::exceptionMapper) | ||
| .map(res -> { | ||
| if (SearchDocument.class == modelClass) { | ||
| TypeReference<Map<String, Object>> typeReference = new TypeReference<Map<String, Object>>() { }; | ||
| TypeReference<Map<String, Object>> typeReference = new TypeReference<Map<String, Object>>() { | ||
| }; | ||
| SearchDocument doc = new SearchDocument(MAPPER.convertValue(res.getValue(), typeReference)); | ||
| return new SimpleResponse<T>(res, (T) doc); | ||
| } | ||
|
|
@@ -603,7 +600,7 @@ Mono<Response<Long>> getDocumentCountWithResponse(Context context) { | |
| * <p> | ||
| * If {@code searchText} is set to {@code null} or {@code "*"} all documents will be matched, see | ||
| * <a href="https://docs.microsoft.com/rest/api/searchservice/Simple-query-syntax-in-Azure-Search">simple query | ||
| * syntax in Azure Search</a> for more information about search query syntax. | ||
| * syntax in Azure Cognitive Search</a> for more information about search query syntax. | ||
| * | ||
| * <p><strong>Code Sample</strong></p> | ||
| * | ||
|
|
@@ -617,16 +614,17 @@ Mono<Response<Long>> getDocumentCountWithResponse(Context context) { | |
| * information. | ||
| * @see <a href="https://docs.microsoft.com/rest/api/searchservice/Search-Documents">Search documents</a> | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public SearchPagedFlux search(String searchText) { | ||
| return this.search(searchText, null, null); | ||
| return this.search(searchText, null); | ||
| } | ||
|
|
||
| /** | ||
| * Searches for documents in the Azure Cognitive Search index. | ||
| * <p> | ||
| * If {@code searchText} is set to {@code null} or {@code "*"} all documents will be matched, see | ||
| * <a href="https://docs.microsoft.com/rest/api/searchservice/Simple-query-syntax-in-Azure-Search">simple query | ||
| * syntax in Azure Search</a> for more information about search query syntax. | ||
| * syntax in Azure Cognitive Search</a> for more information about search query syntax. | ||
| * | ||
| * <p><strong>Code Sample</strong></p> | ||
| * | ||
|
|
@@ -641,6 +639,7 @@ public SearchPagedFlux search(String searchText) { | |
| * information. | ||
| * @see <a href="https://docs.microsoft.com/rest/api/searchservice/Search-Documents">Search documents</a> | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public SearchPagedFlux search(String searchText, SearchOptions searchOptions) { | ||
| SearchRequest request = createSearchRequest(searchText, searchOptions); | ||
| // The firstPageResponse shared among all fucntional calls below. | ||
|
|
@@ -661,16 +660,16 @@ SearchPagedFlux search(String searchText, SearchOptions searchOptions, Context c | |
| return new SearchPagedFlux(() -> func.apply(null), func); | ||
| } | ||
|
|
||
| private Mono<SearchPagedResponse> search(SearchRequest request, | ||
| String continuationToken, SearchFirstPageResponseWrapper firstPageResponseWrapper, Context context) { | ||
| private Mono<SearchPagedResponse> search(SearchRequest request, String continuationToken, | ||
| SearchFirstPageResponseWrapper firstPageResponseWrapper, Context context) { | ||
| if (continuationToken == null && firstPageResponseWrapper.getFirstPageResponse() != null) { | ||
| return Mono.just(firstPageResponseWrapper.getFirstPageResponse()); | ||
| } | ||
| SearchRequest requestToUse = (continuationToken == null) ? request | ||
| SearchRequest requestToUse = (continuationToken == null) | ||
| ? request | ||
| : SearchContinuationToken.deserializeToken(serviceVersion.getVersion(), continuationToken); | ||
|
|
||
| return restClient.getDocuments().searchPostWithResponseAsync(requestToUse, | ||
| null, context) | ||
| return restClient.getDocuments().searchPostWithResponseAsync(requestToUse, null, context) | ||
| .onErrorMap(MappingUtils::exceptionMapper) | ||
| .map(response -> { | ||
| SearchDocumentsResult result = response.getValue(); | ||
|
|
@@ -726,6 +725,7 @@ private static Map<String, List<FacetResult>> getFacets(SearchDocumentsResult re | |
| * {@link SuggestPagedResponse} object for each page containing HTTP response and coverage information. | ||
| * @see <a href="https://docs.microsoft.com/rest/api/searchservice/Suggestions">Suggestions</a> | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public SuggestPagedFlux suggest(String searchText, String suggesterName) { | ||
| return suggest(searchText, suggesterName, null); | ||
| } | ||
|
|
@@ -747,6 +747,7 @@ public SuggestPagedFlux suggest(String searchText, String suggesterName) { | |
| * {@link SuggestPagedResponse} object for each page containing HTTP response and coverage information. | ||
| * @see <a href="https://docs.microsoft.com/rest/api/searchservice/Suggestions">Suggestions</a> | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public SuggestPagedFlux suggest(String searchText, String suggesterName, SuggestOptions suggestOptions) { | ||
| SuggestRequest suggestRequest = createSuggestRequest(searchText, suggesterName, | ||
| SuggestOptionsHandler.ensureSuggestOptions(suggestOptions)); | ||
|
|
@@ -762,8 +763,7 @@ SuggestPagedFlux suggest(String searchText, String suggesterName, SuggestOptions | |
| } | ||
|
|
||
| private Mono<SuggestPagedResponse> suggest(SuggestRequest suggestRequest, Context context) { | ||
| return restClient.getDocuments().suggestPostWithResponseAsync(suggestRequest, | ||
| null, context) | ||
| return restClient.getDocuments().suggestPostWithResponseAsync(suggestRequest, null, context) | ||
| .onErrorMap(MappingUtils::exceptionMapper) | ||
| .map(response -> { | ||
| SuggestDocumentsResult result = response.getValue(); | ||
|
|
@@ -792,8 +792,9 @@ private static List<SuggestResult> getSuggestResults(SuggestDocumentsResult resu | |
| * @param suggesterName suggester name | ||
| * @return auto complete result. | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why weren't these caught in checkstyle check before? Are we suppressing some valid checks?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remembered checkstyle treated the SearchPagedFlux as Single return type.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should still have an annotation and should only be a suppression in checkstyle xml. I still don't understand why the annotation was completely missing.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the annotation for all APIs but got checkstyle error for the paging. Had a conversation with Alan, and decided to go without the annotation and add them back until checkstyle gets fixed. |
||
| public AutocompletePagedFlux autocomplete(String searchText, String suggesterName) { | ||
| return autocomplete(searchText, suggesterName, null, null); | ||
| return autocomplete(searchText, suggesterName, null); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -825,8 +826,7 @@ AutocompletePagedFlux autocomplete(String searchText, String suggesterName, Auto | |
| } | ||
|
|
||
| private Mono<AutocompletePagedResponse> autocomplete(AutocompleteRequest request, Context context) { | ||
| return restClient.getDocuments().autocompletePostWithResponseAsync(request, | ||
| null, context) | ||
| return restClient.getDocuments().autocompletePostWithResponseAsync(request, null, context) | ||
| .onErrorMap(MappingUtils::exceptionMapper) | ||
| .map(MappingUtils::mappingAutocompleteResponse); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.