Lucene 4.6 入门

范例:http://blog.csdn.net/jyf211314/article/details/17503997

 

 

同义词词典:

import java.io.IOException;
    import java.io.Reader;
    import java.util.HashMap;
    import java.util.Map;
    import org.apache.lucene.analysis.Analyzer;
    import org.apache.lucene.analysis.Tokenizer;
    import org.apache.lucene.analysis.synonym.SynonymFilterFactory;
    import org.apache.solr.core.SolrResourceLoader;
    import org.wltea.analyzer.lucene.IKTokenizer;

public class IKSynonymsAnalyzer extends Analyzer {
    
    protected TokenStreamComponents createComponents(String arg0, Reader arg1) {
    Tokenizer token=new IKTokenizer(arg1, true);//开启智能切词
    Map paramsMap=new HashMap();
    paramsMap.put("luceneMatchVersion", "LUCENE_43");
    paramsMap.put("synonyms", "data/synonyms.txt");
    SynonymFilterFactory factory=new SynonymFilterFactory(paramsMap);
    SolrResourceLoader loader= new SolrResourceLoader("");
    try {
    factory.inform(loader);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return new TokenStreamComponents(token, factory.create(token));
    }
    }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。