How do I add an EdgeNGramTokenFilter to a Compass Query?

↘锁芯ラ 提交于 2019-12-13 04:22:07

问题


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.

Is this possible?


回答1:


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"/>

Here is the class:

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 {
    }

}


来源:https://stackoverflow.com/questions/1200474/how-do-i-add-an-edgengramtokenfilter-to-a-compass-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!