如何将EdgeNGramTokenFilter添加到Compass查询?

时间:2009-07-29 14:00:23

标签: lucene compass-lucene

我正在使用指南针构建一些自动完成功能,我需要在指南针查询中添加 EdgeNGramTokenFilter ,但我看不出如何添加它。

这可能吗?

1 个答案:

答案 0 :(得分:0)

我设法添加了EdgeNGramTokenFilter过滤器,方法是在compass.config.xml标记中添加以下行,在<searchEngine>文件中添加对其的引用,从而添加<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 {
    }

}

这是班级:

{{1}}