Storing words with apostrophe in Lucene index

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Storing words with apostrophe in Lucene index

chadg
Hi,

I've a company field in Lucene Index. One of the company names indexed is : Moody's

When user types in any of the following keywords,I want this company to come up in search results. 1.Moo 2.Mood 3.Moodys 4.Moody's

How should I store this index in Lucene and what type of Lucene Query should I use to get this behaviour?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Storing words with apostrophe in Lucene index

iorixxx

> When user types in any of the following keywords,I want
> this company to come up in search results.
> 1.Moo 2.Mood 3.Moodys 4.Moody's
>
> How should I store this index in Lucene and what type of
> Lucene Query should I use to get this behavior?

If you want to use a built-in analyzer WhitespaceAnalyzer with PrefixQuery are enough to get this behavior.
Just add an star ( * ) end of the user query:

Moo*
Mood*
Moodys*
Moody's*

Note that this option will be case sensitive.

To perform case insensitive search either you can add LowerCaseFilter to  WhitespaceAnalyzer, or remove StandardFilter from StandardAnalyzer.
May be it is a good idea to setLowercaseExpandedTerms of your QueryParser to true, since wildcard query words are not analyzed.

If you don't want to use wildcard searches, then EdgeNGramTokenFilter can help you.



     

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]