Skip to content

Commit

Permalink
Searching fully typed documents (Azure#51)
Browse files Browse the repository at this point in the history
* make SearchResult use Document class instead of map for property bag

* Search with fully typed documents
  • Loading branch information
navalev authored Sep 8, 2019
1 parent 5cd100d commit 9a88e77
Show file tree
Hide file tree
Showing 15 changed files with 1,006 additions and 2,612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,31 @@ public Mono<Long> countDocuments() {

@Override
public PagedFlux<SearchResult> search() {
SearchRequest searchRequest = new SearchRequest();
Mono<PagedResponse<SearchResult>> first = restClient.documents()
.searchPostWithRestResponseAsync(new SearchRequest())
.searchPostWithRestResponseAsync(searchRequest)
.map(res -> {
if (res.value().nextPageParameters() != null) {
skip = res.value().nextPageParameters().skip();
}
return new SearchPagedResponse(res);
});
return new PagedFlux<>(() -> first, this::searchPostNextWithRestResponseAsync);
return new PagedFlux<>(() -> first, nextLink -> searchPostNextWithRestResponseAsync(searchRequest, (String) nextLink));

}

@Override
public PagedFlux<SearchResult> search(String searchText, SearchParameters searchParameters, SearchRequestOptions searchRequestOptions) {
SearchRequest searchRequest = createSearchRequest(searchText, searchParameters);
Mono<PagedResponse<SearchResult>> first = restClient.documents()
.searchPostWithRestResponseAsync(createSearchRequest(searchText, searchParameters), searchRequestOptions)
.searchPostWithRestResponseAsync(searchRequest, searchRequestOptions)
.map(res -> {
if (res.value().nextPageParameters() != null) {
skip = res.value().nextPageParameters().skip();
}
return new SearchPagedResponse(res);
});
return new PagedFlux(() -> first, nextLink -> searchPostNextWithRestResponseAsync((String) nextLink));
return new PagedFlux(() -> first, nextLink -> searchPostNextWithRestResponseAsync(searchRequest, (String) nextLink));
}

@Override
Expand Down Expand Up @@ -243,15 +245,15 @@ public Mono<AutocompleteResult> autocomplete(
* @return {@link Mono}{@code <}{@link PagedResponse}{@code <}{@link SearchResult}{@code >}{@code >} next page
* response with results
*/
private Mono<PagedResponse<SearchResult>> searchPostNextWithRestResponseAsync(String nextLink) {
private Mono<PagedResponse<SearchResult>> searchPostNextWithRestResponseAsync(SearchRequest searchRequest, String nextLink) {
if (nextLink == null || nextLink.isEmpty()) {
return Mono.empty();
}
if (skip == null) {
return Mono.empty();
}
return restClient.documents()
.searchPostWithRestResponseAsync(new SearchRequest().skip(skip))
.searchPostWithRestResponseAsync(searchRequest.skip(skip))
.map(res -> {
if (res.value().nextPageParameters() == null || res.value().nextPageParameters().skip() == null) {
skip = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.azure.search.data.generated.models;

import com.azure.core.implementation.annotation.Fluent;
import com.azure.search.data.customization.Document;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Map;
Expand All @@ -18,7 +19,7 @@ public final class SearchResult {
* Unmatched properties from the message are deserialized this collection
*/
@JsonProperty(value = "")
private Map<String, Object> additionalProperties;
private Document additionalProperties;

/*
* The relevance score of the document compared to other documents returned
Expand All @@ -41,7 +42,7 @@ public final class SearchResult {
*
* @return the additionalProperties value.
*/
public Map<String, Object> additionalProperties() {
public Document additionalProperties() {
return this.additionalProperties;
}

Expand All @@ -52,7 +53,7 @@ public Map<String, Object> additionalProperties() {
* @param additionalProperties the additionalProperties value to set.
* @return the SearchResult object itself.
*/
public SearchResult additionalProperties(Map<String, Object> additionalProperties) {
public SearchResult additionalProperties(Document additionalProperties) {
this.additionalProperties = additionalProperties;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.azure.search.data.models;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

public class Bucket {

@JsonProperty(value = "BucketName")
public String bucketName;

@JsonProperty(value = "Count")
public int count;

public Bucket bucketName(String bucketName) {
this.bucketName = bucketName;
return this;
}

public Bucket count(int count) {
this.count = count;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Bucket)) return false;
Bucket bucket = (Bucket) o;
return count == bucket.count &&
Objects.equals(bucketName, bucket.bucketName);
}

@Override
public int hashCode() {
return Objects.hash(bucketName, count);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.azure.search.data.models;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Arrays;
import java.util.Date;
import java.util.Objects;

public class NonNullableModel {

@JsonProperty(value = "Key")
public String key;

@JsonProperty(value = "Rating")
public int rating;

@JsonProperty(value = "Count")
public long count;

@JsonProperty(value = "IsEnabled")
public boolean isEnabled;

@JsonProperty(value = "Ratio")
public double ratio;

@JsonProperty(value = "StartDate")
public Date startDate;

@JsonProperty(value = "EndDate")
public Date endDate;

@JsonProperty(value = "TopLevelBucket")
public Bucket topLevelBucket;

@JsonProperty(value = "Buckets")
public Bucket[] buckets;

public NonNullableModel key(String key) {
this.key = key;
return this;
}

public NonNullableModel rating(int rating) {
this.rating = rating;
return this;
}

public NonNullableModel count(long count) {
this.count = count;
return this;
}

public NonNullableModel isEnabled(boolean enabled) {
isEnabled = enabled;
return this;
}

public NonNullableModel ratio(double ratio) {
this.ratio = ratio;
return this;
}

public NonNullableModel startDate(Date startDate) {
this.startDate = startDate;
return this;
}

public NonNullableModel endDate(Date endDate) {
this.endDate = endDate;
return this;
}

public NonNullableModel topLevelBucket(Bucket topLevelBucket) {
this.topLevelBucket = topLevelBucket;
return this;
}

public NonNullableModel buckets(Bucket[] buckets) {
this.buckets = buckets;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NonNullableModel)) return false;
NonNullableModel that = (NonNullableModel) o;
return rating == that.rating &&
count == that.count &&
isEnabled == that.isEnabled &&
Double.compare(that.ratio, ratio) == 0 &&
key.equals(that.key) &&
((startDate == null && that.startDate == null) || (startDate.equals(that.startDate))) &&
((endDate == null && that.endDate == null) || (endDate.equals(that.endDate))) &&
((topLevelBucket == null && that.topLevelBucket == null) || (topLevelBucket.equals(that.topLevelBucket))) &&
Arrays.equals(buckets, that.buckets);
}

@Override
public int hashCode() {
int result = Objects.hash(key, rating, count, isEnabled, ratio, startDate, endDate, topLevelBucket);
result = 31 * result + Arrays.hashCode(buckets);
return result;
}
}
Loading

0 comments on commit 9a88e77

Please sign in to comment.