PerFieldAnalyzerWrapper 可以使得不同的field使用不同的analyzer进行搜索
么如何针对特定Field使用不同分析器呢,lucene包里面有个PerFieldAnalyzerWrapper类,解决了这一问题,这是lucene的文档里面的一段话: lucene自带文档 写道Example usage:
PerFieldAnalyzerWrapper aWrapper = new PerFieldAnalyzerWrapper(new StandardAnalyzer());
aWrapper.addAnalyzer("firstname", new KeywordAnalyzer());
aWrapper.addAnalyzer("lastname", new KeywordAnalyzer());
In this example, StandardAnalyzer will be used for all fields except "firstname" and "lastname", for which KeywordAnalyzer will be used.
A PerFieldAnalyzerWrapper can be used like any other analyzer, for both indexing and query parsing.
PerFieldAnalyzerWrapper aWrapper = new PerFieldAnalyzerWrapper(new StandardAnalyzer());
aWrapper.addAnalyzer("firstname", new KeywordAnalyzer());
aWrapper.addAnalyzer("lastname", new KeywordAnalyzer());
In this example, StandardAnalyzer will be used for all fields except "firstname" and "lastname", for which KeywordAnalyzer will be used.
A PerFieldAnalyzerWrapper can be used like any other analyzer, for both indexing and query parsing.
PreFieldAnalyzerWrapper类的构造函数中需要一个默认的分析器作为参数。为了给不同的Field指定不同的analyzer,就需要调用该类的addAnalyzer()方法。上面的E文相信大家都能看懂的,