Skip to content

Commit

Permalink
Search Index Client builders (Azure#9)
Browse files Browse the repository at this point in the history
* Data sdk v3 draft (Initial version)

* Generated java data plane sdk using autorest v3 (azure-arm flag set to 'off')
* Adding initial interface for the SearchIndexClient (and stubs)
* adding generate script (with automatic spec fetching and tweaking)
* adding pom.xml
* adding some setup docs and customization stubs
* Fixing BOM header issue in azure core
  • Loading branch information
navalev authored and eladiw committed Aug 7, 2019
1 parent 2236da7 commit 3b68aa9
Show file tree
Hide file tree
Showing 21 changed files with 954 additions and 327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ private HttpRequest createHttpRequest(SwaggerMethodParser methodParser, Object[]

final String host = methodParser.host(args);
urlBuilder.host(host);
String previousPath = urlBuilder.path();
// Todo: This is a temporary change just to get the CSE team unblocked and
// SHOULD NOT be merged back into the main repo
if (previousPath.equals("")) {
urlBuilder.path(path);
} else {
urlBuilder.path(previousPath + "/" + path);
}
}

for (final EncodedParameter queryParameter : methodParser.encodedQueryParameters(args)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class JacksonAdapter implements SerializerAdapter {
*/
private static SerializerAdapter serializerAdapter;

/*
* BOM header from some response bodies. To be removed in deserialization.
*/
private static final String BOM = "\uFEFF";

/**
* Creates a new JacksonAdapter instance with default mapper settings.
*/
Expand Down Expand Up @@ -135,10 +140,13 @@ public String serializeList(List<?> list, CollectionFormat format) {
@Override
@SuppressWarnings("unchecked")
public <T> T deserialize(String value, final Type type, SerializerEncoding encoding) throws IOException {
if (value == null || value.isEmpty()) {
if (value == null || value.isEmpty() || value.equals(BOM)) {
return null;
}

// Remove BOM
if (value.startsWith(BOM)) {
value = value.replaceFirst(BOM, "");
}
final JavaType javaType = createJavaType(type);
try {
if (encoding == SerializerEncoding.XML) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Setting up the IntelliJ IDE

1. Open IntelliJ and import a new project using the pom.xml file
2. Go to the View->Tool Windows->Maven
3. Click add, browse for sdk/core/pom.xml file
4. Click 'reimport all Maven projects'
5. Build the project
11 changes: 10 additions & 1 deletion search/data-plane/data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,18 @@
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.0.0-preview.3</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.azure.search</groupId>
<artifactId>service</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package com.azure.search.data;

import com.azure.core.http.rest.PagedFlux;
import com.azure.search.data.generated.models.*;
import reactor.core.publisher.Mono;

import java.util.List;

/**
* The public (Customer facing) interface for SearchIndexASyncClient.
*/
public interface SearchIndexASyncClient {
// Indices

/**
* Gets Client Api Version.
*
* @return the apiVersion value.
*/
String getApiVersion();

/**
* Gets The name of the Azure Search service.
*
* @return the searchServiceName value.
*/
String getSearchServiceName();

/**
* Gets The DNS suffix of the Azure Search service. The default is search.windows.net.
*
* @return the searchDnsSuffix value.
*/
String getSearchDnsSuffix();

/**
* Gets The name of the Azure Search index.
*
* @return the indexName value.
*/
String getIndexName();

/**
* Sets The name of the Azure Search index.
*
* @param indexName the indexName value.
* @return the service client itself.
*/
SearchIndexASyncClient setIndexName(String indexName);


// Index Operations

/**
* Gets the number of documents
*
* @return the number of documents.
*/
Mono<Long> countDocuments();

/**
* Searches for documents in the Azure Search index
*
* @return the document search result.
*/
PagedFlux<SearchResult> search();

/**
* Searches for documents in the Azure Search index
*
* @return the document search result.
*/
PagedFlux<SearchResult> search(String searchText,
SearchParameters searchParameters,
SearchRequestOptions searchRequestOptions);

/**
* Retrieves a document from the Azure Search index.
*
* @param key the name of the document
* @return
*/
Mono<Object> getDocument(String key);

/**
* Retrieves a document from the Azure Search index.
*
* @param key
* @param selectedFields
* @param searchRequestOptions
* @return
*/
Mono<Object> getDocument(String key, List<String> selectedFields, SearchRequestOptions searchRequestOptions);

/**
* Suggests documents in the Azure Search index that match the given partial query text.
*
* @param searchText
* @param suggesterName
* @return
*/
PagedFlux<SuggestResult> suggest(String searchText, String suggesterName);

/**
* Suggests documents in the Azure Search index that match the given partial query text.
*
* @param searchText
* @param suggesterName
* @param suggestParameters
* @param searchRequestOptions
* @return
*/
PagedFlux<SuggestResult> suggest(String searchText, String suggesterName, SuggestParameters suggestParameters, SearchRequestOptions searchRequestOptions);

/**
* Sends a batch of document write actions to the Azure Search index.
*
* @param batch
* @return
*/
Mono<DocumentIndexResult> index(IndexBatch batch);

/**
* Autocompletes incomplete query terms based on input text and matching terms in the Azure Search index.
*
* @param searchText
* @param suggesterName
* @return
*/
Mono<AutocompleteResult> autocomplete(String searchText, String suggesterName);

/**
* Autocompletes incomplete query terms based on input text and matching terms in the Azure Search index.
*
* @param searchText
* @param suggesterName
* @param searchRequestOptions
* @param autocompleteParameters
* @return
*/
Mono<AutocompleteResult> autocomplete(String searchText, String suggesterName, SearchRequestOptions searchRequestOptions, AutocompleteParameters autocompleteParameters);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.azure.search.data;

import com.azure.core.http.rest.PagedFlux;
import com.azure.search.data.generated.models.*;
import reactor.core.publisher.Mono;

import java.util.List;

Expand All @@ -25,29 +23,13 @@ public interface SearchIndexClient {
*/
String getSearchServiceName();

/**
* Sets The name of the Azure Search service.
*
* @param searchServiceName the searchServiceName value.
* @return the service client itself.
*/
SearchIndexClient setSearchServiceName(String searchServiceName);

/**
* Gets The DNS suffix of the Azure Search service. The default is search.windows.net.
*
* @return the searchDnsSuffix value.
*/
String getSearchDnsSuffix();

/**
* Sets The DNS suffix of the Azure Search service. The default is search.windows.net.
*
* @param searchDnsSuffix the searchDnsSuffix value.
* @return the service client itself.
*/
SearchIndexClient setSearchDnsSuffix(String searchDnsSuffix);

/**
* Gets The name of the Azure Search index.
*
Expand All @@ -71,80 +53,87 @@ public interface SearchIndexClient {
*
* @return the number of documents.
*/
Mono<Long> countDocuments();
Long countDocuments();

/**
* Searches for documents in the Azure Search index
*
* @return the document search result.
*/
PagedFlux<SearchResult> search();
DocumentSearchResult search();

/**
* Searches for documents in the Azure Search index
*
* @return the document search result.
*/
PagedFlux<SearchResult> search(String searchText,
SearchParameters searchParameters,
SearchRequestOptions searchRequestOptions);
DocumentSearchResult search(String searchText,
SearchParameters searchParameters,
SearchRequestOptions searchRequestOptions);

/**
* Retrieves a document from the Azure Search index.
*
* @param key the name of the document
* @return
*/
Mono<Object> getDocument(String key);
Object getDocument(String key);

/**
* Retrieves a document from the Azure Search index.
*
* @param key
* @param selectedFields
* @param searchRequestOptions
* @return
*/
Mono<Object> getDocument(String key, List<String> selectedFields, SearchRequestOptions searchRequestOptions);
Object getDocument(String key, List<String> selectedFields, SearchRequestOptions searchRequestOptions);

/**
* Suggests documents in the Azure Search index that match the given partial query text.
*
* @param searchText
* @param suggesterName
* @return
*/
PagedFlux<SuggestResult> suggest(String searchText, String suggesterName);
DocumentSuggestResult suggest(String searchText, String suggesterName);

/**
* Suggests documents in the Azure Search index that match the given partial query text.
*
* @param searchText
* @param suggesterName
* @param suggestParameters
* @param searchRequestOptions
* @return
*/
PagedFlux<SuggestResult> suggest(String searchText, String suggesterName, SuggestParameters suggestParameters, SearchRequestOptions searchRequestOptions);
DocumentSuggestResult suggest(String searchText, String suggesterName, SuggestParameters suggestParameters, SearchRequestOptions searchRequestOptions);

/**
* Sends a batch of document write actions to the Azure Search index.
*
* @param batch
* @return
*/
Mono<DocumentIndexResult> index(IndexBatch batch);
DocumentIndexResult index(IndexBatch batch);

/**
* Autocompletes incomplete query terms based on input text and matching terms in the Azure Search index.
*
* @param searchText
* @param suggesterName
* @return
*/
Mono<AutocompleteResult> autocomplete(String searchText, String suggesterName);
AutocompleteResult autocomplete(String searchText, String suggesterName);

/**
* Autocompletes incomplete query terms based on input text and matching terms in the Azure Search index.
*
* @param searchText
* @param suggesterName
* @param searchRequestOptions
* @param autocompleteParameters
* @return
*/
Mono<AutocompleteResult> autocomplete(String searchText, String suggesterName, SearchRequestOptions searchRequestOptions, AutocompleteParameters autocompleteParameters);
AutocompleteResult autocomplete(String searchText, String suggesterName, SearchRequestOptions searchRequestOptions, AutocompleteParameters autocompleteParameters);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.azure.search.data;

/**
* The Fluent client builder.
*/
public interface SearchIndexClientBuilder {

// Fluent builders
SearchIndexClient buildClient();

SearchIndexASyncClient buildAsyncClient();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.azure.search.data.common;

import com.azure.core.http.HttpPipelineCallContext;
import com.azure.core.http.HttpPipelineNextPolicy;
import com.azure.core.http.HttpResponse;
import com.azure.core.http.policy.HttpPipelinePolicy;
import org.apache.commons.lang3.StringUtils;
import reactor.core.publisher.Mono;

public class SearchPipelinePolicy implements HttpPipelinePolicy {

private String apiKey;

public SearchPipelinePolicy(String apiKey) {
if (StringUtils.isBlank(apiKey)) {
throw new IllegalArgumentException("Invalid apiKey");
}
this.apiKey = apiKey;
}

@Override
public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
context.httpRequest().header("api-key", this.apiKey);
return next.process();
}
}
Loading

0 comments on commit 3b68aa9

Please sign in to comment.