Skip to content

Commit

Permalink
A bunch of refactoring (Azure#110)
Browse files Browse the repository at this point in the history
* Refactoring code
* Remove duplicate methods
  • Loading branch information
sakintoye authored Sep 27, 2019
1 parent 890ff6d commit 6bd3cad
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,8 @@

public class SearchPagedResponse extends PagedResponseBase<String, SearchResult> {

/**
* Get facets
*
* @return {@link Map}{@code <}{@link String}{@code ,}{@link List}{@code <}{@link FacetResult}{@code >}{@code >}
*/
public Map<String, List<FacetResult>> getFacets() {
return facets;
}

private final Map<String, List<FacetResult>> facets;

/**
* Get count
*
* @return Long
*/
public Long getCount() {
return count;
}

private final Long count;

/**
* Get coverage
*
* @return Double
*/
public Double coverage() {
return coverage;
}

private final Double coverage;

/**
Expand All @@ -67,25 +38,34 @@ public SearchPagedResponse(SimpleResponse<DocumentSearchResult> documentSearchRe
this.coverage = documentSearchResponse.value().coverage();
}

private static String deserializeHeaders(HttpHeaders headers) {
return headers.toMap().entrySet().stream().map((entry) ->
entry.getKey() + "," + entry.getValue()
).collect(Collectors.joining(","));
/**
* Get coverage
*
* @return Double
*/
public Double coverage() {
return coverage;
}

/**
* return facets
* Get facets
* @return {@link Map}{@code <}{@link String}{@code ,}{@link List}{@code <}{@link FacetResult}{@code >}{@code >}
*/
public Map<String, List<FacetResult>> facets() {
return facets;
}

/**
* Return documents counts
* Get documents count
* @return long
*/
public Long count() {
return count;
}

private static String deserializeHeaders(HttpHeaders headers) {
return headers.toMap().entrySet().stream().map((entry) ->
entry.getKey() + "," + entry.getValue()
).collect(Collectors.joining(","));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public RangeFacetResult(FacetResult facetResult) {
}

/**
* Get cont
* Get count
* @return count
*/
public long count() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,22 @@ public class SearchIndexAsyncClientImpl extends SearchIndexBaseClient implements
HttpClient httpClient,
List<HttpPipelinePolicy> policies) {
if (StringUtils.isBlank(searchServiceName)) {
throw new IllegalArgumentException("Invalid searchServiceName");
throw logger.logExceptionAsError(new IllegalArgumentException("Invalid searchServiceName"));
}
if (StringUtils.isBlank(searchDnsSuffix)) {
throw new IllegalArgumentException("Invalid searchDnsSuffix");
throw logger.logExceptionAsError(new IllegalArgumentException("Invalid searchDnsSuffix"));
}
if (StringUtils.isBlank(indexName)) {
throw new IllegalArgumentException("Invalid indexName");
throw logger.logExceptionAsError(new IllegalArgumentException("Invalid indexName"));
}
if (StringUtils.isBlank(apiVersion)) {
throw new IllegalArgumentException("Invalid apiVersion");
throw logger.logExceptionAsError(new IllegalArgumentException("Invalid apiVersion"));
}
if (httpClient == null) {
throw new IllegalArgumentException("Invalid httpClient");
throw logger.logExceptionAsError(new IllegalArgumentException("Invalid httpClient"));
}
if (policies == null) {
throw new IllegalArgumentException("Invalid policies");
throw logger.logExceptionAsError(new IllegalArgumentException("Invalid policies"));
}

this.searchServiceName = searchServiceName;
Expand Down Expand Up @@ -322,9 +322,7 @@ public PagedFlux<AutocompleteItem> autocomplete(
autocompleteParameters);
Mono<PagedResponse<AutocompleteItem>> first = restClient.documents()
.autocompletePostWithRestResponseAsync(autocompleteRequest)
.map(res -> {
return new AutoCompletePagedResponse(res);
});
.map(res -> new AutoCompletePagedResponse(res));
return new PagedFlux<>(() -> first, nextLink -> Mono.empty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ protected void verifyCanSuggestStaticallyTypedDocuments(PagedResponse<SuggestRes
expectedHotelsList.stream().map(h -> h.description()).collect(Collectors.toList()));
}

protected void verifyCanSuggestWithDateTimeInStaticModel(PagedResponse<SuggestResult> suggestResultPagedResponse) {
List<SuggestResult> books = suggestResultPagedResponse.value();
List<Document> docs = suggestResultPagedResponse.value().stream().map(h -> h.additionalProperties()).collect(Collectors.toList());

Assert.assertEquals(1, docs.size());
Assert.assertEquals("War and Peace", books.get(0).text());
}

protected void verifyFuzzyIsOffByDefault(PagedResponse<SuggestResult> suggestResultPagedResponse) {

Assert.assertNotNull(suggestResultPagedResponse);
Expand Down Expand Up @@ -155,5 +147,6 @@ protected void verifyTopDocumentSuggest(PagedResponse<SuggestResult> suggestResu
@Test
public abstract void testCanFilter();

@Test
public abstract void testOrderByProgressivelyBreaksTies();
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,4 @@ private void addDocsData() throws IOException {


}

public void addSingleDocData(Map document) throws IOException {

if (searchIndexAsyncClient == null) {
searchIndexAsyncClient = new SearchIndexClientBuilder()
.serviceName(searchServiceName)
.searchDnsSuffix(dnsSuffix)
.indexName(indexName)
.apiVersion(apiVersion)
.credential(apiAdminKey)
.buildAsyncClient();
}

System.out.println("Indexing 1 doc");
System.out.println("Indexing Results:");
searchIndexAsyncClient.uploadDocument(document)
.doOnSuccess(documentIndexResult ->
documentIndexResult
.results().forEach(
result ->
System.out.println("key:" + result.key() + (result.succeeded() ? " Succeeded" : " Error: " + result.errorMessage()))))
.doOnError(e -> System.out.println(e.getMessage()))
.block();
}
}

0 comments on commit 6bd3cad

Please sign in to comment.