Skip to content

Commit

Permalink
Add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kderusso committed Oct 21, 2024
1 parent 3347a9b commit 6f0e80f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,82 @@ setup:
}
}
]

---
"query rules retriever supports explicit sort on score":

- do:
search:
index: test-index1
body:
retriever:
rule:
match_criteria:
foo: foo
bar: bar
ruleset_ids:
test-ruleset
retriever:
standard:
query:
query_string:
query: bar
sort: [ "_score" ]

- match: { hits.total.value: 3 }
- match: { hits.hits.0._id: foo }
- match: { hits.hits.1._id: foo2 }
- match: { hits.hits.2._id: bar_no_rule }

---
"query rules will error if sorting by anything other than score":

- do:
catch: /\[rule\] retriever only supports sort by score/
search:
index: test-index1
body:
retriever:
rule:
match_criteria:
foo: foo
bar: bar
ruleset_ids:
test-ruleset
retriever:
standard:
query:
query_string:
query: bar
sort: [ { "_id": "desc" } ]

---
"query rules retriever explains pinned documents as constant score queries":

- do:
search:
index: test-index1
body:
retriever:
rule:
match_criteria:
foo: foo
bar: bar
ruleset_ids:
test-ruleset
retriever:
standard:
query:
query_string:
query: bar
explain: true

- match: { hits.hits.0._id: foo }
- match: { hits.hits.0._explanation.value: 1 }
- match: { hits.hits.0._explanation.description: "doc [0] with an original score of [1.7014124E38] is at rank [1] from the following source queries." }
- match: { hits.hits.0._explanation.details.0.value: 1 }
- match: { 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." }
- match: { hits.hits.0._explanation.details.0.details.0.description: "sum of:" }
- match: { hits.hits.0._explanation.details.0.details.0.details.0.description: "max of:" }
- match: { hits.hits.0._explanation.details.0.details.0.details.0.details.0.description: "max of:" }
- match: { hits.hits.0._explanation.details.0.details.0.details.0.details.0.details.0.description: "ConstantScore(_id:([7e 8a]))^1.7014124E38" }
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ private static void checkValidSort(List<SortBuilder<?>> sortBuilders) {
return;
}

if (sortBuilders.get(0) instanceof ScoreSortBuilder == false) {
throw new IllegalArgumentException("Rule retrievers can only sort documents by relevance score, got: " + sortBuilders);
if (sortBuilders.getFirst() instanceof ScoreSortBuilder == false) {
throw new IllegalArgumentException("[" + NAME + "] retriever only supports sort by score, got: " + sortBuilders);
}
}

Expand Down

0 comments on commit 6f0e80f

Please sign in to comment.