You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2018/05/15 20:04:37 UTC

[20/39] lucene-solr:jira/solr-11779: LUCENE-8305: ComplexPhraseQuery.rewrite now handles an embedded MultiTermQuery that rewrites to a MatchNoDocsQuery instead of throwing an exception. Fixes #258 Fixes #327

LUCENE-8305: ComplexPhraseQuery.rewrite now handles an embedded MultiTermQuery
that rewrites to a MatchNoDocsQuery instead of throwing an exception.
Fixes #258
Fixes #327


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/e91d1209
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/e91d1209
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/e91d1209

Branch: refs/heads/jira/solr-11779
Commit: e91d120999d0e92523aed5b1ced1513538c3c05e
Parents: c281993
Author: David Smiley <ds...@apache.org>
Authored: Wed May 9 23:03:40 2018 -0400
Committer: David Smiley <ds...@apache.org>
Committed: Wed May 9 23:03:40 2018 -0400

----------------------------------------------------------------------
 lucene/CHANGES.txt                                            | 4 ++++
 .../queryparser/complexPhrase/ComplexPhraseQueryParser.java   | 7 +++++++
 .../queryparser/complexPhrase/TestComplexPhraseQuery.java     | 2 ++
 3 files changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e91d1209/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index baede74..2535eb1 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -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)

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e91d1209/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java
----------------------------------------------------------------------
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java
index 32f4fb3..ffe0066 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java
@@ -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:"

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e91d1209/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java
----------------------------------------------------------------------
diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java
index 5c45e28..5935da9 100644
--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java
+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java
@@ -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.