Skip to content

Apache Lucene open-source search software

SOLR-4318 NPE when doing a wildcard query on a TextField with the default analysis chain

Erick Erickson05c544ec1960
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 4cf470ce720..9aa6d91b141 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -122,6 +122,9 @@ Bug Fixes
* SOLR-4570: Even if an explicit shard id is used, ZkController#preRegister
should still wait to see the shard id in it's current ClusterState.
(Mark Miller)
+
+* SOLR-4318: NPE encountered with querying with wildcards on a field that uses
+ the DefaultAnalyzer (i.e. no analysis chain defined). (Erick Erickson)
* SOLR-4585: The Collections API validates numShards with < 0 but should use
<= 0. (Mark Miller)
diff --git a/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java b/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java
index 6f68dd5085d..4738af38997 100644
--- a/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java
+++ b/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java
@@ -922,7 +922,8 @@ public abstract class SolrQueryParserBase {
}
protected String analyzeIfMultitermTermText(String field, String part, FieldType fieldType) {
- if (part == null) return part;
+
+ if (part == null || ! (fieldType instanceof TextField) || ((TextField)fieldType).getMultiTermAnalyzer() == null) return part;
SchemaField sf = schema.getFieldOrNull((field));
if (sf == null || ! (fieldType instanceof TextField)) return part;
diff --git a/solr/core/src/java/org/apache/solr/schema/TextField.java b/solr/core/src/java/org/apache/solr/schema/TextField.java
index 6e3c73f2cce..f599d9df3f5 100644
--- a/solr/core/src/java/org/apache/solr/schema/TextField.java
+++ b/solr/core/src/java/org/apache/solr/schema/TextField.java
@@ -137,7 +137,7 @@ public class TextField extends FieldType {
}
public static BytesRef analyzeMultiTerm(String field, String part, Analyzer analyzerIn) {
- if (part == null) return null;
+ if (part == null || analyzerIn == null) return null;
TokenStream source;
try {
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema11.xml b/solr/core/src/test-files/solr/collection1/conf/schema11.xml
index 6d5fd1adc5c..35dc6b81da2 100755
--- a/solr/core/src/test-files/solr/collection1/conf/schema11.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema11.xml
@@ -286,6 +286,7 @@ valued. -->
stored="false" indexed="true"
class="solr.ExternalFileField"/>
+ <fieldType name="text_no_analyzer" stored="false" indexed="true" class="solr.TextField" />
</types>
@@ -322,6 +323,8 @@ valued. -->
<field name="eff_trie" type="eff_tfloat" />
+ <field name="text_no_analyzer" type="text_no_analyzer" indexed="true" />
+
<!-- Dynamic field definitions. If a field name is not found, dynamicFields
will be used if the name matches any of the patterns.
RESTRICTION: the glob-like pattern in the name attribute must have
diff --git a/solr/core/src/test/org/apache/solr/search/TestQueryTypes.java b/solr/core/src/test/org/apache/solr/search/TestQueryTypes.java
index 48f5cc410b2..8f2cee8c72e 100755
--- a/solr/core/src/test/org/apache/solr/search/TestQueryTypes.java
+++ b/solr/core/src/test/org/apache/solr/search/TestQueryTypes.java
@@ -56,6 +56,7 @@ public class TestQueryTypes extends AbstractSolrTestCase {
assertU(adoc("id","7", "v_f","1.5"));
assertU(adoc("id","8", "v_ti","5"));
assertU(adoc("id","9", "v_s","internal\"quote"));
+ assertU(adoc("id","10","text_no_analyzer","should just work"));
Object[] arr = new Object[] {
"id",999.0
@@ -423,6 +424,8 @@ public class TestQueryTypes extends AbstractSolrTestCase {
req("q","_query_:\"{!query defType=query v=$q1}\"", "q1","{!v=$q2}","q2","{!prefix f=v_t v=$qqq}","qqq","hel")
,"//result[@numFound='2']"
);
+ assertQ("Test text field with no analysis doesn't NPE with wildcards (SOLR-4318)",
+ req("q", "text_no_analyzer:should*"), "//result[@numFound='1']");
}
}