Analyzer(分析器)
https://cwiki.apache.org/confluence/display/solr/Understanding+Analyzers,+Tokenizers,+and+Filters
分词器就是将句子分成单个的词,过滤器就是对分词的结果进行筛选,例如中文中将“的”“呀”这些对句子主体意思影响不大的词删除,英语中类似的就是"is","a"等等。
分析器包括两个部分:tokenizer(分词器)和filter(分词过滤器,它们将按照所列的顺序发生作用)。for example:
<fieldType name="text_ik_analysis" class="solr.TextField" sortMissingLast="true" omitNorms="true" autoGeneratePhraseQueries="false">
<analyzer type="index">
<tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true"/>
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true" />
<filter class="solr.LengthFilterFactory" min="2" max="20" />
<filter class="solr.RemoveDuplicatesTokenFilterFactory" />
</analyzer>
<analyzer type="query">
<tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true"/>
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true" />
<filter class="solr.LengthFilterFactory" min="2" max="20" />
<filter class="solr.RemoveDuplicatesTokenFilterFactory" />
</analyzer>
</fieldType>
Tokenizer(分词器)
常见的分词器有:
- KeywordTokenizerFactory:不管什么内容,整句当成一个关键字
- LetterTokenizerFactory:根据字母来分词,抛弃非字母的部分,例如:"I can't" ==> "I", "can", "t"
- WhitespaceTokenizerFactory:根据空格来分词,例如:"I do" ==> "I", "do"
- IKTokenizerFactory:IK分词器
Filter(过滤器)
常见的过滤器:
- LowerCaseFilterFactory:将大写字母转换成小写,不处理非字母部分
- SynonymFilterFactory:同义词
- LengthFilterFactory: 限定字符长度
- RemoveDuplicatesTokenFilterFactory:移除重复文本