LUCENE-8305: ComplexPhraseQuery.rewrite now handles an embedded MultiTermQuery

that rewrites to a MatchNoDocsQuery instead of throwing an exception.
Fixes #258
Fixes #327
This commit is contained in:
David Smiley 2018-05-09 23:03:40 -04:00
parent c2819930d7
commit e91d120999
3 changed files with 13 additions and 0 deletions

View File

@ -198,6 +198,10 @@ Bug Fixes
* LUCENE-8244: Do not leak open file descriptors in SearcherTaxonomyManager's
refresh on exception (Mike McCandless)
* LUCENE-8305: ComplexPhraseQuery.rewrite now handles an embedded MultiTermQuery
that rewrites to a MatchNoDocsQuery instead of throwing an exception.
(Bjarke Mortensen, Andy Tran via David Smiley)
Other
* LUCENE-8301: Update randomizedtesting to 2.6.0. (Dawid Weiss)

View File

@ -398,6 +398,13 @@ public class ComplexPhraseQueryParser extends QueryParser {
} else if (childQuery instanceof BooleanQuery) {
BooleanQuery cbq = (BooleanQuery) childQuery;
addComplexPhraseClause(chosenList, cbq);
} else if (childQuery instanceof MatchNoDocsQuery) {
// Insert fake term e.g. phrase query was for "Fred Smithe*" and
// there were no "Smithe*" terms - need to
// prevent match on just "Fred".
SpanQuery stq = new SpanTermQuery(new Term(field,
"Dummy clause because no terms found - must match nothing"));
chosenList.add(stq);
} else {
// TODO alternatively could call extract terms here?
throw new IllegalArgumentException("Unknown query type:"

View File

@ -64,6 +64,8 @@ public class TestComplexPhraseQuery extends LuceneTestCase {
checkMatches("\"john\"", "1,3"); // Simple single-term still works
checkMatches("\"(john OR johathon) smith\"", "1,2"); // boolean logic with
// brackets works.
checkMatches("\"(john OR nosuchword*) smith\"", "1"); // boolean logic with
// brackets works when one of the terms in BooleanQuery does not exist (LUCENE-8305).
checkMatches("\"(jo* -john) smyth~\"", "2"); // boolean logic with
// brackets works.