Skip to content

Commit

Permalink
Updated SearchIndexClient methods to pass Context (Azure#139)
Browse files Browse the repository at this point in the history
Updated SearchIndexClient methods to pass Context
  • Loading branch information
Humoiz authored Oct 11, 2019
1 parent effcd6e commit 25d992e
Show file tree
Hide file tree
Showing 24 changed files with 466 additions and 370 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public Mono<DocumentIndexResult> mergeDocuments(Iterable<?> documents) {
* @return response containing the document index result.
*/
public Mono<Response<DocumentIndexResult>> mergeDocumentsWithResponse(Iterable<?> documents) {
return this.indexWithResponse(new IndexBatch().addMergeAction(documents));
return withContext(context -> mergeDocumentsWithResponse(documents, context));
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.search.models.AutocompleteItem;
import com.azure.search.models.AutocompleteParameters;
import com.azure.search.models.DocumentIndexResult;
Expand All @@ -17,7 +18,6 @@
import com.azure.search.models.SuggestParameters;
import com.azure.search.models.SuggestResult;


import reactor.core.publisher.Mono;
import reactor.util.annotation.Nullable;
import java.time.Duration;
Expand Down Expand Up @@ -53,18 +53,19 @@ public String getIndexName() {
* @return document index result.
*/
public DocumentIndexResult uploadDocuments(Iterable<?> documents) {
return this.uploadDocumentsWithResponse(documents).getValue();
return this.uploadDocumentsWithResponse(documents, Context.NONE).getValue();
}

/**
* Uploads a collection of documents to the target index
*
* @param documents collection of documents to upload to the target Index.
* @param context additional context that is passed through the Http pipeline during the service call
* @return response containing the document index result.
*/
@SuppressWarnings("unchecked")
public Response<DocumentIndexResult> uploadDocumentsWithResponse(Iterable<?> documents) {
return this.indexWithResponse(new IndexBatch().addUploadAction(documents));
public Response<DocumentIndexResult> uploadDocumentsWithResponse(Iterable<?> documents, Context context) {
return this.indexWithResponse(new IndexBatch().addUploadAction(documents), context);
}

/**
Expand All @@ -74,18 +75,19 @@ public Response<DocumentIndexResult> uploadDocumentsWithResponse(Iterable<?> doc
* @return document index result
*/
public DocumentIndexResult mergeDocuments(Iterable<?> documents) {
return this.mergeDocumentsWithResponse(documents).getValue();
return this.mergeDocumentsWithResponse(documents, Context.NONE).getValue();
}

/**
* Merges a collection of documents with existing documents in the target index.
*
* @param documents collection of documents to be merged
* @param context additional context that is passed through the Http pipeline during the service call
* @return response containing the document index result.
*/
@SuppressWarnings("unchecked")
public Response<DocumentIndexResult> mergeDocumentsWithResponse(Iterable<?> documents) {
return this.indexWithResponse(new IndexBatch().addMergeAction(documents));
public Response<DocumentIndexResult> mergeDocumentsWithResponse(Iterable<?> documents, Context context) {
return this.indexWithResponse(new IndexBatch().addMergeAction(documents), context);
}

/**
Expand All @@ -96,19 +98,20 @@ public Response<DocumentIndexResult> mergeDocumentsWithResponse(Iterable<?> docu
* @return document index result
*/
public DocumentIndexResult mergeOrUploadDocuments(Iterable<?> documents) {
return this.mergeOrUploadDocumentsWithResponse(documents).getValue();
return this.mergeOrUploadDocumentsWithResponse(documents, Context.NONE).getValue();
}

/**
* This action behaves like merge if a document with the given key already exists in the index.
* If the document does not exist, it behaves like upload with a new document.
*
* @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
* @return response containing a document index result
*/
@SuppressWarnings("unchecked")
public Response<DocumentIndexResult> mergeOrUploadDocumentsWithResponse(Iterable<?> documents) {
return this.indexWithResponse(new IndexBatch().addMergeOrUploadAction(documents));
public Response<DocumentIndexResult> mergeOrUploadDocumentsWithResponse(Iterable<?> documents, Context context) {
return this.indexWithResponse(new IndexBatch().addMergeOrUploadAction(documents), context);
}

/**
Expand All @@ -118,18 +121,19 @@ public Response<DocumentIndexResult> mergeOrUploadDocumentsWithResponse(Iterable
* @return document index result.
*/
public DocumentIndexResult deleteDocuments(Iterable<?> documents) {
return this.deleteDocumentsWithResponse(documents).getValue();
return this.deleteDocumentsWithResponse(documents, Context.NONE).getValue();
}

/**
* Deletes a collection of documents from the target index
*
* @param documents collection of documents to delete from the target Index.
* @param context additional context that is passed through the Http pipeline during the service call
* @return response containing a document index result.
*/
@SuppressWarnings("unchecked")
public Response<DocumentIndexResult> deleteDocumentsWithResponse(Iterable<?> documents) {
return this.indexWithResponse(new IndexBatch().addDeleteAction(documents));
public Response<DocumentIndexResult> deleteDocumentsWithResponse(Iterable<?> documents, Context context) {
return this.indexWithResponse(new IndexBatch().addDeleteAction(documents), context);
}

/**
Expand Down Expand Up @@ -165,16 +169,16 @@ public String getSearchServiceName() {
* @return the number of documents.
*/
public Long getDocumentCount() {
return this.getDocumentCountWithResponse().getValue();
return this.getDocumentCountWithResponse(Context.NONE).getValue();
}

/**
* Gets the number of documents
*
* @param context additional context that is passed through the Http pipeline during the service call
* @return response containing the number of documents.
*/
public Response<Long> getDocumentCountWithResponse() {
Mono<Response<Long>> result = asyncClient.getDocumentCountWithResponse();
public Response<Long> getDocumentCountWithResponse(Context context) {
Mono<Response<Long>> result = asyncClient.getDocumentCountWithResponse(context);
return blockWithOptionalTimeout(result, null);
}

Expand All @@ -184,8 +188,10 @@ public Response<Long> getDocumentCountWithResponse() {
* @return A {@link PagedIterable} of SearchResults
*/
public PagedIterable<SearchResult> search() {
PagedFlux<SearchResult> result = asyncClient.search();
return new PagedIterable<>(result);
return this.search(null,
null,
null,
Context.NONE);
}

/**
Expand All @@ -199,7 +205,29 @@ public PagedIterable<SearchResult> search() {
public PagedIterable<SearchResult> search(String searchText,
SearchParameters searchParameters,
SearchRequestOptions searchRequestOptions) {
PagedFlux<SearchResult> result = asyncClient.search(searchText, searchParameters, searchRequestOptions);
return this.search(searchText,
searchParameters,
searchRequestOptions,
Context.NONE);
}

/**
* Searches for documents in the Azure Search index
*
* @param searchText Search Test
* @param searchParameters Search Parameters
* @param searchRequestOptions Search Request Options
* @param context additional context that is passed through the Http pipeline during the service call
* @return A {@link PagedIterable} of SearchResults
*/
public PagedIterable<SearchResult> search(String searchText,
SearchParameters searchParameters,
SearchRequestOptions searchRequestOptions,
Context context) {
PagedFlux<SearchResult> result = asyncClient.search(searchText,
searchParameters,
searchRequestOptions,
context);
return new PagedIterable<>(result);
}

Expand All @@ -222,8 +250,13 @@ public Document getDocument(String key) {
* @param searchRequestOptions search request options
* @return document object
*/
public Document getDocument(String key, List<String> selectedFields, SearchRequestOptions searchRequestOptions) {
return this.getDocumentWithResponse(key, selectedFields, searchRequestOptions).getValue();
public Document getDocument(String key,
List<String> selectedFields,
SearchRequestOptions searchRequestOptions) {
return this.getDocumentWithResponse(key,
selectedFields,
searchRequestOptions,
Context.NONE).getValue();
}

/**
Expand All @@ -232,13 +265,17 @@ public Document getDocument(String key, List<String> selectedFields, SearchReque
* @param key document key
* @param selectedFields selected fields to return
* @param searchRequestOptions search request options
* @param context additional context that is passed through the Http pipeline during the service call
* @return response containing a document object
*/
public Response<Document> getDocumentWithResponse(String key, List<String> selectedFields,
SearchRequestOptions searchRequestOptions) {
public Response<Document> getDocumentWithResponse(String key,
List<String> selectedFields,
SearchRequestOptions searchRequestOptions,
Context context) {
Mono<Response<Document>> results = asyncClient.getDocumentWithResponse(key,
selectedFields,
searchRequestOptions);
searchRequestOptions,
context);
return blockWithOptionalTimeout(results, null);
}

Expand All @@ -250,8 +287,11 @@ public Response<Document> getDocumentWithResponse(String key, List<String> selec
* @return suggests result
*/
public PagedIterable<SuggestResult> suggest(String searchText, String suggesterName) {
PagedFlux<SuggestResult> result = asyncClient.suggest(searchText, suggesterName);
return new PagedIterable<>(result);
return this.suggest(searchText,
suggesterName,
null,
null,
Context.NONE);
}

/**
Expand All @@ -267,10 +307,33 @@ public PagedIterable<SuggestResult> suggest(String searchText,
String suggesterName,
SuggestParameters suggestParameters,
SearchRequestOptions searchRequestOptions) {
return this.suggest(searchText,
suggesterName,
suggestParameters,
searchRequestOptions,
Context.NONE);
}

/**
* Suggests documents in the Azure Search index that match the given partial query text.
*
* @param searchText search text
* @param suggesterName suggester name
* @param suggestParameters suggest parameters
* @param searchRequestOptions search request options
* @param context additional context that is passed through the Http pipeline during the service call
* @return suggests results
*/
public PagedIterable<SuggestResult> suggest(String searchText,
String suggesterName,
SuggestParameters suggestParameters,
SearchRequestOptions searchRequestOptions,
Context context) {
PagedFlux<SuggestResult> result = asyncClient.suggest(searchText,
suggesterName,
suggestParameters,
searchRequestOptions);
searchRequestOptions,
context);
return new PagedIterable<>(result);
}

Expand All @@ -281,17 +344,18 @@ public PagedIterable<SuggestResult> suggest(String searchText,
* @return document index result
*/
public DocumentIndexResult index(IndexBatch<?> batch) {
return this.indexWithResponse(batch).getValue();
return this.indexWithResponse(batch, Context.NONE).getValue();
}

/**
* Sends a batch of document write to the Azure Search index.
*
* @param batch batch of documents to send to the index with the requested action
* @param context additional context that is passed through the Http pipeline during the service call
* @return a response containing a document index result
*/
public Response<DocumentIndexResult> indexWithResponse(IndexBatch<?> batch) {
Mono<Response<DocumentIndexResult>> results = asyncClient.indexWithResponse(batch);
public Response<DocumentIndexResult> indexWithResponse(IndexBatch<?> batch, Context context) {
Mono<Response<DocumentIndexResult>> results = asyncClient.indexWithResponse(batch, context);
return blockWithOptionalTimeout(results, null);
}

Expand All @@ -303,8 +367,11 @@ public Response<DocumentIndexResult> indexWithResponse(IndexBatch<?> batch) {
* @return auto complete result
*/
public PagedIterable<AutocompleteItem> autocomplete(String searchText, String suggesterName) {
PagedFlux<AutocompleteItem> result = asyncClient.autocomplete(searchText, suggesterName, null, null);
return new PagedIterable<>(result);
return this.autocomplete(searchText,
suggesterName,
null,
null,
Context.NONE);
}

/**
Expand All @@ -320,10 +387,33 @@ public PagedIterable<AutocompleteItem> autocomplete(String searchText,
String suggesterName,
SearchRequestOptions searchRequestOptions,
AutocompleteParameters autocompleteParameters) {
return this.autocomplete(searchText,
suggesterName,
searchRequestOptions,
autocompleteParameters,
Context.NONE);
}

/**
* Autocompletes incomplete query terms based on input text and matching terms in the Azure Search index.
*
* @param searchText search text
* @param suggesterName suggester name
* @param searchRequestOptions search request options
* @param autocompleteParameters auto complete parameters
* @param context additional context that is passed through the Http pipeline during the service call
* @return auto complete result
*/
public PagedIterable<AutocompleteItem> autocomplete(String searchText,
String suggesterName,
SearchRequestOptions searchRequestOptions,
AutocompleteParameters autocompleteParameters,
Context context) {
PagedFlux<AutocompleteItem> result = asyncClient.autocomplete(searchText,
suggesterName,
searchRequestOptions,
autocompleteParameters);
suggesterName,
searchRequestOptions,
autocompleteParameters,
context);
return new PagedIterable<>(result);
}

Expand Down
Loading

0 comments on commit 25d992e

Please sign in to comment.