You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ji...@apache.org on 2018/01/09 00:36:04 UTC

lucene-solr:branch_7_2: SOLR-11555: If the query terms reduce to nothing, filter(clause) produces an NPE whereas fq=clause does not

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7_2 429719f25 -> 4d919e2c2


SOLR-11555: If the query terms reduce to nothing, filter(clause) produces an NPE whereas fq=clause does not


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

Branch: refs/heads/branch_7_2
Commit: 4d919e2c2e34693a5cfa3cd2170ac3eb3ebdf465
Parents: 429719f
Author: Erick Erickson <er...@apache.org>
Authored: Wed Dec 27 12:05:31 2017 -0800
Committer: Jim Ferenczi <ji...@apache.org>
Committed: Tue Jan 9 01:35:10 2018 +0100

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  3 +++
 .../java/org/apache/solr/query/FilterQuery.java |  5 +++++
 .../apache/solr/search/TestSolrQueryParser.java | 20 ++++++++++++++++++++
 3 files changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4d919e2c/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 8041326..ff15a50 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -41,6 +41,9 @@ Bug Fixes
   (Christine Poerschke and David Smiley in response to bug report/analysis
   from Dariusz Wojtas and Diego Ceccarelli)
 
+* SOLR-11555: If the query terms reduce to nothing, filter(clause) produces an NPE whereas
+  fq=clause does not (Erick Erickson)
+
 ==================  7.2.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4d919e2c/solr/core/src/java/org/apache/solr/query/FilterQuery.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/query/FilterQuery.java b/solr/core/src/java/org/apache/solr/query/FilterQuery.java
index 785ab5c..a5a7ab0 100644
--- a/solr/core/src/java/org/apache/solr/query/FilterQuery.java
+++ b/solr/core/src/java/org/apache/solr/query/FilterQuery.java
@@ -22,6 +22,7 @@ import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.BoostQuery;
 import org.apache.lucene.search.ConstantScoreQuery;
 import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.MatchNoDocsQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Weight;
 import org.apache.solr.search.DocSet;
@@ -33,6 +34,10 @@ public class FilterQuery extends ExtendedQueryBase {
   protected final Query q;
 
   public FilterQuery(Query q) {
+    if (q == null) {
+      this.q = new MatchNoDocsQuery();
+      return;
+    }
     this.q = q;
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4d919e2c/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java b/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java
index 4bf4cc5..9008595 100644
--- a/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java
+++ b/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java
@@ -497,6 +497,26 @@ public class TestSolrQueryParser extends SolrTestCaseJ4 {
         , "/response/docs/[0]/score==10.0"
     );
 
+    assertU(adoc("id", "40", "wdf_nocase", "just some text, don't want NPE"));
+    assertU(commit());
+
+    // See SOLR-11555. If wdff removes all the characters, an NPE occurs.
+    // try q and fq
+    assertJQ(req("q", "filter(wdf_nocase:&)", "fl", "id", "debug", "query")
+        , "/response/numFound==0"
+    );
+    assertJQ(req("fq", "filter(wdf_nocase:.,)", "fl", "id", "debug", "query")
+        , "/response/numFound==0"
+    );
+
+    // Insure the same behavior as with bare clause, just not filter
+    assertJQ(req("q", "wdf_nocase:&", "fl", "id", "debug", "query")
+        , "/response/numFound==0"
+    );
+    assertJQ(req("fq", "wdf_nocase:.,", "fl", "id", "debug", "query")
+        , "/response/numFound==0"
+    );
+
   }