Solr搜索引擎 — 中文全拼简拼分词

2022-11-28 21:04:48 浏览数 (1)

搞定了中文分词下一个就是要来搞定拼音分词了,拼音分词有分为全拼和简拼

附上:

喵了个咪的博客:http://w-blog.cn

Solr官网:http://lucene.apache.org/solr/

PS:8.0.0版本已经发布,本文使用此时较为稳定的7.7.1版本

一,全拼分词

代码语言:javascript复制
> wget http://files.cnblogs.com/files/wander1129/pinyin.zip
> unzip pinyin.zip
> mv pinyin4j-2.5.0.jar  server/solr-webapp/webapp/WEB-INF/lib
> mv pinyinAnalyzer4.3.1.jar  server/solr-webapp/webapp/WEB-INF/lib
代码语言:javascript复制
> vim server/solr/new_core/conf/managed-schema

<fieldType name="text_pinyin" class="solr.TextField" positionIncrementGap="0">
    <analyzer type="index">
        <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory"/>
        <filter class="com.shentong.search.analyzers.PinyinTransformTokenFilterFactory" minTermLenght="2" />
        <filter class="com.shentong.search.analyzers.PinyinNGramTokenFilterFactory" minGram="1" maxGram="20" />
    </analyzer>
    <analyzer type="query">
        <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory"/>
        <filter class="com.shentong.search.analyzers.PinyinTransformTokenFilterFactory" minTermLenght="2" />
        <filter class="com.shentong.search.analyzers.PinyinNGramTokenFilterFactory" minGram="1" maxGram="20" />
    </analyzer>
</fieldType>

自制分词规则

代码语言:javascript复制
> webapps/solr/WEB-INF/classes/
> cd /usr/local/solr-7.7.1/server/solr-webapp/webapp/WEB-INF
> mkdir classes
代码语言:javascript复制
> wget http://pic.w-blog.cn/ikanalyzer-solr5.zip
> unzip ikanalyzer-solr5.zip 
> cd ikanalyzer-solr5/
> mv ext.dic ../server/solr-webapp/webapp/WEB-INF/classes/
> mv IKAnalyzer.cfg.xml ../server/solr-webapp/webapp/WEB-INF/classes/
> mv stopword.dic ../server/solr-webapp/webapp/WEB-INF/classes/
代码语言:javascript复制
> vim ext.dic

美团

简拼分词

代码语言:javascript复制
> wget http://pic.w-blog.cn/pinyinTokenFilter-1.1.0-RELEASE.jar
> mv pinyinTokenFilter-1.1.0-RELEASE.jar server/solr-webapp/webapp/WEB-INF/lib
代码语言:javascript复制
> vim server/solr/new_core/conf/managed-schema

<fieldType name="text_jian_pinyin" class="solr.TextField">  
    <analyzer type="index">  
        <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" isMaxWordLength="false" useSmart="false" />  
        <filter class="solr.LowerCaseFilterFactory" />  
        <filter class="top.pinyin.index.solr.PinyinTokenFilterFactory" pinyin="true" isFirstChar="true" minTermLenght="2" />  
        <filter class="com.shentong.search.analyzers.PinyinNGramTokenFilterFactory" minGram="2" maxGram="20" />  
    </analyzer>  
    <analyzer type="query">  
        <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" isMaxWordLength="false" useSmart="false" />  
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true" />  
        <filter class="solr.LowerCaseFilterFactory" />  
    </analyzer>  
</fieldType>  
代码语言:javascript复制
<field name="app_name" type="text_jian_pinyin" indexed="true" stored="true" />

0 人点赞