擴展ik原生代碼:
public class IKAnalyzerTokenizerFactory extends TokenizerFactory
{
private boolean useSmart;java
public boolean useSmart()
{
return this.useSmart;
}this
public void setUseSmart(boolean useSmart) {
this.useSmart = useSmart;
}blog
public IKAnalyzerTokenizerFactory(Map<String, String> args) {
super(args);
assureMatchVersion();
setUseSmart(((String)args.get("useSmart")).toString().equals("true"));
}token
public Tokenizer create(AttributeSource.AttributeFactory factory, Reader input)
{
Tokenizer _IKTokenizer = new IKTokenizer(input, this.useSmart);
return _IKTokenizer;
}
}get
將ik從新打包,solr中配置信息以下:input
<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>