java-user@lucene.apache.org
[Top] [All Lists]

RE: Lucene fields not analyzed

Subject: RE: Lucene fields not analyzed
From: "Uwe Schindler"
Date: Tue, 9 Feb 2010 08:35:46 +0100
QueryParser uses the given Analyzer when constructing they query, so it will 
never hit a NOT_ANALYZED term. In general, it is a bad idea to use QueryParser 
on fields that are not analyzed. There are two possibilities to solve the 
problem:

- Instantiate the query to match the not-analyzed (but indexed field) directly 
as a TermQuery.
- Use a PerFieldAnalyzerWrapper and choose a specific analyzer for this field 
that does not touch your names (e.g. KeywordAnalyzer). Use this wrapped 
analyzer for the both searching an indexing (and use Field.Index.ANALYZED!).

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@xxxxxxxxxxx

> -----Original Message-----
> From: Rohit Banga [mailto:iamrohitbanga@xxxxxxxxx]
> Sent: Tuesday, February 09, 2010 8:27 AM
> To: java-user@xxxxxxxxxxxxxxxxx
> Subject: Lucene fields not analyzed
> 
> Hello
> 
> i have a field that stores names of people. i have used the
> NOT_ANALYZED
> parameter to index the names.
> 
> this is what happens during indexing
> 
>     doc.add(new Field("name", "\"" + name + "\"", Field.Store.YES,
> Field.Index.NOT_ANALYZED));
> 
> 
> 
> when i search it, i create a query parser using standardanalyzer and
> append
> ~0.5 to the search query.
> 
> the problem is that if the indexed name is "Mr. Kumar", my search does
> not
> work for "Mr. Kumar" while it does work for "Mr.Kumar" (without the
> space).
> 
> // searching code
>         File index_directory = new File(INDEX_DIR_PATH);
>         IndexReader reader =
> IndexReader.open(FSDirectory.open(index_directory), true);
>         Searcher searcher = new IndexSearcher(reader);
> 
>         Analyzer analyzer = new
> StandardAnalyzer(Version.LUCENE_CURRENT);
> 
>         QueryParser parser = new QueryParser(Version.LUCENE_CURRENT,
> "name",
> analyzer);
> 
>         Query query;
>         query = parser.parse(text + "~0.5");
> 
> how to make it work?
> 
> Rohit Banga


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@xxxxxxxxxxxxxxxxx
For additional commands, e-mail: java-user-help@xxxxxxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>