ik扩展支持Solr配置

扩展ik原生代码:
public class IKAnalyzerTokenizerFactory extends TokenizerFactory
{
private boolean useSmart;

public boolean useSmart()
{
return this.useSmart;
}

public void setUseSmart(boolean useSmart) {
this.useSmart = useSmart;
}

public IKAnalyzerTokenizerFactory(Map<String, String> args) {
super(args);
assureMatchVersion();
setUseSmart(((String)args.get("useSmart")).toString().equals("true"));
}

public Tokenizer create(AttributeSource.AttributeFactory factory, Reader input)
{
Tokenizer _IKTokenizer = new IKTokenizer(input, this.useSmart);
return _IKTokenizer;
}
}

将ik重新打包,solr中配置信息如下:

<fieldType name="text_ik" class="solr.TextField">
	<analyzer type="index">
			<tokenizer class="org.wltea.analyzer.lucene.IKAnalyzerTokenizerFactory" useSmart="false"/>
			<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
			<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
		</analyzer> 
		<analyzer type="query">
			<tokenizer class="org.wltea.analyzer.lucene.IKAnalyzerTokenizerFactory" useSmart="true"/>
			<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
			<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
		</analyzer>
</fieldType>

  

posted @ 2015-06-29 17:55  李克华  阅读(957)  评论(0编辑  收藏  举报