Skip to content

Commit ba40533

Browse files
committed
Improvements based on PR comments
1 parent c5ff33d commit ba40533

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ public int rankWindowSize() {
160160
* Prioritizes docs over ids if both are present.
161161
*
162162
* @param baseQuery the base query to pin documents to
163-
* @return a PinnedQueryBuilder or the original query if no pinned documents
163+
* @return a PinnedQueryBuilder
164+
* @throws IllegalArgumentException if baseQuery is null
164165
*/
165166
private QueryBuilder createPinnedQuery(QueryBuilder baseQuery) {
166-
if (baseQuery == null) {
167-
baseQuery = new MatchAllQueryBuilder();
168-
}
167+
Objects.requireNonNull(baseQuery, "Underlying query cannot be null for pinned retriever");
168+
169169
if (docs.isEmpty() == false) {
170170
return new PinnedQueryBuilder(baseQuery, docs.toArray(new SpecifiedDocument[0]));
171171
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.xcontent.json.JsonXContent;
2525
import org.elasticsearch.xpack.searchbusinessrules.SpecifiedDocument;
2626

27+
2728
import java.io.IOException;
2829
import java.util.ArrayList;
2930
import java.util.List;

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,15 @@ setup:
333333
- gt: { hits.hits.0._score: 1.0 }
334334
- match:
335335
hits.hits.0._explanation.description: "Pinned document by ids, original explanation:"
336+
- match:
337+
hits.hits.0._explanation.details.0.description: "doc [0] with an original score of [1.7014124E38] is at rank [1] from the following source queries."
336338

337339
- match: { hits.hits.1._id: doc2 }
338340
- gt: { hits.hits.1._score: 1.0 }
339341
- match:
340342
hits.hits.1._explanation.description: "Pinned document by ids, original explanation:"
343+
- match:
344+
hits.hits.1._explanation.details.0.description: "doc [1] with an original score of [1.7014122E38] is at rank [2] from the following source queries."
341345

342346
---
343347
"pinned retriever with empty parameters":
@@ -439,3 +443,16 @@ setup:
439443
query:
440444
match: { text: "document" }
441445
sort: [ { "_id": "desc" } ]
446+
447+
---
448+
"pinned retriever error case - null inner query":
449+
- do:
450+
catch: /Underlying query cannot be null for pinned retriever/
451+
search:
452+
index: test-index1
453+
body:
454+
retriever:
455+
pinned:
456+
ids: ["doc1"]
457+
retriever:
458+
standard: {}

0 commit comments

Comments
 (0)