I have 2 lucene queries:
1)
Term term = new Term(Properties.LUCENE_APPARTMENT_ADDRESS,address);
Query termQuery = new TermQuery(term);
TopDocs topDocs = indexSearcher.search(termQuery, 20);
and 2)
QueryParser queryParser = new QueryParser(Version.LUCENE_36, Properties.LUCENE_APPARTMENT_ADDRESS, analyzer);
Query query = queryParser.parse(address);
ScoreDoc[] queryResults = indexSearcher.search(query, 20).scoreDocs;
Why the first one returns 1 result where the 2nd returns nothing? (the address is one word or more)
When you use
QueryParser
, it uses analyzer which does the same sequence of actions as when during the indexing (tokenization, lowercasing, stopwords, etc.).When you use raw
TermQuery
, you need to do all these steps yourself.I guess your analyzer does something special about
Properties.LUCENE_APPARTMENT_ADDRESS
and you are not when passing the address toTermQuery
hence the search results discrepancy.