1. 程式人生 > >solr增加中文分析器

solr增加中文分析器

PE 分享圖片 field textfield true word src enc oct

我的solr版本是5.3.0

1將jar包ik-analyzer-solr5-5.x.jar放入sor的web-inf的lib裏面

技術分享圖片

2 在web-inf下面新建classes目錄,再新增三個配置文件:

技術分享圖片

IKAnalyzer.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>

    <comment>IK Analyzer 擴展配置</
comment> <!-- 用戶可以在這裏配置自己的擴展字典 --> <entry key="ext_dict">mydict.dic</entry> <!-- 用戶可以在這裏配置自己的擴展停用詞字典 --> <entry key="ext_stopwords">ext_stopword.dic</entry> </properties>

mydict.dic

小米手機
華為手機
格力空調
小紅帽

ext_stopword.dic

媽的

3在新建的core的conf下面修改schema.xml

新增:

<fieldType name="text_ik" class="solr.TextField">   
               <analyzer type="index" isMaxWordLength="false" class="org.wltea.analyzer.lucene.IKAnalyzer"/>   
               <analyzer type="query" isMaxWordLength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"/>   
     </
fieldType> 修改: <field name="name" type="text_ik" indexed="true" stored="true" required="true" />

重啟後可實現

測試結果:

技術分享圖片

solr增加中文分析器