Apache Solr open-source search software
SOLR-6017: Fix SimpleQParser to use query analyzer instead of index analyzer
Ryan Ernst0dea18dd2eb7
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 3a83dcb1551..ba1592b2091 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -121,6 +121,9 @@ Bug Fixesrollback as well as how SolrIndexWriter manages it's ref counted directoryinstance. (Mark Miller, Gregory Chanan)+* SOLR-6017: Fix SimpleQParser to use query analyzer instead of index analyzer.+ (Ryan Ernst)+Other Changes---------------------diff --git a/solr/core/src/java/org/apache/solr/search/SimpleQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/SimpleQParserPlugin.javaindex feaa24a01ec..e23f9e34102 100644--- a/solr/core/src/java/org/apache/solr/search/SimpleQParserPlugin.java+++ b/solr/core/src/java/org/apache/solr/search/SimpleQParserPlugin.java@@ -155,7 +155,7 @@ public class SimpleQParserPlugin extends QParserPlugin {// Create a SimpleQueryParser using the analyzer from the schema.final IndexSchema schema = req.getSchema();- parser = new SolrSimpleQueryParser(req.getSchema().getAnalyzer(), queryFields, enabledOps, this, schema);+ parser = new SolrSimpleQueryParser(req.getSchema().getQueryAnalyzer(), queryFields, enabledOps, this, schema);// Set the default operator to be either 'AND' or 'OR' for the query.QueryParser.Operator defaultOp = QueryParsing.getQueryParserDefaultOperator(req.getSchema(), defaultParams.get(QueryParsing.OP));diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-simpleqpplugin.xml b/solr/core/src/test-files/solr/collection1/conf/schema-simpleqpplugin.xmlindex 8ad2b4d3d43..765d88c30ac 100644--- a/solr/core/src/test-files/solr/collection1/conf/schema-simpleqpplugin.xml+++ b/solr/core/src/test-files/solr/collection1/conf/schema-simpleqpplugin.xml@@ -38,6 +38,18 @@<tokenizer class="solr.MockTokenizerFactory" pattern="keyword"/></analyzer></fieldtype>++ <!-- basic text field: except it will use the keyword analyzer -->+ <fieldtype name="text-query" class="solr.TextField">+ <analyzer type="index">+ <tokenizer class="solr.MockTokenizerFactory" pattern="whitespace"/>+ </analyzer>+ <!-- only lower case at query time, so we can check the query analyzer is used -->+ <analyzer type="query">+ <tokenizer class="solr.MockTokenizerFactory" pattern="whitespace"/>+ <filter class="solr.LowerCaseFilterFactory"/>+ </analyzer>+ </fieldtype></types><fields>@@ -45,6 +57,7 @@<field name="text0" type="text" indexed="true" stored="true"/><field name="text1" type="text" indexed="true" stored="true"/><field name="text-keyword0" type="text-keyword" indexed="true" stored="true"/>+ <field name="text-query0" type="text-query" indexed="true" stored="true"/></fields><defaultSearchField>text0</defaultSearchField>diff --git a/solr/core/src/test/org/apache/solr/search/TestSimpleQParserPlugin.java b/solr/core/src/test/org/apache/solr/search/TestSimpleQParserPlugin.javaindex 3a2094e9391..4e62e6e0c3f 100644--- a/solr/core/src/test/org/apache/solr/search/TestSimpleQParserPlugin.java+++ b/solr/core/src/test/org/apache/solr/search/TestSimpleQParserPlugin.java@@ -49,6 +49,8 @@ public class TestSimpleQParserPlugin extends SolrTestCaseJ4 {assertU(adoc("id", "55", "text0", "whitespace", "text1", "whitespace", "text-keyword0", " "));assertU(adoc("id", "56", "text0", "whitespace", "text1", "whitespace", "text-keyword0", "\n"));assertU(adoc("id", "57", "text0", "foobar", "text1", "foo bar", "text-keyword0", "fb"));+ assertU(adoc("id", "58", "text-query0", "HELLO"));+ assertU(adoc("id", "59", "text-query0", "hello"));assertU(commit());}@@ -217,4 +219,10 @@ public class TestSimpleQParserPlugin extends SolrTestCaseJ4 {assertJQ(req("defType", "simple", "qf", "text0", "q", "FOO*"), "/response/numFound==1");assertJQ(req("defType", "simple", "qf", "text0", "q", "BAR*"), "/response/numFound==0");}++ public void testQueryAnalyzerIsUsed() throws Exception {+ // this should only match one doc, which was lower cased before being added+ assertJQ(req("defType", "simple", "qf", "text-query0", "q", "HELLO"),+ "/response/numFound==1");+ }}