You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by Wen Gao <sa...@gmail.com> on 2011/02/22 22:13:35 UTC

[Lucene.Net] how to make the search not case sensitive

Hi,

I am using lucene's standard analyser to search, however, the search result
is case sensitive. e.g, when i search for "database", "DATABASE" could not
return.

I could store the typed items as lowercase, and store the stored data as
lowercase as well, but in this case, the returned results would be lower
case, instead of the original form. e.g, the returned results would be
"database" instead of "DATABASE".

Any ideas?


Wen

Re: [Lucene.Net] how to make the search not case sensitive

Posted by Ayende Rahien <ay...@ayende.com>.
https://github.com/ravendb/ravendb/blob/master/Raven.Database/Indexing/LowerCaseAnalyzer.cs

On Tue, Feb 22, 2011 at 11:13 PM, Wen Gao <sa...@gmail.com> wrote:

> Hi,
>
> I am using lucene's standard analyser to search, however, the search result
> is case sensitive. e.g, when i search for "database", "DATABASE" could not
> return.
>
> I could store the typed items as lowercase, and store the stored data as
> lowercase as well, but in this case, the returned results would be lower
> case, instead of the original form. e.g, the returned results would be
> "database" instead of "DATABASE".
>
> Any ideas?
>
>
> Wen
>

Re: [Lucene.Net] how to make the search not case sensitive

Posted by Wen Gao <sa...@gmail.com>.
Thanks,

I solved this problem. I found that if what i typed is lowercase, the result
is not case senstive, e.g. if search for "database" it would return
"DATABASE", "database". However, if what i typed is uppercase, the result is
case sensitive, e.g. if search for "DATABASE", no results would return. So I
just transfer the input to lowercae using toLower(), and it works.
Is there anyting wrong with this?

Wen



2011/2/22 Peter Mateja <pe...@gmail.com>

> Wen,
> You need to make sure that you are using the same analyzer when both
> indexing and searching in a particular index field.  For instance, in your
> case, you need to ensure that the value "DATABASE" (in whatever field that
> is in) is indexed with the StandardAnalyzer.  Then, use the
> StandardAnalyzer
> to search that field.  This should find the match when you search for
> "database", "DATABASE", "Database", etc, and return the original value
> stored as "DATABASE".
>
> Of course, if you need case sensitivity, then you'd use the
> KeywordAnalyzer.
>
>
> If you've got a more complex index schema which requires different
> analyzers
> per field, then you'll need to look into using the PerFieldAnalyzerWrapper
> in order to correctly handle indexing and searching.
>
> Peter Mateja
> peter.mateja@gmail.com
>
>
>
> On Tue, Feb 22, 2011 at 3:13 PM, Wen Gao <sa...@gmail.com> wrote:
>
> > Hi,
> >
> > I am using lucene's standard analyser to search, however, the search
> result
> > is case sensitive. e.g, when i search for "database", "DATABASE" could
> not
> > return.
> >
> > I could store the typed items as lowercase, and store the stored data as
> > lowercase as well, but in this case, the returned results would be lower
> > case, instead of the original form. e.g, the returned results would be
> > "database" instead of "DATABASE".
> >
> > Any ideas?
> >
> >
> > Wen
> >
>

Re: [Lucene.Net] how to make the search not case sensitive

Posted by Peter Mateja <pe...@gmail.com>.
Wen,
You need to make sure that you are using the same analyzer when both
indexing and searching in a particular index field.  For instance, in your
case, you need to ensure that the value "DATABASE" (in whatever field that
is in) is indexed with the StandardAnalyzer.  Then, use the StandardAnalyzer
to search that field.  This should find the match when you search for
"database", "DATABASE", "Database", etc, and return the original value
stored as "DATABASE".

Of course, if you need case sensitivity, then you'd use the KeywordAnalyzer.


If you've got a more complex index schema which requires different analyzers
per field, then you'll need to look into using the PerFieldAnalyzerWrapper
in order to correctly handle indexing and searching.

Peter Mateja
peter.mateja@gmail.com



On Tue, Feb 22, 2011 at 3:13 PM, Wen Gao <sa...@gmail.com> wrote:

> Hi,
>
> I am using lucene's standard analyser to search, however, the search result
> is case sensitive. e.g, when i search for "database", "DATABASE" could not
> return.
>
> I could store the typed items as lowercase, and store the stored data as
> lowercase as well, but in this case, the returned results would be lower
> case, instead of the original form. e.g, the returned results would be
> "database" instead of "DATABASE".
>
> Any ideas?
>
>
> Wen
>