-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accommodate changes to XContent classes #125
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<String> bodyFields, | |
|
||
public KendraIntelligentRankingProperties(StreamInput input) throws IOException { | ||
this.bodyFields = input.readStringList(); | ||
this.bodyFields = input.readStringList(); | ||
this.titleFields = input.readStringList(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this related to the XContent classes change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not directly. When merging the cherry-picked commit, I also picked up the unit tests that I had previously added (in KendraIntelligentRankingConfigurationTests). When I added those tests in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh... I just added the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, but the backport PR fails to build because we need to merge this PR to fix the XContent stuff: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Looks like there are two ways to handle this issue:
I'm fine with either, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think #126 shouldn't have any conflicts once this one is merged, because any overlapping changes should be identical. |
||
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; | ||
} | ||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re:naming - is this going from less specific naming to more specific intentionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
a) It helps the unit tests, since we can confirm the specific type.
b) There's a best-practice to take the most general type of argument and return the most specific type. I think it's an application of the Liskov substitution principle.