Skip to content

Commit 0a26015

Browse files
committed
Merge remote-tracking branch 'origin/ltr_two_pass' into ltr_two_pass
2 parents 05efc92 + 8595efd commit 0a26015

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

docs/changelog/125103.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 125103
2+
summary: Fix LTR query feature with phrases (and two-phase) queries
3+
area: Ranking
4+
type: bug
5+
issues: []

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/inference/ltr/QueryFeatureExtractor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public List<String> featureNames() {
8181

8282
private static class FeatureDisiWrapper extends DisiWrapper {
8383
final String featureName;
84+
8485
FeatureDisiWrapper(Scorer scorer, String featureName) {
8586
super(scorer, false);
8687
this.featureName = featureName;

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/ltr/QueryFeatureExtractorTests.java

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,37 @@ private IndexReader addDocs(Directory dir, String[] textValues, int[] numberValu
6363

6464
public void testQueryExtractor() throws IOException {
6565
try (var dir = newDirectory()) {
66-
try (var reader = addDocs(
66+
try (
67+
var reader = addDocs(
6768
dir,
68-
new String[]{"the quick brown fox", "the slow brown fox", "the grey dog", "yet another string"},
69-
new int[]{5, 10, 12, 11}
70-
)) {
69+
new String[] { "the quick brown fox", "the slow brown fox", "the grey dog", "yet another string" },
70+
new int[] { 5, 10, 12, 11 }
71+
)
72+
) {
7173
var searcher = newSearcher(reader);
7274
searcher.setSimilarity(new ClassicSimilarity());
7375
QueryRewriteContext ctx = createQueryRewriteContext();
7476
List<QueryExtractorBuilder> queryExtractorBuilders = List.of(
75-
new QueryExtractorBuilder("text_score", QueryProvider.fromParsedQuery(QueryBuilders.matchQuery(TEXT_FIELD_NAME, "quick fox")))
76-
.rewrite(ctx),
77-
new QueryExtractorBuilder(
78-
"number_score",
79-
QueryProvider.fromParsedQuery(QueryBuilders.rangeQuery(INT_FIELD_NAME).from(12).to(12))
80-
).rewrite(ctx),
81-
new QueryExtractorBuilder(
82-
"matching_none",
83-
QueryProvider.fromParsedQuery(QueryBuilders.termQuery(TEXT_FIELD_NAME, "never found term"))
84-
).rewrite(ctx),
85-
new QueryExtractorBuilder(
86-
"matching_missing_field",
87-
QueryProvider.fromParsedQuery(QueryBuilders.termQuery("missing_text", "quick fox"))
88-
).rewrite(ctx),
89-
new QueryExtractorBuilder("phrase_score", QueryProvider.fromParsedQuery(QueryBuilders.matchPhraseQuery(TEXT_FIELD_NAME, "slow brown fox"))
90-
).rewrite(ctx)
77+
new QueryExtractorBuilder(
78+
"text_score",
79+
QueryProvider.fromParsedQuery(QueryBuilders.matchQuery(TEXT_FIELD_NAME, "quick fox"))
80+
).rewrite(ctx),
81+
new QueryExtractorBuilder(
82+
"number_score",
83+
QueryProvider.fromParsedQuery(QueryBuilders.rangeQuery(INT_FIELD_NAME).from(12).to(12))
84+
).rewrite(ctx),
85+
new QueryExtractorBuilder(
86+
"matching_none",
87+
QueryProvider.fromParsedQuery(QueryBuilders.termQuery(TEXT_FIELD_NAME, "never found term"))
88+
).rewrite(ctx),
89+
new QueryExtractorBuilder(
90+
"matching_missing_field",
91+
QueryProvider.fromParsedQuery(QueryBuilders.termQuery("missing_text", "quick fox"))
92+
).rewrite(ctx),
93+
new QueryExtractorBuilder(
94+
"phrase_score",
95+
QueryProvider.fromParsedQuery(QueryBuilders.matchPhraseQuery(TEXT_FIELD_NAME, "slow brown fox"))
96+
).rewrite(ctx)
9197
);
9298
SearchExecutionContext dummySEC = createSearchExecutionContext();
9399
List<Weight> weights = new ArrayList<>();
@@ -138,11 +144,13 @@ public void testEmptyDisiPriorityQueue() throws IOException {
138144
try (var dir = newDirectory()) {
139145
var config = newIndexWriterConfig();
140146
config.setMergePolicy(NoMergePolicy.INSTANCE);
141-
try (var reader = addDocs(
147+
try (
148+
var reader = addDocs(
142149
dir,
143-
new String[]{"the quick brown fox", "the slow brown fox", "the grey dog", "yet another string"},
144-
new int[]{5, 10, 12, 11}
145-
)) {
150+
new String[] { "the quick brown fox", "the slow brown fox", "the grey dog", "yet another string" },
151+
new int[] { 5, 10, 12, 11 }
152+
)
153+
) {
146154

147155
var searcher = newSearcher(reader);
148156
searcher.setSimilarity(new ClassicSimilarity());

0 commit comments

Comments
 (0)