系统环境基于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>
<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