Skip to content

Commit 4476564

Browse files
committed
Working on improving integration test and introducing cluster features
1 parent 38e8d06 commit 4476564

File tree

6 files changed

+121
-23
lines changed

6 files changed

+121
-23
lines changed
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
apply plugin: 'elasticsearch.internal-es-plugin'
22
apply plugin: 'elasticsearch.internal-cluster-test'
3+
apply plugin: 'elasticsearch.internal-yaml-rest-test'
34

45
esplugin {
56
name = 'search-business-rules'
67
description = 'A plugin for applying business rules to search result rankings'
78
classname ='org.elasticsearch.xpack.searchbusinessrules.SearchBusinessRules'
89
extendedPlugins = ['x-pack-core']
910
}
10-
base {
11-
archivesName = 'x-pack-searchbusinessrules'
12-
}
1311

1412
dependencies {
1513
compileOnly project(path: xpackModule('core'))
1614
testImplementation(testArtifact(project(xpackModule('core'))))
1715
testImplementation project(":test:framework")
16+
17+
yamlRestTestImplementation(testArtifact(project(xpackModule('core'))))
18+
}
19+
20+
restResources {
21+
restTests {
22+
includeXpack 'searchbusinessrules'
23+
}
24+
}
25+
26+
testClusters.matching { it.name == "yamlRestTest" }.configureEach {
27+
testDistribution = 'DEFAULT'
28+
setting 'xpack.license.self_generated.type', 'trial'
1829
}

x-pack/plugin/search-business-rules/src/main/java/module-info.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616
requires org.elasticsearch.xcore;
1717

1818
exports org.elasticsearch.xpack.searchbusinessrules;
19+
20+
provides org.elasticsearch.features.FeatureSpecification with org.elasticsearch.xpack.searchbusinessrules.SearchBusinessRulesFeatures;
1921
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.searchbusinessrules;
9+
10+
import org.elasticsearch.features.FeatureSpecification;
11+
import org.elasticsearch.features.NodeFeature;
12+
13+
import java.util.Set;
14+
15+
public class SearchBusinessRulesFeatures implements FeatureSpecification {
16+
public static final NodeFeature PINNED_RETRIEVER_TEST_FEATURE = new NodeFeature("pinned_retriever_test");
17+
18+
@Override
19+
public Set<NodeFeature> getFeatures() {
20+
return Set.of(PINNED_RETRIEVER_TEST_FEATURE);
21+
}
22+
23+
@Override
24+
public Set<NodeFeature> getTestFeatures() {
25+
return Set.of(PINNED_RETRIEVER_TEST_FEATURE);
26+
}
27+
}

x-pack/plugin/search-business-rules/src/main/java/org/elasticsearch/xpack/searchbusinessrules/retriever/PinnedRankDoc.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
18
package org.elasticsearch.xpack.searchbusinessrules.retriever;
29

310
import org.elasticsearch.search.rank.RankDoc;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
# or more contributor license agreements. Licensed under the Elastic License
4+
# 2.0; you may not use this file except in compliance with the Elastic License
5+
# 2.0.
6+
#
7+
8+
org.elasticsearch.xpack.searchbusinessrules.SearchBusinessRulesFeatures

x-pack/plugin/search-business-rules/src/yamlRestTest/resources/rest-api-spec/test/searchbusinessrules/10_pinned_retriever.yml

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
setup:
2+
- requires:
3+
cluster_features: ["pinned_retriever_test"]
4+
reason: "pinned retriever test feature is required"
5+
26
- do:
37
indices.create:
48
index: test-index1
@@ -31,7 +35,6 @@ setup:
3135

3236
---
3337
"pinned retriever basic functionality":
34-
3538
- do:
3639
search:
3740
index: test-index1
@@ -50,13 +53,14 @@ setup:
5053
- match: { hits.hits.2._id: doc3 }
5154
- match: { hits.hits.3._id: doc4 }
5255
- match: { hits.hits.4._id: doc5 }
56+
- is_true: { hits.hits.0._score > 1.0 }
57+
- is_true: { hits.hits.1._score > 1.0 }
58+
- is_true: { hits.hits.2._score <= 1.0 }
59+
- is_true: { hits.hits.3._score <= 1.0 }
60+
- is_true: { hits.hits.4._score <= 1.0 }
5361

5462
---
5563
"pinned retriever parameter variations":
56-
- requires:
57-
cluster_features: ["gte_v7.15.0"]
58-
reason: "docs parameter support was added in 7.15"
59-
6064
- do:
6165
search:
6266
index: test-index1
@@ -76,6 +80,11 @@ setup:
7680
- match: { hits.total.value: 5 }
7781
- match: { hits.hits.0._id: doc1 }
7882
- match: { hits.hits.1._id: doc2 }
83+
- is_true: { hits.hits.0._score > 1.0 }
84+
- is_true: { hits.hits.1._score > 1.0 }
85+
- is_true: { hits.hits.2._score <= 1.0 }
86+
- is_true: { hits.hits.3._score <= 1.0 }
87+
- is_true: { hits.hits.4._score <= 1.0 }
7988

8089
- do:
8190
search:
@@ -91,6 +100,11 @@ setup:
91100

92101
- match: { hits.total.value: 5 }
93102
- match: { hits.hits.0._id: doc1 }
103+
- is_true: { hits.hits.0._score > 1.0 }
104+
- is_true: { hits.hits.1._score <= 1.0 }
105+
- is_true: { hits.hits.2._score <= 1.0 }
106+
- is_true: { hits.hits.3._score <= 1.0 }
107+
- is_true: { hits.hits.4._score <= 1.0 }
94108

95109
- do:
96110
search:
@@ -108,13 +122,14 @@ setup:
108122

109123
- match: { hits.total.value: 5 }
110124
- match: { hits.hits.0._id: doc1 }
125+
- is_true: { hits.hits.0._score > 1.0 }
126+
- is_true: { hits.hits.1._score <= 1.0 }
127+
- is_true: { hits.hits.2._score <= 1.0 }
128+
- is_true: { hits.hits.3._score <= 1.0 }
129+
- is_true: { hits.hits.4._score <= 1.0 }
111130

112131
---
113132
"pinned retriever with combined parameters":
114-
- requires:
115-
cluster_features: ["gte_v7.15.0"]
116-
reason: "combined parameters support was added in 7.15"
117-
118133
- do:
119134
search:
120135
index: test-index1
@@ -133,6 +148,11 @@ setup:
133148
- match: { hits.total.value: 5 }
134149
- match: { hits.hits.0._id: doc1 }
135150
- match: { hits.hits.1._id: doc2 }
151+
- is_true: { hits.hits.0._score > 1.0 }
152+
- is_true: { hits.hits.1._score > 1.0 }
153+
- is_true: { hits.hits.2._score <= 1.0 }
154+
- is_true: { hits.hits.3._score <= 1.0 }
155+
- is_true: { hits.hits.4._score <= 1.0 }
136156

137157
- do:
138158
search:
@@ -156,10 +176,14 @@ setup:
156176
- match: { hits.hits.1._id: doc3 }
157177
- match: { hits.hits.2._id: doc2 }
158178
- match: { hits.hits.3._id: doc4 }
179+
- is_true: { hits.hits.0._score > 1.0 }
180+
- is_true: { hits.hits.1._score > 1.0 }
181+
- is_true: { hits.hits.2._score > 1.0 }
182+
- is_true: { hits.hits.3._score > 1.0 }
183+
- is_true: { hits.hits.4._score <= 1.0 }
159184

160185
---
161186
"pinned retriever combined with rrf":
162-
163187
- do:
164188
search:
165189
index: test-index1
@@ -173,14 +197,18 @@ setup:
173197
{
174198
standard: {
175199
query: {
176-
match_all: {}
200+
match: {
201+
text: "document one"
202+
}
177203
}
178204
}
179205
},
180206
{
181207
standard: {
182208
query: {
183-
match_all: {}
209+
match: {
210+
text: "document two"
211+
}
184212
}
185213
}
186214
}
@@ -189,10 +217,13 @@ setup:
189217
- match: { hits.total.value: 5 }
190218
- match: { hits.hits.0._id: doc1 }
191219
- match: { hits.hits.1._id: doc2 }
220+
- is_true: { hits.hits.0._score > 1.0 }
221+
- is_true: { hits.hits.1._score > 1.0 }
222+
- is_true: { hits.hits.2._score > hits.hits.3._score }
223+
- is_true: { hits.hits.3._score > hits.hits.4._score }
192224

193225
---
194226
"pinned retriever with pagination":
195-
196227
- do:
197228
search:
198229
index: test-index1
@@ -210,10 +241,10 @@ setup:
210241
- match: { hits.total.value: 5 }
211242
- length: { hits.hits: 1 }
212243
- match: { hits.hits.0._id: doc2 }
244+
- is_true: { hits.hits.0._score > 1.0 }
213245

214246
---
215247
"pinned retriever as a sub-retriever":
216-
217248
- do:
218249
search:
219250
index: test-index1
@@ -243,10 +274,14 @@ setup:
243274
]
244275

245276
- match: { hits.total.value: 5 }
277+
- is_true: { hits.hits.0._score > 1.0 }
278+
- is_true: { hits.hits.1._score > 1.0 }
279+
- is_true: { hits.hits.2._score <= 1.0 }
280+
- is_true: { hits.hits.3._score <= 1.0 }
281+
- is_true: { hits.hits.4._score <= 1.0 }
246282

247283
---
248284
"pinned retriever with explicit sort on score":
249-
250285
- do:
251286
search:
252287
index: test-index1
@@ -263,6 +298,11 @@ setup:
263298
- match: { hits.total.value: 5 }
264299
- match: { hits.hits.0._id: doc1 }
265300
- match: { hits.hits.1._id: doc2 }
301+
- is_true: { hits.hits.0._score > 1.0 }
302+
- is_true: { hits.hits.1._score > 1.0 }
303+
- is_true: { hits.hits.2._score <= 1.0 }
304+
- is_true: { hits.hits.3._score <= 1.0 }
305+
- is_true: { hits.hits.4._score <= 1.0 }
266306

267307
---
268308
"pinned retriever with rank window size":
@@ -316,7 +356,6 @@ setup:
316356

317357
---
318358
"pinned retriever explanation":
319-
320359
- do:
321360
headers:
322361
Content-Type: application/json
@@ -335,12 +374,17 @@ setup:
335374
- match: { hits.hits.0._id: doc1 }
336375
- is_true: { hits.hits.0._explanation.value > 1.0 }
337376
- is_true: { hits.hits.0._explanation.description: "pinned documents" }
338-
- is_true: { hits.hits.0._explanation.description: "rank [1]" }
339-
- is_true: { hits.hits.0._explanation.details.0.details.0.details.0.details.0.details.0.description: "ConstantScore" }
377+
- is_true: { hits.hits.0._explanation.details.0.details.0.details.0.description: "pinned_by: [ids]" }
378+
- is_true: { hits.hits.0._explanation.details.0.details.0.details.1.description: "is_pinned: true" }
379+
380+
- match: { hits.hits.1._id: doc2 }
381+
- is_true: { hits.hits.1._explanation.value > 1.0 }
382+
- is_true: { hits.hits.1._explanation.description: "pinned documents" }
383+
- is_true: { hits.hits.1._explanation.details.0.details.0.details.0.description: "pinned_by: [ids]" }
384+
- is_true: { hits.hits.1._explanation.details.0.details.0.details.1.description: "is_pinned: true" }
340385

341386
---
342387
"pinned retriever with empty parameters":
343-
344388
- do:
345389
search:
346390
index: test-index1
@@ -361,7 +405,6 @@ setup:
361405

362406
---
363407
"pinned retriever error cases":
364-
365408
- do:
366409
catch: /\[pinned\] duplicate id found in list: doc1/
367410
search:

0 commit comments

Comments
 (0)