package com.uas.search.analyzer;

import org.apache.lucene.analysis.Analyzer;

/**
 * 替代 {@link org.wltea.analyzer.lucene.IKAnalyzer} , 增加 loadExtDic 属性
 *
 * @author sunyj
 * @since 2017/11/21 16:46
 */
public final class IKAnalyzer extends Analyzer {

    /**
     * 是否以最大粒度进行分词
     */
    private boolean useSmart;

    /**
     * 是否加载自定义词典
     */
    private boolean loadExtDic;

    public IKAnalyzer() {
        this(false);
    }

    public IKAnalyzer(boolean useSmart) {
        this(useSmart, true);
    }

    public IKAnalyzer(boolean useSmart, boolean loadExtDic) {
        this.useSmart = useSmart;
        this.loadExtDic = loadExtDic;
    }

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

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

    public boolean loadExtDic() {
        return loadExtDic;
    }

    public void setLoadExtDic(boolean loadExtDic) {
        this.loadExtDic = loadExtDic;
    }

    protected TokenStreamComponents createComponents(String fieldName) {
        IKTokenizer _IKTokenizer = new IKTokenizer(this.useSmart(), this.loadExtDic());
        return new TokenStreamComponents(_IKTokenizer);
    }
}