tags:

views:

50

answers:

1

In Lucene, using a Standard Analyzer, I want to make fields with space searchable. I set Field.Index.NOT_ANALYZED and Field.Store.YES using the StandardAnalyzer When I look at my index in LUKE, the fields are as I expected, a field and a value such as: location -> 'New York'. Here I found that I can use the KeywordAnalyzer to find this value using the query: location:"New York".

But I want to add another term to the query. Let's say a have a body field which contains the normalized and analyzed terms created by the StandardAnalyzer. Using the KeywordAnalyzer for this field I get different results than when I use the StandardAnalyzer.

How do I combine two Analyzers in one QueryParser, where one Analyzer works for some fields and another one for another fields. I though of creating my own Analyzer which could behave differently depending on the field, but I have no clue how to do it.

+1  A: 

PerFieldAnalyzerWrapper lets you apply different analyzers for different fields.

Kai Chan
This was the solution we used for the exact same problem. I recommend creating a public getAnalyzer method that can be used by both the Searcher and the Writer.
Snekse