You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rj...@apache.org on 2014/04/26 00:38:56 UTC

svn commit: r1590176 - in /lucene/dev/branches/branch_4x/solr/core: ./ src/java/org/apache/solr/search/SimpleQParserPlugin.java src/test-files/solr/collection1/conf/schema-simpleqpplugin.xml src/test/org/apache/solr/search/TestSimpleQParserPlugin.java

Author: rjernst
Date: Fri Apr 25 22:38:55 2014
New Revision: 1590176

URL: http://svn.apache.org/r1590176
Log:
SOLR-6017: Fix SimpleQParser to use query analyzer instead of index analyzer

Modified:
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/SimpleQParserPlugin.java
    lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/schema-simpleqpplugin.xml
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/search/TestSimpleQParserPlugin.java

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/SimpleQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/SimpleQParserPlugin.java?rev=1590176&r1=1590175&r2=1590176&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/SimpleQParserPlugin.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/search/SimpleQParserPlugin.java Fri Apr 25 22:38:55 2014
@@ -155,7 +155,7 @@ public class SimpleQParserPlugin extends
 
       // 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));

Modified: lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/schema-simpleqpplugin.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/schema-simpleqpplugin.xml?rev=1590176&r1=1590175&r2=1590176&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/schema-simpleqpplugin.xml (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/schema-simpleqpplugin.xml Fri Apr 25 22:38:55 2014
@@ -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>

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/search/TestSimpleQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/search/TestSimpleQParserPlugin.java?rev=1590176&r1=1590175&r2=1590176&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/search/TestSimpleQParserPlugin.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/search/TestSimpleQParserPlugin.java Fri Apr 25 22:38:55 2014
@@ -49,6 +49,8 @@ public class TestSimpleQParserPlugin ext
     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 ext
     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");
+  }
 }