本文介绍了如何将EdgeNGramTokenFilter添加到指南针查询中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用指南针构建一些自动完成功能,我需要在指南针查询中添加 EdgeNGramTokenFilter ,但是我看不到如何添加它.
I am building some auto-complete functionality using compass and I need to add an EdgeNGramTokenFilter to the compass query but I cannot see how I can add it.
这可能吗?
推荐答案
我设法通过创建提供程序类来添加EdgeNGramTokenFilter
过滤器,该提供程序类在compass.config.xml
文件中添加了对它的引用,方法是在<searchEngine>
标签
I managed to add the EdgeNGramTokenFilter
filter by creating a provider class adding a reference to it in the compass.config.xml
file by adding the following line within the <searchEngine>
tags
<analyzerFilter name="lower" type="EdgeNGramTokenFilterProvider"/>
这是课程:
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.ngram.EdgeNGramTokenFilter;
import org.apache.lucene.analysis.ngram.EdgeNGramTokenFilter.Side;
import org.compass.core.CompassException;
import org.compass.core.config.CompassSettings;
import org.compass.core.lucene.engine.analyzer.LuceneAnalyzerTokenFilterProvider;
public class EdgeNGramTokenFilterProvider implements LuceneAnalyzerTokenFilterProvider {
public TokenStream createTokenFilter(TokenStream tokenStream) {
return new EdgeNGramTokenFilter(tokenStream, Side.FRONT, 1, 20);
}
public void configure(CompassSettings settings) throws CompassException {
}
}
这篇关于如何将EdgeNGramTokenFilter添加到指南针查询中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!