Skip to content

Commit

Permalink
[Backport 2.x] Added "smartcn" and "cjk" analyzers (#607)
Browse files Browse the repository at this point in the history
* Added "smartcn" analyzer. (#605)

* 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]>
Signed-off-by: Vacha Shah <[email protected]>

* Added "cjk" analyzer. (#604)

* Added "cjk" analyzer.

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

* Adapted changelog.

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

* Fixed license headers.

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

* Tab vs. Spaces fix.

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

---------

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

---------

Signed-off-by: pieper <[email protected]>
Signed-off-by: Vacha Shah <[email protected]>
Co-authored-by: MikePieperSer <[email protected]>
  • Loading branch information
VachaShah and MikePieperSer authored Aug 22, 2023
1 parent b4e30f2 commit a1a0b63
Show file tree
Hide file tree
Showing 9 changed files with 636 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# CHANGELOG
Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased 2.x](https://github.com/opensearch-project/opensearch-java/compare/v2.6.0...2.x)
## [Unreleased 2.x]
### Added
- Added support for "smartcn" analyzer ([#605](https://github.com/opensearch-project/opensearch-java/pull/605))
- Added support for "cjk" analyzer ([#604](https://github.com/opensearch-project/opensearch-java/pull/604))

### Dependencies
- Bumps `org.ajoberstar.grgit:grgit-gradle` from 5.0.0 to 5.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public enum Kind implements JsonEnum {

Whitespace("whitespace"),

Smartcn("smartcn"),

Cjk("cjk"),

;

private final String jsonValue;
Expand Down Expand Up @@ -373,7 +377,43 @@ 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);
}


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

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


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

mapper.serialize(_value, generator);
Expand Down Expand Up @@ -530,6 +570,27 @@ 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 ObjectBuilder<Analyzer> cjk(CjkAnalyzer v) {
this._kind = Kind.Cjk;
this._value = v;
return this;
}

public ObjectBuilder<Analyzer> cjk(
Function<CjkAnalyzer.Builder, ObjectBuilder<CjkAnalyzer>> fn) {
return this.cjk(fn.apply(new CjkAnalyzer.Builder()).build());
}

public Analyzer build() {
_checkSingleUse();
return new Analyzer(this);
Expand All @@ -553,6 +614,8 @@ 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.add(Builder::cjk, CjkAnalyzer._DESERIALIZER, Kind.Cjk.jsonValue());

op.setTypeProperty("type", null);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* 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.List;
import java.util.function.Function;

import javax.annotation.Nullable;

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.ApiTypeHelper;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;

import jakarta.json.stream.JsonGenerator;

// typedef: _types.analysis.LanguageAnalyzer

@JsonpDeserializable
public class CjkAnalyzer implements AnalyzerVariant, JsonpSerializable {
@Nullable
private final List<String> stopwords;

@Nullable
private final String stopwordsPath;

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

private CjkAnalyzer(Builder builder) {

this.stopwords = ApiTypeHelper.unmodifiable(builder.stopwords);
this.stopwordsPath = builder.stopwordsPath;

}

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

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

/**
* API name: {@code stopwords}
*/
public final List<String> stopwords() {
return this.stopwords;
}

/**
* API name: {@code stopwords_path}
*/
@Nullable
public final String stopwordsPath() {
return this.stopwordsPath;
}

/**
* 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.Cjk.jsonValue());


if (ApiTypeHelper.isDefined(this.stopwords)) {
generator.writeKey("stopwords");
generator.writeStartArray();
for (String item0 : this.stopwords) {
generator.write(item0);

}
generator.writeEnd();

}
if (this.stopwordsPath != null) {
generator.writeKey("stopwords_path");
generator.write(this.stopwordsPath);

}

}

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

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

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<CjkAnalyzer> {
@Nullable
private List<String> stopwords;

@Nullable
private String stopwordsPath;

/**
* API name: {@code stopwords}
* <p>
* Adds all elements of <code>list</code> to <code>stopwords</code>.
*/
public final Builder stopwords(List<String> list) {
this.stopwords = _listAddAll(this.stopwords, list);
return this;
}

/**
* API name: {@code stopwords}
* <p>
* Adds one or more values to <code>stopwords</code>.
*/
public final Builder stopwords(String value, String... values) {
this.stopwords = _listAdd(this.stopwords, value, values);
return this;
}

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

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

return new CjkAnalyzer(this);
}
}

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

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

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

op.add(Builder::stopwords, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()),
"stopwords");
op.add(Builder::stopwordsPath, JsonpDeserializer.stringDeserializer(), "stopwords_path");

op.ignore("type");
}

}
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");
}

}
Loading

0 comments on commit a1a0b63

Please sign in to comment.