lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steven Rowe <>
Subject Re: exact match ..
Date Mon, 20 Feb 2006 17:41:58 GMT
Mufaddal Khumri wrote:
> lets say i do this while indexing:
> doc.add(Field.Text("categoryNames", categoryNames));
> Now while searching categoryNames, I do a search for "digital cameras". 
> I only want to match the exact phrase digital cameras with documents who 
> have exactly the phrase "digital cameras" in the categoryNames field. I 
> do not want results that have "digital camera batteries" part of the 
> result.
> Whats the best way to accomplish this?

Hi Mufaddal,

One way to do this is to use the KeywordAnalyzer (in the Lucene 
Subversion trunk, but not in v1.4.3; will be in forthcoming v1.9) for 
the "categoryNames" field.  This analyzer does not tokenize field 
contents, so "digital cameras" would be a single token, and the only 
thing that would match it would be the exact same single token.  Be 
careful when you search to construct the search tokens similarly.

If you have other fields you want to search, and you want to tokenize 
their contents when you index them, you could use the 
PerFieldAnalyzerWrapper, so that the KeywordAnalyzer is only used for 
the "categoryNames" field.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message