Skip to content

Commit 108b89c

Browse files
committed
Actually check scores are passed through
1 parent df8b1ac commit 108b89c

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

test/framework/src/main/java/org/elasticsearch/search/rank/rerank/AbstractRerankerIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;
3131
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;
3232
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasRank;
33+
import static org.hamcrest.Matchers.arrayWithSize;
3334
import static org.hamcrest.Matchers.equalTo;
3435

3536
/**
@@ -403,7 +404,7 @@ public void testRankFeaturePhaseShardThrowingPartialFailures() throws Exception
403404
.allMatch(failure -> failure.getCause().getMessage().contains("rfs - simulated failure"))
404405
);
405406
assertHitCount(response, 5);
406-
assertTrue(response.getHits().getHits().length == 0);
407+
assertThat(response.getHits().getHits(), arrayWithSize(5));
407408
}
408409
);
409410
assertNoOpenContext(indexName);

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/rank/textsimilarity/TextSimilarityRankMultiNodeTests.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.elasticsearch.xpack.inference.rank.textsimilarity;
99

1010
import org.elasticsearch.plugins.Plugin;
11+
import org.elasticsearch.search.SearchHit;
1112
import org.elasticsearch.search.rank.RankBuilder;
1213
import org.elasticsearch.search.rank.rerank.AbstractRerankerIT;
1314
import org.elasticsearch.xpack.inference.LocalStateInferencePlugin;
@@ -16,9 +17,12 @@
1617
import java.util.List;
1718

1819
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
20+
import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery;
1921
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
2022
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
2123
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailuresAndResponse;
24+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;
25+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasRank;
2226

2327
public class TextSimilarityRankMultiNodeTests extends AbstractRerankerIT {
2428

@@ -84,11 +88,11 @@ public void testRerankerAllowedFailureNoExceptions() throws Exception {
8488

8589
assertNoFailuresAndResponse(
8690
prepareSearch().setQuery(
87-
boolQuery().should(matchQuery(searchField, "A"))
88-
.should(matchQuery(searchField, "B"))
89-
.should(matchQuery(searchField, "C"))
90-
.should(matchQuery(searchField, "D"))
91-
.should(matchQuery(searchField, "E"))
91+
boolQuery().should(constantScoreQuery(matchQuery(searchField, "A")).boost(10))
92+
.should(constantScoreQuery(matchQuery(searchField, "B")).boost(20))
93+
.should(constantScoreQuery(matchQuery(searchField, "C")).boost(30))
94+
.should(constantScoreQuery(matchQuery(searchField, "D")).boost(40))
95+
.should(constantScoreQuery(matchQuery(searchField, "E")).boost(50))
9296
)
9397
.setRankBuilder(
9498
getThrowingRankBuilder(
@@ -103,8 +107,16 @@ public void testRerankerAllowedFailureNoExceptions() throws Exception {
103107
.setAllowPartialSearchResults(true)
104108
.setSize(10),
105109
response -> {
106-
// just check it returns 5 documents, the order will be random due to not getting reranked
107110
assertHitCount(response, 5L);
111+
int rank = 1;
112+
for (SearchHit searchHit : response.getHits().getHits()) {
113+
int id = 5 - (rank - 1);
114+
assertThat(searchHit, hasId(String.valueOf(id)));
115+
assertThat(searchHit, hasRank(rank));
116+
assertNotNull(searchHit.getFields().get(searchField));
117+
assertEquals(id * 10, searchHit.getScore(), 0f);
118+
rank++;
119+
}
108120
}
109121
);
110122
assertNoOpenContext(indexName);

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/rank/textsimilarity/TextSimilarityRankTests.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import java.util.List;
3030
import java.util.Map;
3131

32+
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
33+
import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery;
34+
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
3235
import static org.elasticsearch.test.LambdaMatchers.transformedMatch;
3336
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasRank;
3437
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasScore;
@@ -202,17 +205,23 @@ public void testRerankInferenceAllowedFailure() {
202205
AbstractRerankerIT.ThrowingRankBuilderType.THROWING_RANK_FEATURE_PHASE_COORDINATOR_CONTEXT.name()
203206
)
204207
)
205-
.setQuery(QueryBuilders.matchAllQuery()),
208+
.setQuery(
209+
boolQuery().should(constantScoreQuery(matchQuery("text", "0")).boost(50))
210+
.should(constantScoreQuery(matchQuery("text", "1")).boost(40))
211+
.should(constantScoreQuery(matchQuery("text", "2")).boost(30))
212+
.should(constantScoreQuery(matchQuery("text", "3")).boost(20))
213+
.should(constantScoreQuery(matchQuery("text", "4")).boost(10))
214+
),
206215
response -> {
207-
// these will all have a score of 1, the score from matchAllQuery
216+
// these will all have the scores from the constant score clauses
208217
assertThat(
209218
response.getHits().getHits(),
210219
arrayContaining(
211-
searchHitWith(1, 1.0f, "0"),
212-
searchHitWith(2, 1.0f, "1"),
213-
searchHitWith(3, 1.0f, "2"),
214-
searchHitWith(4, 1.0f, "3"),
215-
searchHitWith(5, 1.0f, "4")
220+
searchHitWith(1, 50, "0"),
221+
searchHitWith(2, 40, "1"),
222+
searchHitWith(3, 30, "2"),
223+
searchHitWith(4, 20, "3"),
224+
searchHitWith(5, 10, "4")
216225
)
217226
);
218227
}

0 commit comments

Comments
 (0)