If you are using a basic Lucene indexing strategy, you may do something like this:
|
|
In this situation, every field in each document will be analyzed using the StandardAnalyzer
.
The indexer is constrained to using a single analyzer.
In some situations, this may not meet your needs, as you may want to use different analyzers for different fields in a document.
How can we instruct the index writer to use different analyzers for different fields?
The PerFieldAnalyzerWrapper
does exactly this by letting you populate a Java Map
, which maps document fields to analyzers.
See the documentation here for an overview of how the PerFieldAnalyzerWrapper
works.
You can also use the same approach when building queries
|
|
From the docs:
In this example,
StandardAnalyzer
will be used for all fields except “firstname” and “lastname”, for whichKeywordAnalyzer
will be used.A
PerFieldAnalyzerWrapper
can be used like any other analyzer, for both indexing and query parsing.