Skip to content

Commit 6b4c04b

Browse files
committed
Added equals and hash code implementations to LinearRetrieverBuilder
1 parent 0050ad5 commit 6b4c04b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

x-pack/plugin/rank-rrf/src/main/java/org/elasticsearch/xpack/rank/linear/LinearRetrieverBuilder.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@
3535
import java.util.List;
3636
import java.util.Locale;
3737
import java.util.Map;
38+
import java.util.Objects;
3839

3940
import static org.elasticsearch.action.ValidateActions.addValidationError;
4041
import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg;
4142
import static org.elasticsearch.xpack.rank.RankRRFFeatures.LINEAR_RETRIEVER_SUPPORTED;
4243
import static org.elasticsearch.xpack.rank.linear.LinearRetrieverComponent.DEFAULT_WEIGHT;
4344

44-
// TODO: Add toEquals method
45-
4645
/**
4746
* The {@code LinearRetrieverBuilder} supports the combination of different retrievers through a weighted linear combination.
4847
* For example, assume that we have retrievers r1 and r2, the final score of the {@code LinearRetrieverBuilder} is defined as
@@ -368,4 +367,20 @@ public void doToXContent(XContentBuilder builder, Params params) throws IOExcept
368367

369368
builder.field(RANK_WINDOW_SIZE_FIELD.getPreferredName(), rankWindowSize);
370369
}
370+
371+
@Override
372+
public boolean doEquals(Object o) {
373+
LinearRetrieverBuilder that = (LinearRetrieverBuilder) o;
374+
return super.doEquals(o)
375+
&& Arrays.equals(weights, that.weights)
376+
&& Arrays.equals(normalizers, that.normalizers)
377+
&& Objects.equals(fields, that.fields)
378+
&& Objects.equals(query, that.query)
379+
&& Objects.equals(normalizer, that.normalizer);
380+
}
381+
382+
@Override
383+
public int doHashCode() {
384+
return Objects.hash(super.doHashCode(), Arrays.hashCode(weights), Arrays.hashCode(normalizers), fields, query, normalizer);
385+
}
371386
}

0 commit comments

Comments
 (0)