官網:
https://code.google.com/archi...java
IK Analyzer 2012 FF版本 (即For 4.0),在API和功能上保持不變,只是讓其支持了Lucene4.0和Solr4.0,讓這部分的用戶能用起來。
若是你仍是Lucene3.2-3.6的用戶,那麼你只須要下載IK Analyzer 2012 U6版本。由於FF版本的API與3.x是不兼容的。
【IK Analyzer 安裝包包含】:web
它的安裝部署十分簡單 , 將 IKAnalyzer2012.jar 部署於項目的lib目錄中;IKAnalyzer.cfg.xml 與 stopword.dic 文件放置在 class 根目錄(對於 web 項目,一般是WEB-INF/classes 目錄,同 hibernate、log4j 等配置文件相同)下便可。apache
最新版本:IK Analyzer 2012vim
# 必定要下載FF版本,由於使用的是solr4.0以上版本 $ wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/ik-analyzer/IK%20Analyzer%202012FF_hf1.zip #解壓到IK2012目錄中,而且不覆蓋相同文件 $ unzip -n IKAnalyzer2012_u6.zip -d IK2012 #拷貝jar包到tomcat下solr的工程目錄中 $ cp IK2012/IKAnalyzer2012FF_u1.jar /opt/tomcat-8.5.31/webapps/solr/WEB-INF/lib/ #建立classes文件夾 $ mkdir /opt/tomcat-8.5.31/webapps/solr/WEB-INF/classes # 拷貝IKAnalyzer.cfg.xml和stopword.dic到classes文件夾下 $ cp IKAnalyzer.cfg.xml /opt/tomcat-8.5.31/webapps/solr/WEB-INF/classes/ $ cp stopword.dic /opt/tomcat-8.5.31/webapps/solr/WEB-INF/classes/
修改solr core中schema文件,默認位置:api
$ vim /opt/solr-4.10.3/example/solr/collection1/conf/schema.xml
添加以下配置:tomcat
<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>
同時,把須要分詞的字段,設置爲text_ikapp
<field name="id" type="int" indexed="true" stored="true" required="true" multiValued="false" /> <field name="name" type="text_ik" indexed="true" stored="true" required="true" multiValued="false" /> <field name="title" type="text_ik" indexed="true" stored="true" required="true" multiValued="false" /> <field name="category" type="int" indexed="true" stored="true" required="true" multiValued="false" /> <field name="content" type="text_ik" indexed="true" stored="true" required="true" multiValued="false" /> <field name="price" type="double" indexed="true" stored="true" required="true" multiValued="false" /> <field name="color" type="string" indexed="true" stored="true" required="true" multiValued="false" /> <field name="orderBy" type="int" indexed="true" stored="true" required="true" multiValued="false" /> <field name="updatetime" type="date" indexed="true" stored="true" required="true" multiValued="false" />
注意:若是以前已經建立了索引,須要將以前的索引刪掉,從新建立分詞後的索引。webapp
$ /opt/tomcat-8.5.31/bin/shutdown.sh $ /opt/tomcat-8.5.31/bin/startup.sh
1.默認是用的IKAnalyzer分詞器內置的詞典進行分詞的。咱們也能夠本身配置IKAnalyzer分詞器的擴展詞典測試
# 修改IKAnalyzer.cfg.xml文件 $ vim /opt/tomcat-8.5.31/webapps/solr/WEB-INF/classes/IKAnalyzer.cfg.xml
配置以下ui
<?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">ext.dic;</entry> <!--用戶能夠在這裏配置本身的擴展中止詞字典,表示不用哪些詞作索引--> <entry key="ext_stopwords">stopword.dic;</entry> </properties>
2.在classes下建立 ext.dic 來配置字典(每一行表示一個總體索引)
$ vim /opt/tomcat-8.5.31/webapps/solr/WEB-INF/classes/ext.dic
配置以下:
別看我亂我就是索引 哈哈哈 我是第三行
stopword.dic 和 ext.dic 的編碼方式爲UTF-8 無BOM的編碼方式。
3.重啓tomcat後測試