apache / lucene

Apache Lucene open-source search software
https://lucene.apache.org/
Apache License 2.0
2.45k stars 973 forks source link

Add sub query explanations in DisjunctionMaxQuery#explain on no-match #13362

Closed timgrein closed 1 month ago

timgrein commented 1 month ago

Closes https://github.com/apache/lucene/issues/13357

Description

https://github.com/apache/lucene/issues/13357 states that it's useful to have the explanations of the sub queries of DisjuncationMaxQuery present, even if the document didn't match. Considering that other queries like CoveringQuery also include explanations, if the document didn't match I've adjusted the logic according to the issue's proposal.

Also added tests for explain (match and no match case). I've also adjusted CheckHits#verifyExplanation to only check sub explanations, if the overall explanation returned a hit and scores need to be checked.

jpountz commented 1 month ago

This could make explanations harder to read for large queries, e.g. queries produced through rewriting. I wonder about doing something in-between such as only including the non-matching subs if the query doesn't match, what do you think?

timgrein commented 1 month ago

This could make explanations harder to read for large queries, e.g. queries produced through rewriting. I wonder about doing something in-between such as only including the non-matching subs if the query doesn't match, what do you think?

Fair point! Adjusted the PR accordingly and added an additional test for the in-between behavior.

timgrein commented 1 month ago

Thanks for the reviews! Added it to the improvement section ✅ @jpountz