How to match exact text in Lucene search?

后端 未结 3 1551
执笔经年
执笔经年 2021-01-06 16:33

Im trying to match a text Config migration from ASA5505 8.2 to ASA5516 in column TITLE.

My program looks like this.



        
3条回答
  •  执念已碎
    2021-01-06 16:54

    PVR is correct, that using a phrase query is probably the right solution here, but they missed on how to use the PhraseQuery class. You are already using QueryParser though, so just use the query parser syntax by enclosing you search text in quotes:

    Query query = queryParser.parse("TITLE:\"Config migration from ASA5505 8.2 to ASA5516\"");
    

    Based on your update, you are using a different analyzer at index-time and query-time. SimpleAnalyzer and StandardAnalyzer don't do the same things. Unless you have a very good reason to do otherwise, you should analyze the same way when indexing and querying.

    So, change the analyzer in your indexing code to StandardAnalyzer (or vice-versa, use SimpleAnalyzer when querying), and you should see better results.

提交回复
热议问题