CentOS環境安裝Solr4.7.0+Apache Nutch 1.7 + IK2012中文分詞 筆記

系統環境基於Java,本文不做講解

Solr4.7下載地址:http://archive.apache.org/dist/lucene/solr/4.7.0/

Nutch1.7下載地址:http://archive.apache.org/dist/nutch/1.7/

下載二進制文件包:

wget http://archive.apache.org/dist/nutch/1.7/apache-nutch-1.7-bin.tar.gz

wget http://archive.apache.org/dist/lucene/solr/4.7.0/solr-4.7.0.tgz

文件解壓:

tar -zxvf apache-nutch-1.7-bin.tar.gz

tar -zxvfsolr-4.7.0.tgz

1.Nutch安裝以及配置

Nutch配置文件修改:

nano /apache-nutch-1.7/conf/nutch-site.xml

內容如下:

<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>

<property>

    <name>http.agent.name</name>

    <value>Friendly Crawler</value>

  </property>

  <property>

   <name>parser.skip.truncated</name>

    <value>false</value>

  </property>

</configuration>

創建抓取目錄:
mkdir urls
新增種子文件:
nano seed.txt
寫入 http://www.csdn.com

2.Solr安裝配置
cd solr-4.7.0/example
java -jar start.jar
驗證Solr登陸
http://127.0.0.1:8983/solr

3.集成Solr+Nutch
cd solr/collection1/conf
nano schema.xml
在<field>...</field>中新增以下字段:

<field name="host" type="string" stored="false" indexed="true"/>

<field name="digest" type="string" stored="true" indexed="false"/>

<field name="segment" type="string" stored="true" indexed="false"/>

<field name="boost" type="float" stored="true" indexed="false"/>

<field name="tstamp" type="date" stored="true" indexed="false"/>

<field name="anchor" type="string" stored="true" indexed="true" multiValued="true"/>

<field name="cache" type="string" stored="true" indexed="false"/>

注意修改title和content的stored屬性爲true,並修改multiValued屬性爲false,不然後面無法做高亮顯示。

4.Nutch抓取文件並索引到Solr

cd /apache-nutch-1.7

rm -rf crawl

bin/nutch crawl urls  -dir crawl -depth 2 -topN 5 -solr http://localhost:8983/solr/collection1

出現crawl finished: crawl表示抓取成功

5.IK2012分詞器安裝

下載IK2012分詞器,解壓後我們得到:


複製IKAnalyzer2012FF_u1.jar到 example/solr-webapp/webapp/WEB_INF/lib下

複製IKAnalyzer.cfg.xml,stopword.dic到 example/solr/collection1/conf 下

nano example/solr/collection/conf/schema.xml

在<types>...</types>新增如下代碼:

<!-- IK2012 -->

<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>

修改title,content,text的屬性type="text_ik",至此完成分詞功能。


相關注意事項:

1.若在公網上部署Solr,注意最後用iptables讓8983端口只能使用localhost訪問,因爲Solr登陸是不需要用戶名密碼的。

2.第一次我是使用最新版Solr6.0,但是IK2012中文分詞始終不能成功,應該是不支持,本文裏使用的版本是我親測可行的。


最後,有時間把SolrJ的使用再做相關紀錄。


注:

start.jar運行後關閉ssh窗口會導致Solr終止進程,需要kill掉重新使用java -jar start.jar運行,這裏附上Linux下運行終止jar腳本一個:

http://download.csdn.net/detail/nobmr/9525179



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章