From 927fa4393743ffb16ab4480ee0ff6e9efaa86d1f Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Tue, 7 Jul 2020 12:15:31 -0700 Subject: [PATCH] Update Search APIs Based on Review (#12791) * Remove vararg APIs from IndexDocumentsBatch * Update README codesnippets --- sdk/search/azure-search-documents/README.md | 4 +- .../search/documents/SearchAsyncClient.java | 10 +- .../indexes/models/IndexDocumentsBatch.java | 111 ++++-------------- .../IndexContentManagementExample.java | 5 +- .../azure/search/documents/ReadmeSamples.java | 4 +- .../documents/SearchJavaDocCodeSnippets.java | 16 +-- .../search/documents/IndexBatchTests.java | 58 ++++----- .../search/documents/IndexingSyncTests.java | 32 ++--- .../search/documents/LookupSyncTests.java | 6 +- 9 files changed, 94 insertions(+), 152 deletions(-) diff --git a/sdk/search/azure-search-documents/README.md b/sdk/search/azure-search-documents/README.md index 3105eed5d2468..947c0b0df4655 100644 --- a/sdk/search/azure-search-documents/README.md +++ b/sdk/search/azure-search-documents/README.md @@ -412,8 +412,8 @@ to be aware of. ```Java IndexDocumentsBatch batch = new IndexDocumentsBatch(); -batch.addUploadActions(new Hotel().setId("783").setName("Upload Inn")); -batch.addMergeActions(new Hotel().setId("12").setName("Renovated Ranch")); +batch.addUploadActions(Collections.singletonList(new Hotel().setId("783").setName("Upload Inn"))); +batch.addMergeActions(Collections.singletonList(new Hotel().setId("12").setName("Renovated Ranch"))); searchClient.indexDocuments(batch); ``` diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/SearchAsyncClient.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/SearchAsyncClient.java index eff449625e7ff..66950b98e0b95 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/SearchAsyncClient.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/SearchAsyncClient.java @@ -704,9 +704,8 @@ private static Map> getFacets(SearchDocumentsResult re Map> facets = new HashMap<>(); - result.getFacets().forEach((key, values) -> { - facets.put(key, values.stream().map(FacetResultConverter::map).collect(Collectors.toList())); - }); + result.getFacets().forEach((key, values) -> + facets.put(key, values.stream().map(FacetResultConverter::map).collect(Collectors.toList()))); return facets; } @@ -951,10 +950,11 @@ private static AutocompleteRequest createAutoCompleteRequest(String searchText, } private static IndexDocumentsBatch buildIndexBatch(Iterable documents, IndexActionType actionType) { - List> actions = new ArrayList>(); + List> actions = new ArrayList<>(); documents.forEach(d -> actions.add(new IndexAction() .setActionType(actionType) .setDocument(d))); - return new IndexDocumentsBatch(actions); + + return new IndexDocumentsBatch().addActions(actions); } } diff --git a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/IndexDocumentsBatch.java b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/IndexDocumentsBatch.java index 038738b4d1d23..857e1237157e8 100644 --- a/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/IndexDocumentsBatch.java +++ b/sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/indexes/models/IndexDocumentsBatch.java @@ -10,8 +10,6 @@ import com.azure.search.documents.models.IndexBatchBase; import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; /** * Contains a batch of document write actions to send to the index. @@ -22,35 +20,25 @@ public class IndexDocumentsBatch extends IndexBatchBase { * Constructor of {@link IndexDocumentsBatch}. */ public IndexDocumentsBatch() { - super(new ArrayList>()); + super(new ArrayList<>()); } /** - * Constructor of {@link IndexDocumentsBatch} + * Adds document index actions to the batch. * - * @param actions the actions value to set. + * @param actions Index actions. + * @return The updated IndexDocumentsBatch object. */ - public IndexDocumentsBatch(List> actions) { - super(actions); - } - - /** - * Adds an Upload IndexAction to the IndexAction chain for a document. - * - * @param documents The documents to be uploaded. - * @return IndexBatch with the desired actions added. - */ - @SuppressWarnings("unchecked") - public IndexDocumentsBatch addUploadActions(T... documents) { - addDocumentActions(Arrays.asList(documents), IndexActionType.UPLOAD); + public IndexDocumentsBatch addActions(Iterable> actions) { + actions.forEach(action -> this.getActions().add(action)); return this; } /** - * Adds Upload IndexActions to the IndexAction chain for a collection of documents. + * Adds upload document actions to the batch. * - * @param documents The document collection to be uploaded. - * @return IndexBatch with the desired actions added. + * @param documents Documents to be uploaded. + * @return The updated IndexDocumentsBatch object. */ public IndexDocumentsBatch addUploadActions(Iterable documents) { addDocumentActions(documents, IndexActionType.UPLOAD); @@ -58,22 +46,10 @@ public IndexDocumentsBatch addUploadActions(Iterable documents) { } /** - * Adds a Delete IndexAction to the IndexAction chain for a document. - * - * @param documents The documents to be deleted. - * @return IndexBatch with the desired actions added. - */ - @SuppressWarnings("unchecked") - public IndexDocumentsBatch addDeleteActions(T... documents) { - addDocumentActions(Arrays.asList(documents), IndexActionType.DELETE); - return this; - } - - /** - * Adds Delete IndexActions to the IndexAction chain for a collection of documents. + * Adds document delete actions to the batch. * - * @param documents The document collection to be deleted. - * @return IndexBatch with the desired actions added. + * @param documents Document to be deleted. + * @return The updated IndexDocumentsBatch object. */ public IndexDocumentsBatch addDeleteActions(Iterable documents) { addDocumentActions(documents, IndexActionType.DELETE); @@ -81,11 +57,11 @@ public IndexDocumentsBatch addDeleteActions(Iterable documents) { } /** - * Adds Delete IndexActions to the IndexAction chain for a collection of documents. + * Adds document delete actions based on key IDs to the batch. * - * @param keyName The name of the key field that uniquely identifies documents in the index. - * @param keyValues The keys of the documents to delete. - * @return IndexBatch with the desired actions added. + * @param keyName The key field name. + * @param keyValues Keys of the documents to delete. + * @return The updated IndexDocumentsBatch object. */ @SuppressWarnings({"unchecked", "rawtypes"}) public IndexDocumentsBatch addDeleteActions(String keyName, Iterable keyValues) { @@ -101,33 +77,10 @@ public IndexDocumentsBatch addDeleteActions(String keyName, Iterable } /** - * Adds Delete IndexActions to the IndexAction chain for a collection of documents. - * - * @param keyName The name of the key field that uniquely identifies documents in the index. - * @param keyValues The keys of the documents to delete. - * @return IndexBatch with the desired actions added. - */ - public IndexDocumentsBatch addDeleteActions(String keyName, String... keyValues) { - return this.addDeleteActions(keyName, Arrays.asList(keyValues)); - } - - /** - * Adds a Merge IndexAction to the IndexAction chain for a document. - * - * @param documents The documents to be merged. - * @return IndexBatch with the desired actions added. - */ - @SuppressWarnings("unchecked") - public IndexDocumentsBatch addMergeActions(T... documents) { - addDocumentActions(Arrays.asList(documents), IndexActionType.MERGE); - return this; - } - - /** - * Adds Merge IndexActions to the IndexAction chain for a collection of documents. + * Adds merge document actions to the batch.. * - * @param documents The document collection to be merged. - * @return IndexBatch with the desired actions added. + * @param documents Documents to be merged. + * @return The updated IndexDocumentsBatch object. */ public IndexDocumentsBatch addMergeActions(Iterable documents) { addDocumentActions(documents, IndexActionType.MERGE); @@ -135,22 +88,10 @@ public IndexDocumentsBatch addMergeActions(Iterable documents) { } /** - * Adds a Merge or Upload IndexAction to the IndexAction chain for a document. - * - * @param documents The documents to be merged or uploaded. - * @return IndexBatch with the desired actions added. - */ - @SuppressWarnings("unchecked") - public IndexDocumentsBatch addMergeOrUploadActions(T... documents) { - addDocumentActions(Arrays.asList(documents), IndexActionType.MERGE_OR_UPLOAD); - return this; - } - - /** - * Adds Merge or Upload IndexActions to the IndexAction chain for a collection of documents. + * Adds merge or upload document actions to the batch. * - * @param documents The document collection to be merged or uploaded. - * @return IndexBatch with the desired actions added. + * @param documents Documents to be merged or uploaded. + * @return The updated IndexDocumentsBatch object. */ public IndexDocumentsBatch addMergeOrUploadActions(Iterable documents) { addDocumentActions(documents, IndexActionType.MERGE_OR_UPLOAD); @@ -158,10 +99,8 @@ public IndexDocumentsBatch addMergeOrUploadActions(Iterable documents) { } private void addDocumentActions(Iterable documents, IndexActionType actionType) { - documents.forEach(d -> { - this.getActions().add(new IndexAction() - .setActionType(actionType) - .setDocument(d)); - }); + documents.forEach(d -> this.getActions().add(new IndexAction() + .setActionType(actionType) + .setDocument(d))); } } diff --git a/sdk/search/azure-search-documents/src/samples/java/com/azure/search/documents/IndexContentManagementExample.java b/sdk/search/azure-search-documents/src/samples/java/com/azure/search/documents/IndexContentManagementExample.java index f8d8a9983c716..fc537ac0fd8ee 100644 --- a/sdk/search/azure-search-documents/src/samples/java/com/azure/search/documents/IndexContentManagementExample.java +++ b/sdk/search/azure-search-documents/src/samples/java/com/azure/search/documents/IndexContentManagementExample.java @@ -10,6 +10,7 @@ import com.azure.search.documents.models.IndexDocumentsResult; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -66,8 +67,8 @@ private static void advancedIndexing() { .buildClient(); IndexDocumentsBatch batch = new IndexDocumentsBatch() - .addMergeOrUploadActions(new Hotel().setHotelId("100")) - .addDeleteActions(new Hotel().setHotelId("200")); + .addMergeOrUploadActions(Collections.singletonList(new Hotel().setHotelId("100"))) + .addDeleteActions(Collections.singletonList(new Hotel().setHotelId("200"))); // Send a single batch that performs many different actions IndexDocumentsResult result = client.indexDocuments(batch); diff --git a/sdk/search/azure-search-documents/src/samples/java/com/azure/search/documents/ReadmeSamples.java b/sdk/search/azure-search-documents/src/samples/java/com/azure/search/documents/ReadmeSamples.java index 3d684fd1ae873..7559c905983b5 100644 --- a/sdk/search/azure-search-documents/src/samples/java/com/azure/search/documents/ReadmeSamples.java +++ b/sdk/search/azure-search-documents/src/samples/java/com/azure/search/documents/ReadmeSamples.java @@ -215,8 +215,8 @@ public void retrieveDocuments() { public void batchDocumentsOperations() { IndexDocumentsBatch batch = new IndexDocumentsBatch(); - batch.addUploadActions(new Hotel().setId("783").setName("Upload Inn")); - batch.addMergeActions(new Hotel().setId("12").setName("Renovated Ranch")); + batch.addUploadActions(Collections.singletonList(new Hotel().setId("783").setName("Upload Inn"))); + batch.addMergeActions(Collections.singletonList(new Hotel().setId("12").setName("Renovated Ranch"))); searchClient.indexDocuments(batch); } diff --git a/sdk/search/azure-search-documents/src/samples/java/com/azure/search/documents/SearchJavaDocCodeSnippets.java b/sdk/search/azure-search-documents/src/samples/java/com/azure/search/documents/SearchJavaDocCodeSnippets.java index 62c6b34a4ab3c..39702f0996813 100644 --- a/sdk/search/azure-search-documents/src/samples/java/com/azure/search/documents/SearchJavaDocCodeSnippets.java +++ b/sdk/search/azure-search-documents/src/samples/java/com/azure/search/documents/SearchJavaDocCodeSnippets.java @@ -220,8 +220,8 @@ public void indexDocuments() { searchDocument2.put("hotelId", "2"); searchDocument2.put("hotelName", "test2"); IndexDocumentsBatch indexDocumentsBatch = new IndexDocumentsBatch<>(); - indexDocumentsBatch.addUploadActions(searchDocument1); - indexDocumentsBatch.addDeleteActions(searchDocument2); + indexDocumentsBatch.addUploadActions(Collections.singletonList(searchDocument1)); + indexDocumentsBatch.addDeleteActions(Collections.singletonList(searchDocument2)); IndexDocumentsResult result = searchClient.indexDocuments(indexDocumentsBatch); for (IndexingResult indexingResult : result.getResults()) { System.out.printf("Does document with key %s finish successfully? %b%n", indexingResult.getKey(), @@ -242,8 +242,8 @@ public void indexDocumentsWithResponse() { searchDocument2.put("hotelId", "2"); searchDocument2.put("hotelName", "test2"); IndexDocumentsBatch indexDocumentsBatch = new IndexDocumentsBatch<>(); - indexDocumentsBatch.addUploadActions(searchDocument1); - indexDocumentsBatch.addDeleteActions(searchDocument2); + indexDocumentsBatch.addUploadActions(Collections.singletonList(searchDocument1)); + indexDocumentsBatch.addDeleteActions(Collections.singletonList(searchDocument2)); Response resultResponse = searchClient.indexDocumentsWithResponse(indexDocumentsBatch, null, new Context(key1, value1)); System.out.println("The status code of the response is " + resultResponse.getStatusCode()); @@ -561,8 +561,8 @@ public void indexDocumentsAsync() { searchDocument2.put("hotelId", "2"); searchDocument2.put("hotelName", "test2"); IndexDocumentsBatch indexDocumentsBatch = new IndexDocumentsBatch<>(); - indexDocumentsBatch.addUploadActions(searchDocument1); - indexDocumentsBatch.addDeleteActions(searchDocument2); + indexDocumentsBatch.addUploadActions(Collections.singletonList(searchDocument1)); + indexDocumentsBatch.addDeleteActions(Collections.singletonList(searchDocument2)); searchAsyncClient.indexDocuments(indexDocumentsBatch) .subscribe(result -> { for (IndexingResult indexingResult : result.getResults()) { @@ -585,8 +585,8 @@ public void indexDocumentsWithResponseAsync() { searchDocument2.put("hotelId", "2"); searchDocument2.put("hotelName", "test2"); IndexDocumentsBatch indexDocumentsBatch = new IndexDocumentsBatch<>(); - indexDocumentsBatch.addUploadActions(searchDocument1); - indexDocumentsBatch.addDeleteActions(searchDocument2); + indexDocumentsBatch.addUploadActions(Collections.singletonList(searchDocument1)); + indexDocumentsBatch.addDeleteActions(Collections.singletonList(searchDocument2)); searchAsyncClient.indexDocumentsWithResponse(indexDocumentsBatch, null) .subscribe(resultResponse -> { System.out.println("The status code of the response is " + resultResponse.getStatusCode()); diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/IndexBatchTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/IndexBatchTests.java index 8e1560b4bbb77..7513e7b940107 100644 --- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/IndexBatchTests.java +++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/IndexBatchTests.java @@ -2,9 +2,9 @@ // Licensed under the MIT License. package com.azure.search.documents; +import com.azure.search.documents.indexes.models.IndexDocumentsBatch; import com.azure.search.documents.models.IndexAction; import com.azure.search.documents.models.IndexActionType; -import com.azure.search.documents.indexes.models.IndexDocumentsBatch; import org.junit.jupiter.api.Test; import java.util.ArrayList; @@ -26,11 +26,11 @@ public void uploadDocument() { .setActionType(IndexActionType.UPLOAD) .setDocument(searchDocument); - IndexDocumentsBatch expected = new IndexDocumentsBatch( - Collections.singletonList(indexAction)); + IndexDocumentsBatch expected = new IndexDocumentsBatch() + .addActions(Collections.singletonList(indexAction)); IndexDocumentsBatch actual = new IndexDocumentsBatch() - .addUploadActions(searchDocument); + .addUploadActions(Collections.singletonList(searchDocument)); validate(expected, actual); } @@ -51,7 +51,8 @@ public void uploadDocuments() { .map(doc -> new IndexAction().setActionType(IndexActionType.UPLOAD).setDocument(doc)) .collect(Collectors.toList()); - IndexDocumentsBatch expectedBatch = new IndexDocumentsBatch(indexActions); + IndexDocumentsBatch expectedBatch = new IndexDocumentsBatch() + .addActions(indexActions); IndexDocumentsBatch actualBatch = new IndexDocumentsBatch() .addUploadActions(docs); @@ -68,11 +69,11 @@ public void mergeDocument() { .setActionType(IndexActionType.MERGE) .setDocument(searchDocument); - IndexDocumentsBatch expected = new IndexDocumentsBatch( - Collections.singletonList(indexAction)); + IndexDocumentsBatch expected = new IndexDocumentsBatch() + .addActions(Collections.singletonList(indexAction)); IndexDocumentsBatch actual = new IndexDocumentsBatch() - .addMergeActions(searchDocument); + .addMergeActions(Collections.singletonList(searchDocument)); validate(expected, actual); } @@ -93,7 +94,8 @@ public void mergeDocuments() { .map(doc -> new IndexAction().setActionType(IndexActionType.MERGE).setDocument(doc)) .collect(Collectors.toList()); - IndexDocumentsBatch expectedBatch = new IndexDocumentsBatch(indexActions); + IndexDocumentsBatch expectedBatch = new IndexDocumentsBatch() + .addActions(indexActions); IndexDocumentsBatch actualBatch = new IndexDocumentsBatch() .addMergeActions(docs); @@ -110,11 +112,11 @@ public void mergeOrUploadDocument() { .setActionType(IndexActionType.MERGE_OR_UPLOAD) .setDocument(searchDocument); - IndexDocumentsBatch expected = new IndexDocumentsBatch( - Collections.singletonList(indexAction)); + IndexDocumentsBatch expected = new IndexDocumentsBatch() + .addActions(Collections.singletonList(indexAction)); IndexDocumentsBatch actual = new IndexDocumentsBatch() - .addMergeOrUploadActions(searchDocument); + .addMergeOrUploadActions(Collections.singletonList(searchDocument)); validate(expected, actual); } @@ -135,7 +137,8 @@ public void mergeOrUploadDocuments() { .map(doc -> new IndexAction().setActionType(IndexActionType.MERGE_OR_UPLOAD).setDocument(doc)) .collect(Collectors.toList()); - IndexDocumentsBatch expectedBatch = new IndexDocumentsBatch(indexActions); + IndexDocumentsBatch expectedBatch = new IndexDocumentsBatch() + .addActions(indexActions); IndexDocumentsBatch actualBatch = new IndexDocumentsBatch() .addMergeOrUploadActions(docs); @@ -152,11 +155,11 @@ public void deleteDocument() { .setActionType(IndexActionType.DELETE) .setDocument(searchDocument); - IndexDocumentsBatch expected = new IndexDocumentsBatch( - Collections.singletonList(indexAction)); + IndexDocumentsBatch expected = new IndexDocumentsBatch() + .addActions(Collections.singletonList(indexAction)); IndexDocumentsBatch actual = new IndexDocumentsBatch() - .addDeleteActions(searchDocument); + .addDeleteActions(Collections.singletonList(searchDocument)); validate(expected, actual); } @@ -177,7 +180,8 @@ public void deleteDocuments() { .map(doc -> new IndexAction().setActionType(IndexActionType.DELETE).setDocument(doc)) .collect(Collectors.toList()); - IndexDocumentsBatch expectedBatch = new IndexDocumentsBatch(indexActions); + IndexDocumentsBatch expectedBatch = new IndexDocumentsBatch() + .addActions(indexActions); IndexDocumentsBatch actualBatch = new IndexDocumentsBatch() .addDeleteActions(docs); @@ -215,14 +219,14 @@ public void canBuildIndexBatchWithMultipleActionsAndSingleDocument() { .setActionType(IndexActionType.UPLOAD) .setDocument(documentToUpload); - IndexDocumentsBatch expected = new IndexDocumentsBatch( - Arrays.asList(mergeAction, mergeOrUploadAction, deleteAction, uploadAction)); + IndexDocumentsBatch expected = new IndexDocumentsBatch() + .addActions(Arrays.asList(mergeAction, mergeOrUploadAction, deleteAction, uploadAction)); IndexDocumentsBatch actual = new IndexDocumentsBatch() - .addMergeActions(documentToMerge) - .addMergeOrUploadActions(documentToMergeOrUpload) - .addDeleteActions(documentToDelete) - .addUploadActions(documentToUpload); + .addMergeActions(Collections.singletonList(documentToMerge)) + .addMergeOrUploadActions(Collections.singletonList(documentToMergeOrUpload)) + .addDeleteActions(Collections.singletonList(documentToDelete)) + .addUploadActions(Collections.singletonList(documentToUpload)); validate(expected, actual); } @@ -301,8 +305,8 @@ public void canBuildIndexBatchWithMultipleActionsAndMultipleDocuments() { .setActionType(IndexActionType.UPLOAD) .setDocument(documentsToUpload.get(1)); - IndexDocumentsBatch expected = new IndexDocumentsBatch( - Arrays.asList( + IndexDocumentsBatch expected = new IndexDocumentsBatch() + .addActions(Arrays.asList( mergeAction1, mergeAction2, mergeOrUploadAction1, @@ -310,9 +314,7 @@ public void canBuildIndexBatchWithMultipleActionsAndMultipleDocuments() { deleteAction1, deleteAction2, uploadAction1, - uploadAction2 - ) - ); + uploadAction2)); IndexDocumentsBatch actual = new IndexDocumentsBatch() .addMergeActions(documentsToMerge) diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/IndexingSyncTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/IndexingSyncTests.java index 1e9bf3ab965fe..e4e1a084bb13d 100644 --- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/IndexingSyncTests.java +++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/IndexingSyncTests.java @@ -130,7 +130,7 @@ public void canDeleteBatchByKeys() { assertEquals(2, client.getDocumentCount()); IndexDocumentsBatch deleteBatch = new IndexDocumentsBatch() - .addDeleteActions("HotelId", "1", "2"); + .addDeleteActions("HotelId", Arrays.asList("1", "2")); IndexDocumentsResult documentIndexResult = client.indexDocuments(deleteBatch); waitForIndexing(); @@ -201,11 +201,11 @@ public void canIndexStaticallyTypedDocuments() throws ParseException { Hotel randomHotel = prepareStaticallyTypedHotel("randomId"); // deleting a non existing document IndexDocumentsBatch batch = new IndexDocumentsBatch() - .addUploadActions(hotel1) - .addDeleteActions(randomHotel) - .addMergeActions(nonExistingHotel) - .addMergeOrUploadActions(hotel3) - .addUploadActions(hotel2); + .addUploadActions(Collections.singletonList(hotel1)) + .addDeleteActions(Collections.singletonList(randomHotel)) + .addMergeActions(Collections.singletonList(nonExistingHotel)) + .addMergeOrUploadActions(Collections.singletonList(hotel3)) + .addUploadActions(Collections.singletonList(hotel2)); try { client.indexDocumentsWithResponse(batch, new IndexDocumentsOptions().setThrowOnAnyError(true), @@ -246,11 +246,11 @@ public void canIndexDynamicDocumentsNotThrow() { SearchDocument randomHotel = prepareDynamicallyTypedHotel("randomId"); // deleting a non existing document IndexDocumentsBatch batch = new IndexDocumentsBatch() - .addUploadActions(hotel1) - .addDeleteActions(randomHotel) - .addMergeActions(nonExistingHotel) - .addMergeOrUploadActions(hotel3) - .addUploadActions(hotel2); + .addUploadActions(Collections.singletonList(hotel1)) + .addDeleteActions(Collections.singletonList(randomHotel)) + .addMergeActions(Collections.singletonList(nonExistingHotel)) + .addMergeOrUploadActions(Collections.singletonList(hotel3)) + .addUploadActions(Collections.singletonList(hotel2)); Response resultResponse = client.indexDocumentsWithResponse(batch, new IndexDocumentsOptions().setThrowOnAnyError(false), Context.NONE); @@ -283,11 +283,11 @@ public void canIndexDynamicDocumentsThrowOnError() { SearchDocument randomHotel = prepareDynamicallyTypedHotel("randomId"); // deleting a non existing document IndexDocumentsBatch batch = new IndexDocumentsBatch() - .addUploadActions(hotel1) - .addDeleteActions(randomHotel) - .addMergeActions(nonExistingHotel) - .addMergeOrUploadActions(hotel3) - .addUploadActions(hotel2); + .addUploadActions(Collections.singletonList(hotel1)) + .addDeleteActions(Collections.singletonList(randomHotel)) + .addMergeActions(Collections.singletonList(nonExistingHotel)) + .addMergeOrUploadActions(Collections.singletonList(hotel3)) + .addUploadActions(Collections.singletonList(hotel2)); try { client.indexDocuments(batch); diff --git a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/LookupSyncTests.java b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/LookupSyncTests.java index c01d2bfc8e0a5..4d4838b7b99d2 100644 --- a/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/LookupSyncTests.java +++ b/sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/LookupSyncTests.java @@ -279,7 +279,7 @@ public void getDynamicDocumentCannotAlwaysDetermineCorrectType() { // expectedDoc.put("Location", createPointGeometryString(40.760586, -73.975403)); expectedDoc.put("Rooms", Collections.singletonList(new SearchDocument(Collections.singletonMap("BaseRate", "NaN")))); - client.indexDocuments(new IndexDocumentsBatch<>().addUploadActions(indexedDoc)); + client.indexDocuments(new IndexDocumentsBatch<>().addUploadActions(Collections.singletonList(indexedDoc))); // Select only the fields set in the test case so we don't get superfluous data back. List selectedFields = Arrays.asList("HotelId", "LastRenovationDate", "Location", "Rooms/BaseRate"); @@ -296,7 +296,7 @@ public void canGetDocumentWithBase64EncodedKey() { SearchDocument expectedDoc = new SearchDocument(); expectedDoc.put("HotelId", complexKey); - client.indexDocuments(new IndexDocumentsBatch<>().addUploadActions(expectedDoc)); + client.indexDocuments(new IndexDocumentsBatch<>().addUploadActions(Collections.singletonList(expectedDoc))); assertEquals(client.getDocumentWithResponse(complexKey, SearchDocument.class, new ArrayList<>(expectedDoc.keySet()), Context.NONE).getValue(), expectedDoc); } @@ -314,7 +314,7 @@ public void roundTrippingDateTimeOffsetNormalizesToUtc() { expectedDoc.put("LastRenovationDate", OffsetDateTime.parse("2010-06-27T08:00Z")); - client.indexDocuments(new IndexDocumentsBatch<>().addUploadActions(indexedDoc)); + client.indexDocuments(new IndexDocumentsBatch<>().addUploadActions(Collections.singletonList(indexedDoc))); SearchDocument actualDoc = client.getDocumentWithResponse("1", SearchDocument.class, new ArrayList<>(expectedDoc.keySet()), Context.NONE).getValue(); assertMapEquals(expectedDoc, actualDoc, false);