Skip to content

Commit

Permalink
Add missed fields to PhraseSuggestOption: collapseMatch
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta committed Apr 12, 2024
1 parent a0a4f75 commit cb01a9a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
## [Unreleased 2.x]

### Added
- Add missed fields to PhraseSuggestOption: collapseMatch ([#960](https://github.com/opensearch-project/opensearch-java/pull/960))

### Dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ public class PhraseSuggestOption implements JsonpSerializable {

private final double score;

@Nullable
private final Boolean collateMatch;

// ---------------------------------------------------------------------------------------------

private PhraseSuggestOption(Builder builder) {

this.text = ApiTypeHelper.requireNonNull(builder.text, this, "text");
this.highlighted = builder.highlighted;
this.score = ApiTypeHelper.requireNonNull(builder.score, this, "score");
this.collateMatch = builder.collateMatch;

}

Expand Down Expand Up @@ -92,6 +96,13 @@ public final double score() {
return this.score;
}

/**
* API name: {@code collate_match}
*/
public final Boolean collateMatch() {
return this.collateMatch;
}

/**
* Serialize this object to JSON.
*/
Expand All @@ -114,6 +125,10 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.writeKey("score");
generator.write(this.score);

if (this.collateMatch != null) {
generator.writeKey("collate_match");
generator.write(this.collateMatch);
}
}

// ---------------------------------------------------------------------------------------------
Expand All @@ -130,6 +145,9 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<P

private Double score;

@Nullable
private Boolean collateMatch;

/**
* Required - API name: {@code text}
*/
Expand All @@ -154,6 +172,14 @@ public final Builder score(double value) {
return this;
}

/**
* API name: {@code collate_match}
*/
public final Builder collateMatch(@Nullable Boolean value) {
this.collateMatch = value;
return this;
}

/**
* Builds a {@link PhraseSuggestOption}.
*
Expand Down Expand Up @@ -182,6 +208,7 @@ protected static void setupPhraseSuggestOptionDeserializer(ObjectDeserializer<Ph
op.add(Builder::text, JsonpDeserializer.stringDeserializer(), "text");
op.add(Builder::highlighted, JsonpDeserializer.stringDeserializer(), "highlighted");
op.add(Builder::score, JsonpDeserializer.doubleDeserializer(), "score");
op.add(Builder::collateMatch, JsonpDeserializer.booleanDeserializer(), "collate_match");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.opensearch.Version;
import org.opensearch.client.json.JsonData;
import org.opensearch.client.opensearch.OpenSearchAsyncClient;
import org.opensearch.client.opensearch._types.FieldValue;
import org.opensearch.client.opensearch._types.OpenSearchException;
Expand Down Expand Up @@ -772,7 +773,14 @@ public void testPhraseSuggester() throws IOException {

String suggesterName = "msgSuggester";

PhraseSuggester phraseSuggester = FieldSuggesterBuilders.phrase().field("msg.trigram").build();
PhraseSuggester phraseSuggester = FieldSuggesterBuilders.phrase()
.field("msg.trigram")
.collate(
c -> c.query(q -> q.source("{\"match\": {\"{{field_name}}\" : \"{{suggestion}}\"}}"))
.prune(true)
.params(Map.of("field_name", JsonData.of("msg")))
)
.build();
FieldSuggester fieldSuggester = new FieldSuggester.Builder().text("design paterns").phrase(phraseSuggester).build();
Suggester suggester = new Suggester.Builder().suggesters(Collections.singletonMap(suggesterName, fieldSuggester)).build();
SearchRequest searchRequest = new SearchRequest.Builder().index(index).suggest(suggester).build();
Expand All @@ -785,19 +793,9 @@ public void testPhraseSuggester() throws IOException {
assertTrue(response.suggest().get(suggesterName).get(0).isPhrase());
assertNotNull(response.suggest().get(suggesterName).get(0).phrase().options());
assertEquals(response.suggest().get(suggesterName).get(0).phrase().options().get(0).text(), "design patterns");
assertEquals(response.suggest().get(suggesterName).get(0).phrase().options().get(0).collateMatch(), true);
}

// @Test
// public void testValueBodyResponse() throws Exception {
// DiskUsageResponse resp = highLevelClient().indices().diskUsage(b -> b
// .index("*")
// .allowNoIndices(true)
// .runExpensiveTasks(true)
// );
//
// assertNotNull(resp.valueBody().toJson().asJsonObject().get("_shards"));
// }

public static class AppData {

private int intValue;
Expand Down

0 comments on commit cb01a9a

Please sign in to comment.