Finding exact match using Lucene search API

Steve Chapman picture Steve Chapman · Jun 10, 2009 · Viewed 10.6k times · Source

I'm working on a company search API using Lucene. My Lucene company index has got 2 companies: 1.Abigail Adams National Bancorp, Inc. 2.National Bancorp

If the user types in National Bancorp, then only company # 2(ie. National Bancorp) should be returned and not #1.....ie. only exact matches should be returned. How do I achieve this functionality?

Thanks for reading.

Answer

Shashikant Kore picture Shashikant Kore · Jun 11, 2009

You can use KeywordAnalyzer to index and search on this field. Keyword Analyzer will generate only one token for the entire string.