Skip to content

Commit

Permalink
Added "smartcn" analyzer. (#605)
Browse files Browse the repository at this point in the history
* Added "smartcn" analyzer.

Signed-off-by: pieper <[email protected]>

* Adapted changelog.

Signed-off-by: pieper <[email protected]>

* Fixed license headers.

Signed-off-by: pieper <[email protected]>

* Fixed release number.

Signed-off-by: pieper <[email protected]>

---------

Signed-off-by: pieper <[email protected]>
  • Loading branch information
MikePieperSer authored Aug 21, 2023
1 parent 64dd87f commit 1e68c31
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased 2.x]

### Added
- Added support for "smartcn" analyzer ([#605](https://github.com/opensearch-project/opensearch-java/pull/605))

### Dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public enum Kind implements JsonEnum {

Whitespace("whitespace"),

Smartcn("smartcn"),

;

private final String jsonValue;
Expand Down Expand Up @@ -373,7 +375,25 @@ public WhitespaceAnalyzer whitespace() {
return TaggedUnionUtils.get(this, Kind.Whitespace);
}

@Override
/**
* Is this variant instance of kind {@code cjk}?
*/
public boolean isSmartcn() {
return _kind == Kind.Smartcn;
}

/**
* Get the {@code cjk} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code cjk} kind.
*/
public SmartcnAnalyzer smartcn() {
return TaggedUnionUtils.get(this, Kind.Smartcn);
}


@Override
public void serialize(JsonGenerator generator, JsonpMapper mapper) {

mapper.serialize(_value, generator);
Expand Down Expand Up @@ -530,6 +550,16 @@ public ObjectBuilder<Analyzer> whitespace(
return this.whitespace(fn.apply(new WhitespaceAnalyzer.Builder()).build());
}

public ObjectBuilder<Analyzer> smartcn(SmartcnAnalyzer v) {
this._kind = Kind.Smartcn;
this._value = v;
return this;
}

public ObjectBuilder<Analyzer> smartcn() {
return this.smartcn(new SmartcnAnalyzer.Builder().build());
}

public Analyzer build() {
_checkSingleUse();
return new Analyzer(this);
Expand All @@ -553,6 +583,7 @@ protected static void setupAnalyzerDeserializer(ObjectDeserializer<Builder> op)
op.add(Builder::standard, StandardAnalyzer._DESERIALIZER, "standard");
op.add(Builder::stop, StopAnalyzer._DESERIALIZER, "stop");
op.add(Builder::whitespace, WhitespaceAnalyzer._DESERIALIZER, "whitespace");
op.add(Builder::smartcn, SmartcnAnalyzer._DESERIALIZER, Kind.Smartcn.jsonValue());

op.setTypeProperty("type", null);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.client.opensearch._types.analysis;

import java.util.function.Function;

import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.JsonpSerializable;
import org.opensearch.client.json.ObjectBuilderDeserializer;
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;

import jakarta.json.stream.JsonGenerator;

// typedef: _types.analysis.LanguageAnalyzer

@JsonpDeserializable
public class SmartcnAnalyzer implements AnalyzerVariant, JsonpSerializable {

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

private SmartcnAnalyzer(Builder builder) {

}

public static SmartcnAnalyzer of(Function<Builder, ObjectBuilder<SmartcnAnalyzer>> fn) {
return fn.apply(new Builder()).build();
}

/**
* Analyzer variant kind.
*/
@Override
public Analyzer.Kind _analyzerKind() {
return Analyzer.Kind.Smartcn;
}

/**
* Serialize this object to JSON.
*/
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartObject();
serializeInternal(generator, mapper);
generator.writeEnd();
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

generator.write("type", Analyzer.Kind.Smartcn.jsonValue());

}

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

/**
* Builder for {@link SmartcnAnalyzer}.
*/

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<SmartcnAnalyzer> {

/**
* Builds a {@link SmartcnAnalyzer}.
*
* @throws NullPointerException
* if some required fields are null.
*/
public SmartcnAnalyzer build() {
_checkSingleUse();

return new SmartcnAnalyzer(this);
}
}

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

/**
* Json deserializer for {@link SmartcnAnalyzer}
*/
public static final JsonpDeserializer<SmartcnAnalyzer> _DESERIALIZER = ObjectBuilderDeserializer.lazy(Builder::new,
SmartcnAnalyzer::setupLanguageAnalyzerDeserializer);

protected static void setupLanguageAnalyzerDeserializer(ObjectDeserializer<SmartcnAnalyzer.Builder> op) {

op.ignore("type");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.client.opensearch._types.analysis;

import java.util.function.Function;

import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.ObjectBuilderDeserializer;
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.util.ObjectBuilder;

import jakarta.json.stream.JsonGenerator;

// typedef: _types.analysis.ReverseTokenFilter

@JsonpDeserializable
public class SmartcnStopTokenFilter extends TokenFilterBase implements TokenFilterDefinitionVariant {
// ---------------------------------------------------------------------------------------------

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

}

public static SmartcnStopTokenFilter of(Function<Builder, ObjectBuilder<SmartcnStopTokenFilter>> fn) {
return fn.apply(new Builder()).build();
}

/**
* TokenFilterDefinition variant kind.
*/
@Override
public TokenFilterDefinition.Kind _tokenFilterDefinitionKind() {
return TokenFilterDefinition.Kind.SmartcnStop;
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

generator.write("type", TokenFilterDefinition.Kind.SmartcnStop.jsonValue());
super.serializeInternal(generator, mapper);

}

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

/**
* Builder for {@link SmartcnStopTokenFilter}.
*/

public static class Builder extends AbstractBuilder<Builder>
implements
ObjectBuilder<SmartcnStopTokenFilter> {
@Override
protected Builder self() {
return this;
}

/**
* Builds a {@link SmartcnStopTokenFilter}.
*
* @throws NullPointerException
* if some required fields are null.
*/
public SmartcnStopTokenFilter build() {
_checkSingleUse();

return new SmartcnStopTokenFilter(this);
}
}

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

/**
* Json deserializer for {@link SmartcnStopTokenFilter}
*/
public static final JsonpDeserializer<SmartcnStopTokenFilter> _DESERIALIZER = ObjectBuilderDeserializer
.lazy(Builder::new, SmartcnStopTokenFilter::setupSmartcnStopTokenFilterDeserializer);

protected static void setupSmartcnStopTokenFilterDeserializer(ObjectDeserializer<SmartcnStopTokenFilter.Builder> op) {
setupTokenFilterBaseDeserializer(op);

op.ignore("type");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.client.opensearch._types.analysis;

import java.util.function.Function;

import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.ObjectBuilderDeserializer;
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.util.ObjectBuilder;

import jakarta.json.stream.JsonGenerator;

// typedef: _types.analysis.IcuTokenizer

@JsonpDeserializable
public class SmartcnTokenizer extends TokenizerBase implements TokenizerDefinitionVariant {
// ---------------------------------------------------------------------------------------------

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

}

public static SmartcnTokenizer of(Function<Builder, ObjectBuilder<SmartcnTokenizer>> fn) {
return fn.apply(new Builder()).build();
}

/**
* TokenizerDefinition variant kind.
*/
@Override
public TokenizerDefinition.Kind _tokenizerDefinitionKind() {
return TokenizerDefinition.Kind.SmartcnTokenizer;
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

generator.write("type", TokenizerDefinition.Kind.SmartcnTokenizer.jsonValue());
super.serializeInternal(generator, mapper);

}

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

/**
* Builder for {@link SmartcnTokenizer}.
*/

public static class Builder extends AbstractBuilder<Builder> implements ObjectBuilder<SmartcnTokenizer> {

@Override
protected Builder self() {
return this;
}

/**
* Builds a {@link SmartcnTokenizer}.
*
* @throws NullPointerException
* if some required fields are null.
*/
public SmartcnTokenizer build() {
_checkSingleUse();

return new SmartcnTokenizer(this);
}
}

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

/**
* Json deserializer for {@link SmartcnTokenizer}
*/
public static final JsonpDeserializer<SmartcnTokenizer> _DESERIALIZER = ObjectBuilderDeserializer.lazy(Builder::new,
SmartcnTokenizer::setupSmartcnTokenizerDeserializer);

protected static void setupSmartcnTokenizerDeserializer(ObjectDeserializer<SmartcnTokenizer.Builder> op) {
TokenizerBase.setupTokenizerBaseDeserializer(op);

op.ignore("type");
}

}
Loading

0 comments on commit 1e68c31

Please sign in to comment.