Reputation: 1280
This has been baffling me recently, and I can't seem to find a suitable explanation anywhere.
If I run a query built using the Query API, it works perfectly well.
TermQuery sourceQuery = new TermQuery(new Term("source", "CNN"));
Running results = searcher.search(sourceQuery, 30)
and checking results.totalHits
shows me a value of 159.
However, in the same program, I set up a QueryParser
(my default field is called text
):
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_35);
QueryParser parser = new QueryParser(Version.LUCENE_35,
"text", analyzer);
and input the command-line query
source:CNN
I get no results. Running this command on Luke does give me a result. Does anyone have an idea what's happening?
Upvotes: 1
Views: 1210
Reputation: 2473
You probably have used the wrong Analyzer for the QueryParser object. Note that:
I guess your terms are in upper case (or turned into upper case) when you index the text. That explains why approach 1 and 3 work, but 2 does not because the cases do not match. In general, it's a good idea to use the same Analyzer when indexing and when searching, or at least pay attention to the case.
Upvotes: 5