Skip to content

Commit

Permalink
Use Latest PagedFlux Changes from Azure Core (Azure#8303)
Browse files Browse the repository at this point in the history
* Update PagedFlux usage to use new changes from Azure Core

* Use custom PagedFlux implementation in Azure Search to support pages with additional metadata

* Updated PagedFlux usage in Azure Search to allow search to use its non-String continuation token

* Update paging to new guidelines

* Fixed sample and test code

* Added missing documentation

* Remove unused dependency

* Add logic to handle when Azure Resource Group isn't set

* Changes based on PR feedback

* Moved PagedResponse classes into util

* Fix constructor scoping issue
  • Loading branch information
alzimmermsft authored Mar 3, 2020
1 parent feb5efd commit 2c9db7f
Show file tree
Hide file tree
Showing 30 changed files with 695 additions and 381 deletions.
3 changes: 2 additions & 1 deletion sdk/core/azure-core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
// public API surface area
exports com.azure.core.annotation;
exports com.azure.core.credential;
exports com.azure.core.cryptography;
exports com.azure.core.exception;
exports com.azure.core.http;
exports com.azure.core.http.policy;
exports com.azure.core.http.rest;
exports com.azure.core.util;
exports com.azure.core.util.logging;
exports com.azure.core.util.paging;
exports com.azure.core.util.polling;
exports com.azure.core.util.serializer;
exports com.azure.core.util.tracing;
exports com.azure.core.cryptography;

// exporting some packages specifically for Jackson
opens com.azure.core.http to com.fasterxml.jackson.databind;
Expand Down
10 changes: 10 additions & 0 deletions sdk/search/azure-search/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
<version>1.4.0-beta.2</version> <!-- {x-version-update;unreleased_com.azure:azure-core-http-netty;dependency} -->
</dependency>

<!-- Added this dependency to include necessary annotations used by reactor core.
Without this dependency, javadoc throws a warning as it cannot find enum When.MAYBE
which is used in @Nullable annotation in reactor core classes -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version> <!-- {x-version-update;com.google.code.findbugs:jsr305;external_dependency} -->
<scope>provided</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>com.azure</groupId>
Expand Down

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@

import com.azure.core.annotation.ServiceClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedIterableBase;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.search.models.AutocompleteItem;
import com.azure.search.models.AutocompleteOptions;
import com.azure.search.models.IndexBatch;
import com.azure.search.models.IndexDocumentsResult;
Expand All @@ -18,6 +15,11 @@
import com.azure.search.models.SearchResult;
import com.azure.search.models.SuggestOptions;
import com.azure.search.models.SuggestResult;
import com.azure.search.util.AutocompletePagedIterable;
import com.azure.search.util.SearchPagedIterable;
import com.azure.search.util.SearchPagedResponse;
import com.azure.search.util.SuggestPagedIterable;
import com.azure.search.util.SuggestPagedResponse;

import java.util.List;

Expand Down Expand Up @@ -95,11 +97,11 @@ public Response<IndexDocumentsResult> uploadDocumentsWithResponse(Iterable<?> do
* Merges a collection of documents with existing documents in the target index.
* <p>
* If the type of the document contains non-nullable primitive-typed properties, these properties may not merge
* correctly. If you do not set such a property, it will automatically take its default value (for example,
* {@code 0} for {@code int} or {@code false} for {@code boolean}), which will override the value of the property
* currently stored in the index, even if this was not your intent. For this reason, it is strongly recommended
* that you always declare primitive-typed properties with their class equivalents (for example, an integer
* property should be of type {@code Integer} instead of {@code int}).
* correctly. If you do not set such a property, it will automatically take its default value (for example, {@code
* 0} for {@code int} or {@code false} for {@code boolean}), which will override the value of the property currently
* stored in the index, even if this was not your intent. For this reason, it is strongly recommended that you
* always declare primitive-typed properties with their class equivalents (for example, an integer property should
* be of type {@code Integer} instead of {@code int}).
*
* @param documents collection of documents to be merged
* @return document index result
Expand All @@ -119,11 +121,11 @@ public IndexDocumentsResult mergeDocuments(Iterable<?> documents) {
* Merges a collection of documents with existing documents in the target index.
* <p>
* If the type of the document contains non-nullable primitive-typed properties, these properties may not merge
* correctly. If you do not set such a property, it will automatically take its default value (for example,
* {@code 0} for {@code int} or {@code false} for {@code boolean}), which will override the value of the property
* currently stored in the index, even if this was not your intent. For this reason, it is strongly recommended
* that you always declare primitive-typed properties with their class equivalents (for example, an integer
* property should be of type {@code Integer} instead of {@code int}).
* correctly. If you do not set such a property, it will automatically take its default value (for example, {@code
* 0} for {@code int} or {@code false} for {@code boolean}), which will override the value of the property currently
* stored in the index, even if this was not your intent. For this reason, it is strongly recommended that you
* always declare primitive-typed properties with their class equivalents (for example, an integer property should
* be of type {@code Integer} instead of {@code int}).
*
* @param documents collection of documents to be merged
* @param context additional context that is passed through the Http pipeline during the service call
Expand All @@ -145,11 +147,11 @@ public Response<IndexDocumentsResult> mergeDocumentsWithResponse(Iterable<?> doc
* not exist, it behaves like upload with a new document.
* <p>
* If the type of the document contains non-nullable primitive-typed properties, these properties may not merge
* correctly. If you do not set such a property, it will automatically take its default value (for example,
* {@code 0} for {@code int} or {@code false} for {@code boolean}), which will override the value of the property
* currently stored in the index, even if this was not your intent. For this reason, it is strongly recommended
* that you always declare primitive-typed properties with their class equivalents (for example, an integer
* property should be of type {@code Integer} instead of {@code int}).
* correctly. If you do not set such a property, it will automatically take its default value (for example, {@code
* 0} for {@code int} or {@code false} for {@code boolean}), which will override the value of the property currently
* stored in the index, even if this was not your intent. For this reason, it is strongly recommended that you
* always declare primitive-typed properties with their class equivalents (for example, an integer property should
* be of type {@code Integer} instead of {@code int}).
*
* @param documents collection of documents to be merged, if exists, otherwise uploaded
* @return document index result
Expand All @@ -170,11 +172,11 @@ public IndexDocumentsResult mergeOrUploadDocuments(Iterable<?> documents) {
* not exist, it behaves like upload with a new document.
* <p>
* If the type of the document contains non-nullable primitive-typed properties, these properties may not merge
* correctly. If you do not set such a property, it will automatically take its default value (for example,
* {@code 0} for {@code int} or {@code false} for {@code boolean}), which will override the value of the property
* currently stored in the index, even if this was not your intent. For this reason, it is strongly recommended
* that you always declare primitive-typed properties with their class equivalents (for example, an integer
* property should be of type {@code Integer} instead of {@code int}).
* correctly. If you do not set such a property, it will automatically take its default value (for example, {@code
* 0} for {@code int} or {@code false} for {@code boolean}), which will override the value of the property currently
* stored in the index, even if this was not your intent. For this reason, it is strongly recommended that you
* always declare primitive-typed properties with their class equivalents (for example, an integer property should
* be of type {@code Integer} instead of {@code int}).
*
* @param documents collection of documents to be merged, if exists, otherwise uploaded
* @param context additional context that is passed through the Http pipeline during the service call
Expand Down Expand Up @@ -271,11 +273,12 @@ public Response<Long> getDocumentCountWithResponse(Context context) {
* syntax in Azure Search</a> for more information about search query syntax.
*
* @param searchText A full-text search query expression.
* @return A {@link PagedIterable} that iterates over {@link SearchResult} objects and provides access to the {@link
* SearchPagedResponse} object for each page containing HTTP response and count, facet, and coverage information.
* @return A {@link SearchPagedIterable} that iterates over {@link SearchResult} objects and provides access to the
* {@link SearchPagedResponse} object for each page containing HTTP response and count, facet, and coverage
* information.
* @see <a href="https://docs.microsoft.com/rest/api/searchservice/Search-Documents">Search documents</a>
*/
public PagedIterableBase<SearchResult, SearchPagedResponse> search(String searchText) {
public SearchPagedIterable search(String searchText) {
return search(searchText, null, null, Context.NONE);
}

Expand All @@ -291,13 +294,14 @@ public PagedIterableBase<SearchResult, SearchPagedResponse> search(String search
* @param requestOptions additional parameters for the operation. Contains the tracking ID sent with the request to
* help with debugging
* @param context additional context that is passed through the Http pipeline during the service call
* @return A {@link PagedIterable} that iterates over {@link SearchResult} objects and provides access to the {@link
* SearchPagedResponse} object for each page containing HTTP response and count, facet, and coverage information.
* @return A {@link SearchPagedIterable} that iterates over {@link SearchResult} objects and provides access to the
* {@link SearchPagedResponse} object for each page containing HTTP response and count, facet, and coverage
* information.
* @see <a href="https://docs.microsoft.com/rest/api/searchservice/Search-Documents">Search documents</a>
*/
public PagedIterableBase<SearchResult, SearchPagedResponse> search(String searchText, SearchOptions searchOptions,
public SearchPagedIterable search(String searchText, SearchOptions searchOptions,
RequestOptions requestOptions, Context context) {
return new PagedIterableBase<>(asyncClient.search(searchText, searchOptions, requestOptions, context));
return new SearchPagedIterable(asyncClient.search(searchText, searchOptions, requestOptions, context));
}

/**
Expand Down Expand Up @@ -340,11 +344,11 @@ public Response<Document> getDocumentWithResponse(String key, List<String> selec
* @param searchText The search text on which to base suggestions
* @param suggesterName The name of the suggester as specified in the suggesters collection that's part of the index
* definition
* @return A {@link PagedIterableBase} that iterates over {@link SuggestResult} objects and provides access to the
* {@link SuggestPagedResponse} object for each page containing HTTP response and coverage information.
* @return A {@link SuggestPagedIterable} that iterates over {@link SuggestResult} objects and provides access to
* the {@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>
*/
public PagedIterableBase<SuggestResult, SuggestPagedResponse> suggest(String searchText, String suggesterName) {
public SuggestPagedIterable suggest(String searchText, String suggesterName) {
return suggest(searchText, suggesterName, null, null, Context.NONE);
}

Expand All @@ -358,13 +362,13 @@ public PagedIterableBase<SuggestResult, SuggestPagedResponse> suggest(String sea
* @param requestOptions additional parameters for the operation. Contains the tracking ID sent with the request to
* help with debugging
* @param context additional context that is passed through the Http pipeline during the service call
* @return A {@link PagedIterableBase} that iterates over {@link SuggestResult} objects and provides access to the
* {@link SuggestPagedResponse} object for each page containing HTTP response and coverage information.
* @return A {@link SuggestPagedIterable} that iterates over {@link SuggestResult} objects and provides access to
* the {@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>
*/
public PagedIterableBase<SuggestResult, SuggestPagedResponse> suggest(String searchText, String suggesterName,
SuggestOptions suggestOptions, RequestOptions requestOptions, Context context) {
return new PagedIterableBase<>(asyncClient.suggest(searchText, suggesterName, suggestOptions, requestOptions,
public SuggestPagedIterable suggest(String searchText, String suggesterName, SuggestOptions suggestOptions,
RequestOptions requestOptions, Context context) {
return new SuggestPagedIterable(asyncClient.suggest(searchText, suggesterName, suggestOptions, requestOptions,
context));
}

Expand Down Expand Up @@ -410,8 +414,7 @@ public Response<IndexDocumentsResult> indexWithResponse(IndexBatch<?> batch, Con
* @param suggesterName suggester name
* @return auto complete result.
*/
public PagedIterableBase<AutocompleteItem, AutocompletePagedResponse> autocomplete(String searchText,
String suggesterName) {
public AutocompletePagedIterable autocomplete(String searchText, String suggesterName) {
return autocomplete(searchText, suggesterName, null, null, Context.NONE);
}

Expand All @@ -426,9 +429,9 @@ public PagedIterableBase<AutocompleteItem, AutocompletePagedResponse> autocomple
* @param context additional context that is passed through the HTTP pipeline during the service call
* @return auto complete result.
*/
public PagedIterableBase<AutocompleteItem, AutocompletePagedResponse> autocomplete(String searchText,
String suggesterName, AutocompleteOptions autocompleteOptions, RequestOptions requestOptions, Context context) {
return new PagedIterableBase<>(asyncClient.autocomplete(searchText, suggesterName, autocompleteOptions,
public AutocompletePagedIterable autocomplete(String searchText, String suggesterName,
AutocompleteOptions autocompleteOptions, RequestOptions requestOptions, Context context) {
return new AutocompletePagedIterable(asyncClient.autocomplete(searchText, suggesterName, autocompleteOptions,
requestOptions, context));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.search.util;

import com.azure.core.http.rest.PagedFluxBase;
import com.azure.search.models.AutocompleteItem;
import reactor.core.publisher.Mono;

import java.util.function.Supplier;

/**
* Implementation of {@link PagedFluxBase} where the element type is {@link AutocompleteItem} and the page type is
* {@link AutocompletePagedResponse}.
*/
public final class AutocompletePagedFlux extends PagedFluxBase<AutocompleteItem, AutocompletePagedResponse> {
/**
* Creates an instance of {@link AutocompletePagedFlux} that retrieves a single page.
*
* @param firstPageRetriever Supplier that handles retrieving the first page.
*/
public AutocompletePagedFlux(Supplier<Mono<AutocompletePagedResponse>> firstPageRetriever) {
super(firstPageRetriever);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.search.util;

import com.azure.core.http.rest.PagedIterableBase;
import com.azure.search.models.AutocompleteItem;

/**
* Implementation of {@link PagedIterableBase} where the element type is {@link AutocompleteItem} and the page type is
* {@link AutocompletePagedResponse}.
*/
public final class AutocompletePagedIterable extends PagedIterableBase<AutocompleteItem, AutocompletePagedResponse> {
/**
* Creates instance given {@link AutocompletePagedIterable}.
*
* @param pagedFluxBase The {@link AutocompletePagedFlux} that will be consumed as an iterable.
*/
public AutocompletePagedIterable(AutocompletePagedFlux pagedFluxBase) {
super(pagedFluxBase);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.search.util;

import com.azure.core.annotation.Immutable;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.search.models.AutocompleteItem;
import com.azure.search.models.AutocompleteResult;

/**
* This class represents a response from the autocomplete API. It contains the {@link AutocompleteItem
* AutocompleteItems} returned from the service.
*/
@Immutable
public final class AutocompletePagedResponse extends PagedResponseBase<Void, AutocompleteItem> {
private final Double coverage;

/**
* Creates an {@link AutocompletePagedResponse} from the returned {@link Response}.
*
* @param autocompleteResponse Autocomplete response returned from the service.
*/
public AutocompletePagedResponse(SimpleResponse<AutocompleteResult> autocompleteResponse) {
super(autocompleteResponse.getRequest(),
autocompleteResponse.getStatusCode(),
autocompleteResponse.getHeaders(),
autocompleteResponse.getValue().getResults(),
null,
null);

this.coverage = autocompleteResponse.getValue().getCoverage();
}

/**
* The percentage of the index covered in the autocomplete request.
* <p>
* If {@code minimumCoverage} wasn't supplied in the request this will be {@code null}.
*
* @return The percentage of the index covered in the suggest request if {@code minimumCoverage} was set in the
* request, otherwise {@code null}.
*/
public Double getCoverage() {
return coverage;
}
}
Loading

0 comments on commit 2c9db7f

Please sign in to comment.