mirror of https://github.com/apache/lucene.git
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:
parent
c2819930d7
commit
e91d120999
|
@ -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)
|
||||
|
|
|
@ -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:"
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in New Issue