I'm currently unsure about the behavior of the QueryParser vs. TermQuery in Lucene; I'm using Lucene 3.6.
In my example I'm try the following examples over the same index, where the field in question is set at Field.Store.NO
and Field.Index.NOT_ANALYZED_NO_NORMS
.
Query q1 = new TermQuery(new Term("names", "test three"));
QueryParser q2p = new QueryParser(GenericIndexer.LUCENE_VERSION, "names", someAnalyzer);
Query q2 = q2p.parse("names:test three");
Query q3 = q2p.parse("names:\"test three\"");
In both cases q2
and q3
I'm unable to reproduce the same syntax as q1
; by printing out the queries, I can see that:
- q1 =
names:test three
- q2 =
names:test names:three
- q3 =
names:"test three"
Due to this difference queries q2
and q3
return no results, while query q1
return the expected result.
Question: Is there a way to have the query parser to reproduce the same query as the TermQuery or am I missing some fundamental Lucene's notion here?
Note: for the QueryParser, the analyzer is the same one used during indexing, although I'm not sure how relevant this information is.