views:

1245

answers:

3

Hi,

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.

+2  A: 

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

Shashikant Kore
Can you please answer this one?http://stackoverflow.com/questions/899542/problem-using-same-instance-of-indexsearcher-for-multiple-requests
Steve Chapman
A: 

You may want to reconsider your requirements, depending on whether or not I correctly understood your question. Please bare with me if I did misunderstand you.

Just a little food for thought:

  • If you only want exact matches returned, then why are you searching in the first place?

  • Are you sure that the user expects exact matches? I typically search assuming that the search engine will accommodate missing words.

  • Suppose the user searched for National Bank but National Bank was no longer in your index. Would you still want Abigail Adams National Bancorp, Inc to be excluded from the results simply because it was not an exact match?

In light of this, I would suggest you continue to present all possible matches (exact or not) to the user and let them decide for themselves which is most appropriate for them. I say this simply because you may not be thinking the same way as all of your users. Lucene will take care of making sure the closest matches rank highest in the results, helping them make quicker choices.

Adam Paynter
A: 

I have a question regarding Lucene scoring. I have two documents in the index, one contains "my name" and the other contains "my first name". When I search for the keyword "my name", the second document is listed above the first one. What I want is that if the document contains exact keyword I typed, it should be listed first, then the other. Can anyone help me how to do this. Thanks.

Truong Do
Please make this a new question. Then we could answer it.
Yuval F