Ansj的使用和相關資料下載下傳參考:http://iamyida.iteye.com/blog/2220833
參考 http://www.cnblogs.com/luxh/p/5016894.html 配置和solr和tomcat的
1、從http://iamyida.iteye.com/blog/2220833下載下傳好Ansj需要的相關的資料,下面是已下載下傳好的。
Ansj資料: http://pan.baidu.com/s/1kTLGp7L
2、複制ansj相關檔案到solr項目中
1)将ansj_seg-2.0.8.jar、nlp-lang-0.2.jar和solr-analyzer-ansj-5.1.0.jar放到solr項目中
放置目錄:/luxh/solr/apache-tomcat-8.0.29/webapps/solr/WEB-INF/lib
2)将library.properties、libary目錄和stopwords目錄放置到solr項目中
放置目錄:
[[email protected] classes]# pwd
/luxh/solr/apache-tomcat-8.0.29/webapps/solr/WEB-INF/classes
[[email protected] classes]# ls
library library.properties log4j.properties stopwords
[[email protected] classes]#
3)配置library.properties
按照自己的實際路徑配置。
[[email protected] 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
3、在solr_home下建立一個collection
1)建立一個collection叫collection1
[[email protected] solr_home]# pwd
/luxh/solr/solr_home
[[email protected] solr_home]# mkdir collection1
2)拷貝/solr-5.3.1/server/solr/configsets/basic_configs下的内容到建立的collection1中
[[email protected] basic_configs]# pwd
/luxh/solr/solr-5.3.1/server/solr/configsets/basic_configs
[[email protected] basic_configs]# cp -r ./* /luxh/solr/solr_home/collection1/
4、配置collection1中的schema.xml,加入ansj分詞配置
[[email protected] conf]# pwd
/luxh/solr/solr_home/collection1/conf
[[email protected] conf]# ls
currency.xml lang protwords.txt _rest_managed.json schema.xml solrconfig.xml stopwords.txt synonyms.txt
[[email protected] 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>
5、啟動tomcat
6、通過 http://你的ip:8080/solr/admin.html Add Core
instanceDir指向剛才建立的collection1
7、測試
1)英文
2)中文