你們知道因爲lucene和solr在最新版本在分詞方面改動比較大,在solr4.x上使用IK分詞,而且設置粗細力度,安裝官方的說法是這樣設置的:java
結果發現建索引和查詢時候的分詞力度是同樣的,默認是安裝細力度分詞,解決方案以下:apache
package org.apache.solr.analysis;ide
import java.io.Reader;函數
import java.util.Map;this
import org.apache.lucene.analysis.Tokenizer;spa
import org.apache.lucene.analysis.util.TokenizerFactory;.net
import org.apache.lucene.util.AttributeSource.AttributeFactory;索引
import org.wltea.analyzer.lucene.IKTokenizer;get
/**input
* 解決IK Analyzer 2012FF_hf1 在solr4.x應用時,配置useSmart失效的問題
*
* @author lqin
* @date 2013-12-24
* @email qin.liang@sinovatio.com
* @version 1.0
*
*/
public class IKAnalyzerSolrTokenizerFactory extends TokenizerFactory {
/**
* 構造函數,從參數裏面讀取配置
* @param args
*/
public IKAnalyzerSolrTokenizerFactory(Map<String, String> args)
{
super(args);
assureMatchVersion();
// 設置分詞力度,useSmart=true粗力度,useSmart=false細力度
this.setUseSmart("true".equals(args.get("useSmart")));
}
private boolean useSmart;
public boolean useSmart()
{
return useSmart;
}
public void setUseSmart(boolean useSmart)
{
this.useSmart = useSmart;
}
public void init(Map<String, String> args) {
this.useSmart = "true".equals(args.get("useSmart")) ;
}
@Override
public Tokenizer create(AttributeFactory factory, Reader input)
{
Tokenizer _IKTokenizer = new IKTokenizer(input , this.useSmart);
return _IKTokenizer;
}
}
修改配置: