Ansj的使用和相關資料下載參考:http://iamyida.iteye.com/blog/2220833html
參考 http://www.cnblogs.com/luxh/p/5016894.html 配置和solr和tomcat的web
一、從http://iamyida.iteye.com/blog/2220833下載好Ansj須要的相關的資料,下面是已下載好的。apache
Ansj資料: http://pan.baidu.com/s/1kTLGp7Ljson
二、複製ansj相關文件到solr項目中tomcat
1)將ansj_seg-2.0.8.jar、nlp-lang-0.2.jar和solr-analyzer-ansj-5.1.0.jar放到solr項目中app
放置目錄:/luxh/solr/apache-tomcat-8.0.29/webapps/solr/WEB-INF/libwebapp
2)將library.properties、libary目錄和stopwords目錄放置到solr項目中測試
放置目錄:ui
[root@iZ23exixsjaZ classes]# pwd /luxh/solr/apache-tomcat-8.0.29/webapps/solr/WEB-INF/classes [root@iZ23exixsjaZ classes]# ls library library.properties log4j.properties stopwords [root@iZ23exixsjaZ classes]#
3)配置library.propertiesthis
按照本身的實際路徑配置。
[root@iZ23exixsjaZ classes]# vi library.properties #redress dic file path ambiguityLibrary=/luxh/solr/apache-tomcat-8.0.29/webapps/solr/WEB-INF/classes/library/ambiguity.dic #path of userLibrary this is default library userLibrary=/luxh/solr/apache-tomcat-8.0.29/webapps/solr/WEB-INF/classes/library #set real name isRealName=true
三、在solr_home下創建一個collection
1)建立一個collection叫collection1
[root@iZ23exixsjaZ solr_home]# pwd /luxh/solr/solr_home [root@iZ23exixsjaZ solr_home]# mkdir collection1
2)拷貝/solr-5.3.1/server/solr/configsets/basic_configs下的內容到新建的collection1中
[root@iZ23exixsjaZ basic_configs]# pwd /luxh/solr/solr-5.3.1/server/solr/configsets/basic_configs [root@iZ23exixsjaZ basic_configs]# cp -r ./* /luxh/solr/solr_home/collection1/
四、配置collection1中的schema.xml,加入ansj分詞配置
[root@iZ23exixsjaZ conf]# pwd /luxh/solr/solr_home/collection1/conf [root@iZ23exixsjaZ conf]# ls currency.xml lang protwords.txt _rest_managed.json schema.xml solrconfig.xml stopwords.txt synonyms.txt [root@iZ23exixsjaZ conf]# vi schema.xml
加入以下內容:
<fieldType name="text_ansj" class="solr.TextField"> <analyzer type="index"> <tokenizer class="org.apache.lucene.analysis.ansj.AnsjTokenizerFactory" query="false" pstemming="true" stopwordsDir="stopwords/stopwords.dic"/> </analyzer> <analyzer type="query"> <tokenizer class="org.apache.lucene.analysis.ansj.AnsjTokenizerFactory" query="true" pstemming="false"/> </analyzer> </fieldType>
五、啓動tomcat
[root@iZ23exixsjaZ apache-tomcat-8.0.29]# bin/startup.sh
六、經過 http://你的ip:8080/solr/admin.html Add Core
instanceDir指向剛纔建立的collection1
七、測試
1)英文
2)中文