You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Joe Attardi <ja...@gmail.com> on 2007/07/30 15:56:41 UTC

Indexing/Analyzer question - case-insensitive "contains" search

Hi everyone,

I told you I'd be back with more questions!  :-)
Here is my situation. In my application, the field to be searched is
selected via a drop-down box. I want my searches to basically be "contains"
searches - I take what the user typed in, put a wildcard character at the
beginning and end, and put that in a WildcardQuery with the selected field.
In simple cases, this works great.

But, the StandardAnalyzer and SimpleAnalyzer is removing some characters I
need. For example, one of my objects has a name of "Joe's Devices". If I
search for "Joe's", it doesn't work, because the apostrophe is stripped out.
I tried using the KeywordAnalyzer, which keeps the string intact, but then
won't my searches be case-sensitive? This is easy to fix of course by
calling toLowerCase() on the text when it is indexed, but then later when
retrieved from the index to be displayed in the search results, "Joe's
Devices" is displayed as "joe's devices". Is there anything I can do here
short of putting two copies of the name in the document - one indexed/not
stored ("joe's devices"), and one stored/not indexed("Joe's Devices") ? Or
can I accomplish this case-insensitive "contains" search some other way -
would I have to write a custom Analyzer, or something?

Thanks in advance!

-- 
Joe Attardi
jattardi@gmail.com
http://thinksincode.blogspot.com/