mirror of https://github.com/apache/lucene.git
SOLR-6017: Fix SimpleQParser to use query analyzer instead of index analyzer
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1590166 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
033f80fd7a
commit
0dea18dd2e
|
@ -121,6 +121,9 @@ Bug Fixes
|
|||
rollback as well as how SolrIndexWriter manages it's ref counted directory
|
||||
instance. (Mark Miller, Gregory Chanan)
|
||||
|
||||
* SOLR-6017: Fix SimpleQParser to use query analyzer instead of index analyzer.
|
||||
(Ryan Ernst)
|
||||
|
||||
Other Changes
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue