Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for icu collation options
Browse files Browse the repository at this point in the history
Signed-off-by: bfindlay <bfindlay@acm.org>
Bfindlay committed Nov 15, 2023
1 parent e1ab8a2 commit 71c0013
Showing 2 changed files with 248 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -12,6 +12,10 @@
import java.util.function.Function;
import javax.annotation.Nullable;
import org.opensearch.client.json.*;
import org.opensearch.client.opensearch._types.analysis.IcuCollationAlternate;
import org.opensearch.client.opensearch._types.analysis.IcuCollationCaseFirst;
import org.opensearch.client.opensearch._types.analysis.IcuCollationDecomposition;
import org.opensearch.client.opensearch._types.analysis.IcuCollationStrength;
import org.opensearch.client.util.ObjectBuilder;

// typedef: _types.mapping.ICUCollationKeywordProperty
@@ -25,13 +29,46 @@ public class IcuCollationKeywordProperty extends DocValuesPropertyBase implement
@Nullable
private final String nullValue;

// Collation Options

@Nullable
private final IcuCollationAlternate alternate;

@Nullable
private final Boolean caseLevel;

@Nullable
private final IcuCollationCaseFirst caseFirst;

@Nullable
private final IcuCollationDecomposition decomposition;

@Nullable
private final Boolean hiraganaQuaternaryMode;

@Nullable
private final Boolean numeric;

@Nullable
private final IcuCollationStrength strength;

@Nullable
private final String variableTop;

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

private IcuCollationKeywordProperty(Builder builder) {
super(builder);

this.index = builder.index;
this.nullValue = builder.nullValue;
this.alternate = builder.alternate;
this.caseLevel = builder.caseLevel;
this.caseFirst = builder.caseFirst;
this.decomposition = builder.decomposition;
this.hiraganaQuaternaryMode = builder.hiraganaQuaternaryMode;
this.numeric = builder.numeric;
this.strength = builder.strength;
this.variableTop = builder.variableTop;
}

public static IcuCollationKeywordProperty of(Function<Builder, ObjectBuilder<IcuCollationKeywordProperty>> fn) {
@@ -59,6 +96,62 @@ public final String nullValue() {
return this.nullValue;
}

/**
* API name: {@code alternate}
*/
public final IcuCollationAlternate alternate() {
return this.alternate;
}

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

/**
* API name: {@code case_first}
*/
public final IcuCollationCaseFirst caseFirst() {
return this.caseFirst;
}

/**
* API name: {@code decomposition}
*/
public final IcuCollationDecomposition decomposition() {
return this.decomposition;
}

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

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

/**
* API name: {@code strength}
*/
public final IcuCollationStrength strength() {
return this.strength;
}

/**
* API name: {@code variable_top}
*/
public final String variableTop() {
return this.variableTop;
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.write("type", "icu_collation_keyword");
super.serializeInternal(generator, mapper);
@@ -70,6 +163,38 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.writeKey("null_value");
generator.write(this.nullValue);
}
if (this.alternate != null) {
generator.writeKey("alternate");
generator.write(this.alternate.jsonValue());
}
if (this.caseLevel != null) {
generator.writeKey("case_level");
generator.write(this.caseLevel);
}
if (this.caseFirst != null) {
generator.writeKey("case_first");
generator.write(this.caseFirst.jsonValue());
}
if (this.decomposition != null) {
generator.writeKey("decomposition");
generator.write(this.decomposition.jsonValue());
}
if (this.hiraganaQuaternaryMode != null) {
generator.writeKey("hiragana_quaternary_mode");
generator.write(this.hiraganaQuaternaryMode);
}
if (this.numeric != null) {
generator.writeKey("numeric");
generator.write(this.numeric);
}
if (this.strength != null) {
generator.writeKey("strength");
generator.write(this.strength.jsonValue());
}
if (this.variableTop != null) {
generator.writeKey("variable_top");
generator.write(this.variableTop);
}
}

// ---------------------------------------------------------------------------------------------
@@ -87,6 +212,30 @@ public static class Builder extends DocValuesPropertyBase.AbstractBuilder<Builde
@Nullable
private String nullValue;

@Nullable
private IcuCollationAlternate alternate;

@Nullable
private Boolean caseLevel;

@Nullable
private IcuCollationCaseFirst caseFirst;

@Nullable
private IcuCollationDecomposition decomposition;

@Nullable
private Boolean hiraganaQuaternaryMode;

@Nullable
private Boolean numeric;

@Nullable
private IcuCollationStrength strength;

@Nullable
private String variableTop;

/**
* API name: {@code index}
*/
@@ -103,6 +252,70 @@ public final Builder nullValue(@Nullable String value) {
return this;
}

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

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

/**
* API name: {@code case_first}
*/
public final Builder caseFirst(@Nullable IcuCollationCaseFirst value) {
this.caseFirst = value;
return this;
}

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

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

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

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

/**
* API name: {@code variable_top}
*/
public final Builder variableTop(@Nullable String value) {
this.variableTop = value;
return this;
}

@Override
protected Builder self() {
return this;
@@ -134,5 +347,13 @@ protected static void setupIcuCollationKeywordPropertyDeserializer(ObjectDeseria
DocValuesPropertyBase.setupDocValuesPropertyBaseDeserializer(op);
op.add(Builder::index, JsonpDeserializer.booleanDeserializer(), "index");
op.add(Builder::nullValue, JsonpDeserializer.stringDeserializer(), "null_value");
op.add(Builder::alternate, IcuCollationAlternate._DESERIALIZER, "alternate");
op.add(Builder::caseLevel, JsonpDeserializer.booleanDeserializer(), "case_level");
op.add(Builder::caseFirst, IcuCollationCaseFirst._DESERIALIZER, "case_first");
op.add(Builder::decomposition, IcuCollationDecomposition._DESERIALIZER, "decomposition");
op.add(Builder::hiraganaQuaternaryMode, JsonpDeserializer.booleanDeserializer(), "hiragana_quaternary_mode");
op.add(Builder::numeric, JsonpDeserializer.booleanDeserializer(), "numeric");
op.add(Builder::strength, IcuCollationStrength._DESERIALIZER, "strength");
op.add(Builder::variableTop, JsonpDeserializer.stringDeserializer(), "variable_top");
}
}
Original file line number Diff line number Diff line change
@@ -19,6 +19,23 @@ public class GetMappingsResponseTest extends Assert {
@Test
public void deserialize_IcuCollationKeywordExists_propertyDeserializes() throws JsonProcessingException {
Map<String, Object> mappingTemplate = new HashMap<>();
Map<String, Object> icuCollationConfig = new HashMap<>();
icuCollationConfig.put("type", "icu_collation_keyword");
icuCollationConfig.put("ignore_above", 1);
icuCollationConfig.put("index", true);
icuCollationConfig.put("null_value", "not-null-value");
icuCollationConfig.put("store", true);

// Collations
icuCollationConfig.put("alternate", "shifted");
icuCollationConfig.put("case_level", true);
icuCollationConfig.put("case_first", "lower");
icuCollationConfig.put("decomposition", "no");
icuCollationConfig.put("hiragana_quaternary_mode", true);
icuCollationConfig.put("numeric", true);
icuCollationConfig.put("strength", "quaternary");
icuCollationConfig.put("variable_top", "$");

mappingTemplate.put(
"test-index",
Map.of(
@@ -27,24 +44,7 @@ public void deserialize_IcuCollationKeywordExists_propertyDeserializes() throws
"index_patterns",
Collections.singletonList("test-pattern*"),
"mappings",
Map.of(
"properties",
Map.of(
"icu_test_field",
Map.of(
"type",
"icu_collation_keyword",
"ignore_above",
1,
"index",
true,
"null_value",
"not-null-value",
"store",
true
)
)
),
Map.of("properties", Map.of("icu_test_field", icuCollationConfig)),
"order",
0,
"settings",
@@ -70,5 +70,13 @@ public void deserialize_IcuCollationKeywordExists_propertyDeserializes() throws
assertTrue(icu.index());
assertTrue(icu.store());
assertEquals((int) icu.ignoreAbove(), 1);
assertEquals(icu.alternate().jsonValue(), "shifted");
assertTrue(icu.caseLevel());
assertEquals(icu.caseFirst().jsonValue(), "lower");
assertEquals(icu.decomposition().jsonValue(), "no");
assertTrue(icu.hiraganaQuaternaryMode());
assertTrue(icu.numeric());
assertEquals(icu.strength().jsonValue(), "quaternary");
assertEquals(icu.variableTop(), "$");
}
}

0 comments on commit 71c0013

Please sign in to comment.