Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions sdk/search/azure-search-documents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ URL endpoint and admin key.

```java readme-sample-createIndexClient
SearchIndexClient searchIndexClient = new SearchIndexClientBuilder()
.endpoint(endpoint)
.credential(new AzureKeyCredential(apiKey))
.endpoint(ENDPOINT)
.credential(new AzureKeyCredential(API_KEY))
.buildClient();
```

or

```java readme-sample-createIndexAsyncClient
SearchIndexAsyncClient searchIndexAsyncClient = new SearchIndexClientBuilder()
.endpoint(endpoint)
.credential(new AzureKeyCredential(apiKey))
.endpoint(ENDPOINT)
.credential(new AzureKeyCredential(API_KEY))
.buildAsyncClient();
```

Expand All @@ -151,17 +151,17 @@ URL endpoint and admin key.

```java readme-sample-createIndexerClient
SearchIndexerClient searchIndexerClient = new SearchIndexerClientBuilder()
.endpoint(endpoint)
.credential(new AzureKeyCredential(apiKey))
.endpoint(ENDPOINT)
.credential(new AzureKeyCredential(API_KEY))
.buildClient();
```

or

```java readme-sample-createIndexerAsyncClient
SearchIndexerAsyncClient searchIndexerAsyncClient = new SearchIndexerClientBuilder()
.endpoint(endpoint)
.credential(new AzureKeyCredential(apiKey))
.endpoint(ENDPOINT)
.credential(new AzureKeyCredential(API_KEY))
.buildAsyncClient();
```

Expand All @@ -172,19 +172,19 @@ admin key, you can create the `SearchClient/SearchAsyncClient` with an existing

```java readme-sample-createSearchClient
SearchClient searchClient = new SearchClientBuilder()
.endpoint(endpoint)
.credential(new AzureKeyCredential(adminKey))
.indexName(indexName)
.endpoint(ENDPOINT)
.credential(new AzureKeyCredential(ADMIN_KEY))
.indexName(INDEX_NAME)
.buildClient();
```

or

```java readme-sample-createAsyncSearchClient
SearchAsyncClient searchAsyncClient = new SearchClientBuilder()
.endpoint(endpoint)
.credential(new AzureKeyCredential(adminKey))
.indexName(indexName)
.endpoint(ENDPOINT)
.credential(new AzureKeyCredential(ADMIN_KEY))
.indexName(INDEX_NAME)
.buildAsyncClient();
```

Expand Down Expand Up @@ -247,7 +247,7 @@ Let's explore them with a search for a "luxury" hotel.
enumerate over the results, and extract data using `SearchDocument`'s dictionary indexer.

```java readme-sample-searchWithDynamicType
for (SearchResult searchResult : searchClient.search("luxury")) {
for (SearchResult searchResult : SEARCH_CLIENT.search("luxury")) {
SearchDocument doc = searchResult.getDocument(SearchDocument.class);
String id = (String) doc.get("hotelId");
String name = (String) doc.get("hotelName");
Expand Down Expand Up @@ -287,7 +287,7 @@ public class Hotel {
Use it in place of `SearchDocument` when querying.

```java readme-sample-searchWithStronglyType
for (SearchResult searchResult : searchClient.search("luxury")) {
for (SearchResult searchResult : SEARCH_CLIENT.search("luxury")) {
Hotel doc = searchResult.getDocument(Hotel.class);
String id = doc.getId();
String name = doc.getName();
Expand All @@ -308,7 +308,7 @@ SearchOptions options = new SearchOptions()
.setFilter("rating ge 4")
.setOrderBy("rating desc")
.setTop(5);
SearchPagedIterable searchResultsIterable = searchClient.search("luxury", options, Context.NONE);
SearchPagedIterable searchResultsIterable = SEARCH_CLIENT.search("luxury", options, Context.NONE);
// ...
```

Expand All @@ -324,7 +324,7 @@ to configure the field of model class.

```java readme-sample-createIndexUseFieldBuilder
List<SearchField> searchFields = SearchIndexClient.buildSearchFields(Hotel.class, null);
searchIndexClient.createIndex(new SearchIndex("index", searchFields));
SEARCH_INDEX_CLIENT.createIndex(new SearchIndex("index", searchFields));
```

For advanced scenarios, we can build search fields using `SearchField` directly.
Expand Down Expand Up @@ -376,7 +376,7 @@ SearchSuggester suggester = new SearchSuggester("sg", Collections.singletonList(
// Prepare SearchIndex with index name and search fields.
SearchIndex index = new SearchIndex("hotels").setFields(searchFieldList).setSuggesters(suggester);
// Create an index
searchIndexClient.createIndex(index);
SEARCH_INDEX_CLIENT.createIndex(index);
```

### Retrieving a specific document from your index
Expand All @@ -386,7 +386,7 @@ your index if you already know the key. You could get the key from a query, for
information about it or navigate your customer to that document.

```java readme-sample-retrieveDocuments
Hotel hotel = searchClient.getDocument("1", Hotel.class);
Hotel hotel = SEARCH_CLIENT.getDocument("1", Hotel.class);
System.out.printf("This is hotelId %s, and this is hotel name %s.%n", hotel.getId(), hotel.getName());
```

Expand All @@ -400,7 +400,7 @@ to be aware of.
IndexDocumentsBatch<Hotel> batch = new IndexDocumentsBatch<>();
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);
SEARCH_CLIENT.indexDocuments(batch);
```

The request will throw `IndexBatchException` by default if any of the individual actions fail, and you can use
Expand All @@ -413,7 +413,7 @@ The examples so far have been using synchronous APIs, but we provide full suppor
to use [SearchAsyncClient](#create-a-searchclient).

```java readme-sample-searchWithAsyncClient
searchAsyncClient.search("luxury")
SEARCH_ASYNC_CLIENT.search("luxury")
.subscribe(result -> {
Hotel hotel = result.getDocument(Hotel.class);
System.out.printf("This is hotelId %s, and this is hotel name %s.%n", hotel.getId(), hotel.getName());
Expand All @@ -438,7 +438,7 @@ Any Search API operation that fails will throw an [`HttpResponseException`][Http

```java readme-sample-handleErrorsWithSyncClient
try {
Iterable<SearchResult> results = searchClient.search("hotel");
Iterable<SearchResult> results = SEARCH_CLIENT.search("hotel");
} catch (HttpResponseException ex) {
// The exception contains the HTTP status code and the detailed message
// returned from the search service
Expand Down
2 changes: 2 additions & 0 deletions sdk/search/azure-search-documents/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
--add-reads com.azure.core.test=ALL-UNNAMED
--add-reads com.azure.core.http.netty=ALL-UNNAMED
</javaModulesSurefireArgLine>

<spotbugs.includeTests>true</spotbugs.includeTests>
</properties>

<dependencies>
Expand Down
Loading