mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-09 06:25:07 +00:00
Fix script score function that combines _score and weight (#22713)
The weight factor function does not check if the delegate score function needs to access the score of the query. This results in a _score equals to 0 for all score function that set a weight. This change modifies the WeightFactorFunction#needsScore to delegate the call to its underlying score function. Fix #21483
This commit is contained in:
parent
daf1f184d4
commit
4ec4bad908
@ -68,7 +68,7 @@ public class WeightFactorFunction extends ScoreFunction {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean needsScores() {
|
public boolean needsScores() {
|
||||||
return false;
|
return scoreFunction.needsScores();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Explanation explainWeight() {
|
public Explanation explainWeight() {
|
||||||
|
@ -751,6 +751,33 @@ public class FunctionScoreTests extends ESTestCase {
|
|||||||
assertThat(searchResult.scoreDocs[0].score, equalTo(explanation.getValue()));
|
assertThat(searchResult.scoreDocs[0].score, equalTo(explanation.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testWeightFactorNeedsScore() {
|
||||||
|
for (boolean needsScore : new boolean[] {true, false}) {
|
||||||
|
WeightFactorFunction function = new WeightFactorFunction(10.0f, new ScoreFunction(CombineFunction.REPLACE) {
|
||||||
|
@Override
|
||||||
|
public LeafScoreFunction getLeafScoreFunction(LeafReaderContext ctx) throws IOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean needsScores() {
|
||||||
|
return needsScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean doEquals(ScoreFunction other) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int doHashCode() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assertEquals(needsScore, function.needsScores());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class DummyScoreFunction extends ScoreFunction {
|
private static class DummyScoreFunction extends ScoreFunction {
|
||||||
protected DummyScoreFunction(CombineFunction scoreCombiner) {
|
protected DummyScoreFunction(CombineFunction scoreCombiner) {
|
||||||
super(scoreCombiner);
|
super(scoreCombiner);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user