Skip to content

Commit 3368233

Browse files
authored
[Backport 2.x] Generate Tokenizers (#1454)
* Add support for SimplePattern tokenizers (#1448) Signed-off-by: Thomas Farr <[email protected]> (cherry picked from commit 73ba6bf) * Fix mistake in Simple Pattern Tokenizer specification/generation (#1451) Signed-off-by: Thomas Farr <[email protected]> (cherry picked from commit 37e24dc) * Generate remaining tokenizers Signed-off-by: Thomas Farr <[email protected]> --------- Signed-off-by: Thomas Farr <[email protected]>
1 parent 28ce365 commit 3368233

29 files changed

+2055
-507
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66
- Added `toBuilder()` and `Builder.copy()` methods to all generated classes ([#1300](https://github.com/opensearch-project/opensearch-java/pull/1300))
77
- Added support for additional ML APIs ([#1443](https://github.com/opensearch-project/opensearch-java/pull/1443))
88
- Added support for the Search Pipeline APIs ([#1442](https://github.com/opensearch-project/opensearch-java/pull/1442))
9+
- Added support for `simple_pattern` and `simple_pattern_split` tokenizers ([#1448](https://github.com/opensearch-project/opensearch-java/pull/1448), [#1451](https://github.com/opensearch-project/opensearch-java/pull/1451))
910

1011
### Dependencies
1112

java-client/src/main/java/org/opensearch/client/opensearch/_types/analysis/CharGroupTokenizer.java java-client/src/generated/java/org/opensearch/client/opensearch/_types/analysis/CharGroupTokenizer.java

+111-47
Original file line numberDiff line numberDiff line change
@@ -30,58 +30,64 @@
3030
* GitHub history for details.
3131
*/
3232

33+
//----------------------------------------------------
34+
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
35+
//----------------------------------------------------
36+
3337
package org.opensearch.client.opensearch._types.analysis;
3438

3539
import jakarta.json.stream.JsonGenerator;
3640
import java.util.List;
41+
import java.util.Objects;
3742
import java.util.function.Function;
43+
import javax.annotation.Generated;
44+
import javax.annotation.Nonnull;
3845
import javax.annotation.Nullable;
3946
import org.opensearch.client.json.JsonpDeserializable;
4047
import org.opensearch.client.json.JsonpDeserializer;
4148
import org.opensearch.client.json.JsonpMapper;
4249
import org.opensearch.client.json.ObjectBuilderDeserializer;
4350
import org.opensearch.client.json.ObjectDeserializer;
4451
import org.opensearch.client.util.ApiTypeHelper;
52+
import org.opensearch.client.util.CopyableBuilder;
4553
import org.opensearch.client.util.ObjectBuilder;
54+
import org.opensearch.client.util.ToCopyableBuilder;
4655

4756
// typedef: _types.analysis.CharGroupTokenizer
4857

4958
@JsonpDeserializable
50-
public class CharGroupTokenizer extends TokenizerBase implements TokenizerDefinitionVariant {
51-
private final List<String> tokenizeOnChars;
59+
@Generated("org.opensearch.client.codegen.CodeGenerator")
60+
public class CharGroupTokenizer extends TokenizerBase
61+
implements
62+
TokenizerDefinitionVariant,
63+
ToCopyableBuilder<CharGroupTokenizer.Builder, CharGroupTokenizer> {
5264

5365
@Nullable
5466
private final Integer maxTokenLength;
5567

68+
@Nonnull
69+
private final List<String> tokenizeOnChars;
70+
5671
// ---------------------------------------------------------------------------------------------
5772

5873
private CharGroupTokenizer(Builder builder) {
5974
super(builder);
60-
61-
this.tokenizeOnChars = ApiTypeHelper.unmodifiableRequired(builder.tokenizeOnChars, this, "tokenizeOnChars");
6275
this.maxTokenLength = builder.maxTokenLength;
63-
76+
this.tokenizeOnChars = ApiTypeHelper.unmodifiableRequired(builder.tokenizeOnChars, this, "tokenizeOnChars");
6477
}
6578

66-
public static CharGroupTokenizer of(Function<Builder, ObjectBuilder<CharGroupTokenizer>> fn) {
79+
public static CharGroupTokenizer of(Function<CharGroupTokenizer.Builder, ObjectBuilder<CharGroupTokenizer>> fn) {
6780
return fn.apply(new Builder()).build();
6881
}
6982

7083
/**
71-
* TokenizerDefinition variant kind.
84+
* {@link TokenizerDefinition} variant kind.
7285
*/
7386
@Override
7487
public TokenizerDefinition.Kind _tokenizerDefinitionKind() {
7588
return TokenizerDefinition.Kind.CharGroup;
7689
}
7790

78-
/**
79-
* Required - API name: {@code tokenize_on_chars}
80-
*/
81-
public final List<String> tokenizeOnChars() {
82-
return this.tokenizeOnChars;
83-
}
84-
8591
/**
8692
* API name: {@code max_token_length}
8793
*/
@@ -90,79 +96,119 @@ public final Integer maxTokenLength() {
9096
return this.maxTokenLength;
9197
}
9298

93-
protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
99+
/**
100+
* Required - API name: {@code tokenize_on_chars}
101+
*/
102+
@Nonnull
103+
public final List<String> tokenizeOnChars() {
104+
return this.tokenizeOnChars;
105+
}
94106

107+
protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
95108
generator.write("type", "char_group");
96109
super.serializeInternal(generator, mapper);
97-
if (ApiTypeHelper.isDefined(this.tokenizeOnChars)) {
98-
generator.writeKey("tokenize_on_chars");
99-
generator.writeStartArray();
100-
for (String item0 : this.tokenizeOnChars) {
101-
generator.write(item0);
102-
103-
}
104-
generator.writeEnd();
105-
106-
}
107110
if (this.maxTokenLength != null) {
108111
generator.writeKey("max_token_length");
109112
generator.write(this.maxTokenLength);
110-
111113
}
112114

115+
generator.writeKey("tokenize_on_chars");
116+
generator.writeStartArray();
117+
for (String item0 : this.tokenizeOnChars) {
118+
generator.write(item0);
119+
}
120+
generator.writeEnd();
113121
}
114122

115123
// ---------------------------------------------------------------------------------------------
116124

125+
@Override
126+
@Nonnull
127+
public Builder toBuilder() {
128+
return new Builder(this);
129+
}
130+
131+
@Nonnull
132+
public static Builder builder() {
133+
return new Builder();
134+
}
135+
117136
/**
118137
* Builder for {@link CharGroupTokenizer}.
119138
*/
120-
121-
public static class Builder extends TokenizerBase.AbstractBuilder<Builder> implements ObjectBuilder<CharGroupTokenizer> {
122-
private List<String> tokenizeOnChars;
123-
139+
public static class Builder extends TokenizerBase.AbstractBuilder<Builder> implements CopyableBuilder<Builder, CharGroupTokenizer> {
124140
@Nullable
125141
private Integer maxTokenLength;
142+
private List<String> tokenizeOnChars;
143+
144+
public Builder() {}
145+
146+
private Builder(CharGroupTokenizer o) {
147+
super(o);
148+
this.maxTokenLength = o.maxTokenLength;
149+
this.tokenizeOnChars = _listCopy(o.tokenizeOnChars);
150+
}
151+
152+
private Builder(Builder o) {
153+
super(o);
154+
this.maxTokenLength = o.maxTokenLength;
155+
this.tokenizeOnChars = _listCopy(o.tokenizeOnChars);
156+
}
157+
158+
@Override
159+
@Nonnull
160+
public Builder copy() {
161+
return new Builder(this);
162+
}
163+
164+
@Override
165+
@Nonnull
166+
protected Builder self() {
167+
return this;
168+
}
169+
170+
/**
171+
* API name: {@code max_token_length}
172+
*/
173+
@Nonnull
174+
public final Builder maxTokenLength(@Nullable Integer value) {
175+
this.maxTokenLength = value;
176+
return this;
177+
}
126178

127179
/**
128180
* Required - API name: {@code tokenize_on_chars}
181+
*
129182
* <p>
130183
* Adds all elements of <code>list</code> to <code>tokenizeOnChars</code>.
184+
* </p>
131185
*/
186+
@Nonnull
132187
public final Builder tokenizeOnChars(List<String> list) {
133188
this.tokenizeOnChars = _listAddAll(this.tokenizeOnChars, list);
134189
return this;
135190
}
136191

137192
/**
138193
* Required - API name: {@code tokenize_on_chars}
194+
*
139195
* <p>
140196
* Adds one or more values to <code>tokenizeOnChars</code>.
197+
* </p>
141198
*/
199+
@Nonnull
142200
public final Builder tokenizeOnChars(String value, String... values) {
143201
this.tokenizeOnChars = _listAdd(this.tokenizeOnChars, value, values);
144202
return this;
145203
}
146204

147-
/**
148-
* API name: {@code max_token_length}
149-
*/
150-
public final Builder maxTokenLength(@Nullable Integer value) {
151-
this.maxTokenLength = value;
152-
return this;
153-
}
154-
155-
@Override
156-
protected Builder self() {
157-
return this;
158-
}
159-
160205
/**
161206
* Builds a {@link CharGroupTokenizer}.
162207
*
163-
* @throws NullPointerException
164-
* if some of the required fields are null.
208+
* @throws NullPointerException if some of the required fields are null.
165209
*/
210+
@Override
211+
@Nonnull
166212
public CharGroupTokenizer build() {
167213
_checkSingleUse();
168214

@@ -181,11 +227,29 @@ public CharGroupTokenizer build() {
181227
);
182228

183229
protected static void setupCharGroupTokenizerDeserializer(ObjectDeserializer<CharGroupTokenizer.Builder> op) {
184-
TokenizerBase.setupTokenizerBaseDeserializer(op);
185-
op.add(Builder::tokenizeOnChars, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "tokenize_on_chars");
230+
setupTokenizerBaseDeserializer(op);
186231
op.add(Builder::maxTokenLength, JsonpDeserializer.integerDeserializer(), "max_token_length");
232+
op.add(Builder::tokenizeOnChars, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "tokenize_on_chars");
187233

188234
op.ignore("type");
189235
}
190236

237+
@Override
238+
public int hashCode() {
239+
int result = super.hashCode();
240+
result = 31 * result + Objects.hashCode(this.maxTokenLength);
241+
result = 31 * result + this.tokenizeOnChars.hashCode();
242+
return result;
243+
}
244+
245+
@Override
246+
public boolean equals(Object o) {
247+
if (!super.equals(o)) {
248+
return false;
249+
}
250+
if (this == o) return true;
251+
if (o == null || this.getClass() != o.getClass()) return false;
252+
CharGroupTokenizer other = (CharGroupTokenizer) o;
253+
return Objects.equals(this.maxTokenLength, other.maxTokenLength) && this.tokenizeOnChars.equals(other.tokenizeOnChars);
254+
}
191255
}

0 commit comments

Comments
 (0)