diff --git a/src/main/java/org/opensearch/search/relevance/SearchRelevancePlugin.java b/src/main/java/org/opensearch/search/relevance/SearchRelevancePlugin.java index 8e96eed..b2143f9 100644 --- a/src/main/java/org/opensearch/search/relevance/SearchRelevancePlugin.java +++ b/src/main/java/org/opensearch/search/relevance/SearchRelevancePlugin.java @@ -22,7 +22,7 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.settings.Setting; -import org.opensearch.common.xcontent.NamedXContentRegistry; +import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.env.Environment; import org.opensearch.env.NodeEnvironment; import org.opensearch.plugins.ActionPlugin; diff --git a/src/main/java/org/opensearch/search/relevance/configuration/ResultTransformerConfigurationFactory.java b/src/main/java/org/opensearch/search/relevance/configuration/ResultTransformerConfigurationFactory.java index 431efcc..a9f3085 100644 --- a/src/main/java/org/opensearch/search/relevance/configuration/ResultTransformerConfigurationFactory.java +++ b/src/main/java/org/opensearch/search/relevance/configuration/ResultTransformerConfigurationFactory.java @@ -9,7 +9,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.core.xcontent.XContentParser; import java.io.IOException; diff --git a/src/main/java/org/opensearch/search/relevance/configuration/SearchConfigurationExtBuilder.java b/src/main/java/org/opensearch/search/relevance/configuration/SearchConfigurationExtBuilder.java index a84f544..ca082eb 100644 --- a/src/main/java/org/opensearch/search/relevance/configuration/SearchConfigurationExtBuilder.java +++ b/src/main/java/org/opensearch/search/relevance/configuration/SearchConfigurationExtBuilder.java @@ -7,12 +7,12 @@ */ package org.opensearch.search.relevance.configuration; -import org.opensearch.common.ParseField; import org.opensearch.common.ParsingException; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.xcontent.XContentBuilder; -import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.core.ParseField; +import org.opensearch.core.xcontent.XContentBuilder; +import org.opensearch.core.xcontent.XContentParser; import org.opensearch.search.SearchExtBuilder; import org.opensearch.search.relevance.transformer.TransformerType; diff --git a/src/main/java/org/opensearch/search/relevance/configuration/TransformerConfiguration.java b/src/main/java/org/opensearch/search/relevance/configuration/TransformerConfiguration.java index 625ab02..9178831 100644 --- a/src/main/java/org/opensearch/search/relevance/configuration/TransformerConfiguration.java +++ b/src/main/java/org/opensearch/search/relevance/configuration/TransformerConfiguration.java @@ -10,9 +10,9 @@ import static org.opensearch.search.relevance.configuration.Constants.ORDER; import static org.opensearch.search.relevance.configuration.Constants.PROPERTIES; -import org.opensearch.common.ParseField; import org.opensearch.common.io.stream.Writeable; -import org.opensearch.common.xcontent.ToXContentObject; +import org.opensearch.core.ParseField; +import org.opensearch.core.xcontent.ToXContentObject; public abstract class TransformerConfiguration implements Writeable, ToXContentObject { protected static final ParseField TRANSFORMER_ORDER = new ParseField(ORDER); diff --git a/src/main/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/configuration/KendraIntelligentRankingConfiguration.java b/src/main/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/configuration/KendraIntelligentRankingConfiguration.java index 25a0c11..5606b51 100644 --- a/src/main/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/configuration/KendraIntelligentRankingConfiguration.java +++ b/src/main/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/configuration/KendraIntelligentRankingConfiguration.java @@ -7,16 +7,17 @@ */ package org.opensearch.search.relevance.transformer.kendraintelligentranking.configuration; -import org.opensearch.common.ParseField; import org.opensearch.common.ParsingException; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.ObjectParser; -import org.opensearch.common.xcontent.ToXContentObject; -import org.opensearch.common.xcontent.XContentBuilder; -import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.core.ParseField; +import org.opensearch.core.xcontent.ObjectParser; +import org.opensearch.core.xcontent.ToXContent; +import org.opensearch.core.xcontent.ToXContentObject; +import org.opensearch.core.xcontent.XContentBuilder; +import org.opensearch.core.xcontent.XContentParser; import org.opensearch.search.relevance.configuration.ResultTransformerConfiguration; import org.opensearch.search.relevance.configuration.TransformerConfiguration; import org.opensearch.search.relevance.transformer.kendraintelligentranking.KendraIntelligentRanker; @@ -76,7 +77,7 @@ public void writeTo(StreamOutput out) throws IOException { this.properties.writeTo(out); } - public static ResultTransformerConfiguration parse(XContentParser parser) throws IOException { + public static KendraIntelligentRankingConfiguration parse(XContentParser parser) throws IOException { try { KendraIntelligentRankingConfiguration configuration = PARSER.parse(parser, null); if (configuration != null && configuration.getOrder() <= 0) { @@ -90,7 +91,7 @@ public static ResultTransformerConfiguration parse(XContentParser parser) throws } @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(); builder.field(TRANSFORMER_ORDER.getPreferredName(), this.order); builder.field(TRANSFORMER_PROPERTIES.getPreferredName(), this.properties); @@ -154,7 +155,7 @@ public KendraIntelligentRankingProperties(final List bodyFields, public KendraIntelligentRankingProperties(StreamInput input) throws IOException { this.bodyFields = input.readStringList(); - this.bodyFields = input.readStringList(); + this.titleFields = input.readStringList(); this.docLimit = input.readInt(); } @@ -195,7 +196,7 @@ public boolean equals(Object o) { KendraIntelligentRankingProperties properties = (KendraIntelligentRankingProperties) o; - return (bodyFields == properties.bodyFields) && (titleFields == properties.titleFields) && + return Objects.equals(bodyFields, properties.bodyFields) && Objects.equals(titleFields, properties.titleFields) && (docLimit == properties.docLimit); } @@ -228,4 +229,6 @@ public void setDocLimit(final int docLimit) { this.docLimit = docLimit; } } + + } diff --git a/src/main/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/configuration/KendraIntelligentRankingConfigurationFactory.java b/src/main/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/configuration/KendraIntelligentRankingConfigurationFactory.java index bb9d9b3..7659e9f 100644 --- a/src/main/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/configuration/KendraIntelligentRankingConfigurationFactory.java +++ b/src/main/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/configuration/KendraIntelligentRankingConfigurationFactory.java @@ -9,7 +9,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.core.xcontent.XContentParser; import org.opensearch.search.relevance.configuration.ResultTransformerConfiguration; import org.opensearch.search.relevance.configuration.ResultTransformerConfigurationFactory; import org.opensearch.search.relevance.transformer.kendraintelligentranking.KendraIntelligentRanker; diff --git a/src/test/java/org/opensearch/search/relevance/actionfilter/SearchActionFilterTests.java b/src/test/java/org/opensearch/search/relevance/actionfilter/SearchActionFilterTests.java index e73d9ce..1af2da7 100644 --- a/src/test/java/org/opensearch/search/relevance/actionfilter/SearchActionFilterTests.java +++ b/src/test/java/org/opensearch/search/relevance/actionfilter/SearchActionFilterTests.java @@ -32,9 +32,9 @@ import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentBuilder; -import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.json.JsonXContent; +import org.opensearch.core.xcontent.XContentBuilder; +import org.opensearch.core.xcontent.XContentParser; import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; import org.opensearch.search.builder.SearchSourceBuilder; diff --git a/src/test/java/org/opensearch/search/relevance/configuration/SearchConfigurationExtBuilderTests.java b/src/test/java/org/opensearch/search/relevance/configuration/SearchConfigurationExtBuilderTests.java index d16cb11..3952607 100644 --- a/src/test/java/org/opensearch/search/relevance/configuration/SearchConfigurationExtBuilderTests.java +++ b/src/test/java/org/opensearch/search/relevance/configuration/SearchConfigurationExtBuilderTests.java @@ -12,10 +12,10 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentHelper; -import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.XContentBuilder; +import org.opensearch.core.xcontent.XContentParser; import org.opensearch.test.OpenSearchTestCase; import java.io.IOException; diff --git a/src/test/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/KendraIntelligentRankerTests.java b/src/test/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/KendraIntelligentRankerTests.java index bafe6b7..a26bf87 100644 --- a/src/test/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/KendraIntelligentRankerTests.java +++ b/src/test/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/KendraIntelligentRankerTests.java @@ -13,8 +13,8 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.json.JsonXContent; +import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.index.query.MatchAllQueryBuilder; import org.opensearch.index.query.MatchQueryBuilder; import org.opensearch.search.SearchHit; diff --git a/src/test/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/configuration/KendraIntelligentRankingConfigurationTests.java b/src/test/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/configuration/KendraIntelligentRankingConfigurationTests.java index 0a35176..4b7eeaa 100644 --- a/src/test/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/configuration/KendraIntelligentRankingConfigurationTests.java +++ b/src/test/java/org/opensearch/search/relevance/transformer/kendraintelligentranking/configuration/KendraIntelligentRankingConfigurationTests.java @@ -7,17 +7,73 @@ */ package org.opensearch.search.relevance.transformer.kendraintelligentranking.configuration; -import org.junit.Test; +import org.opensearch.common.bytes.BytesReference; +import org.opensearch.common.io.stream.BytesStreamOutput; +import org.opensearch.common.settings.Settings; +import org.opensearch.common.xcontent.XContentHelper; +import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.XContentParser; +import org.opensearch.search.relevance.configuration.Constants; import org.opensearch.test.OpenSearchTestCase; import java.io.IOException; +import java.util.List; public class KendraIntelligentRankingConfigurationTests extends OpenSearchTestCase { - public void testParseWithNullParserAndContext() { - try { - KendraIntelligentRankingConfiguration.parse(null); - fail(); - } catch (NullPointerException | IOException e) { - } + public void testParseWithNullParserAndContext() throws IOException { + expectThrows(NullPointerException.class, () -> KendraIntelligentRankingConfiguration.parse(null)); + } + + public void testSerializeToXContentRoundtrip() throws IOException { + KendraIntelligentRankingConfiguration expected = getKendraIntelligentRankingConfiguration(); + + XContentType xContentType = randomFrom(XContentType.values()); + BytesReference serialized = XContentHelper.toXContent(expected, xContentType, true); + + XContentParser parser = createParser(xContentType.xContent(), serialized); + + KendraIntelligentRankingConfiguration deserialized = + KendraIntelligentRankingConfiguration.parse(parser); + assertEquals(expected, deserialized); + } + + public void testSerializeToStreamRoundtrip() throws IOException { + KendraIntelligentRankingConfiguration expected = getKendraIntelligentRankingConfiguration(); + BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(); + expected.writeTo(bytesStreamOutput); + + KendraIntelligentRankingConfiguration deserialized = + new KendraIntelligentRankingConfiguration(bytesStreamOutput.bytes().streamInput()); + assertEquals(expected, deserialized); + } + + private static KendraIntelligentRankingConfiguration getKendraIntelligentRankingConfiguration() { + int order = randomInt(10) + 1; + int docLimit = randomInt( Integer.MAX_VALUE - 25) + 25; + KendraIntelligentRankingConfiguration.KendraIntelligentRankingProperties properties = + new KendraIntelligentRankingConfiguration.KendraIntelligentRankingProperties(List.of("body1"), + List.of("title1"), docLimit); + return new KendraIntelligentRankingConfiguration(order, properties); + } + + public void testReadFromSettings() throws IOException { + int order = randomInt(10); + int docLimit = randomInt(100) + 25; + String bodyField = "body1"; + String titleField = "title1"; + Settings settings = Settings.builder() + .put(Constants.ORDER, order) + .put("properties.doc_limit", docLimit) + .put("properties.body_field", bodyField) + .putList("properties.title_field", titleField) + .build(); + + KendraIntelligentRankingConfiguration expected = new KendraIntelligentRankingConfiguration(order, + new KendraIntelligentRankingConfiguration.KendraIntelligentRankingProperties(List.of(bodyField), + List.of(titleField), docLimit)); + + KendraIntelligentRankingConfiguration actual = new KendraIntelligentRankingConfiguration(settings); + + assertEquals(expected, actual); } } \ No newline at end of file