码迷,mamicode.com
首页 > Web开发 > 详细

Lucene 4.6 入门

时间:2014-10-22 06:17:13      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:Lucene   blog   http   io   ar   java   for   sp   div   

范例: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));
    }
    }

 

Lucene 4.6 入门

标签:Lucene   blog   http   io   ar   java   for   sp   div   

原文地址:http://www.cnblogs.com/limpek/p/4042120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!