nutch+solr 单机全文检索服务的搭建

缘起

最近研究数字货币时,需要大量网上舆情的数据。分析了Google, Bing, Yahoo, Baidu, SOGOU, 360等搜索引擎后,种种原因(将另文述说,如果需要可跟帖),还是自己建一个比较合适。多年前曾经使用过Nutch+Solr,现使用最新推荐组合版本,再搭建一次,过程留存如下:

环境:

Centos 7  (4核,8G,300G),Nutch 1.14 + Solr 6.6.0 ( Nutch 推荐组合)

步骤

1,先找到官方文档

最为详实,权威。 https://wiki.apache.org/nutch/NutchTutorial

2,下载 Nutch,Solr,解压之

3,修改爬虫名称

行走网络江湖,需要留个名声,在 apache-nutch-1.14/conf/nutch-site.xml 文件中,添加:

<property>
 <name>http.agent.name</name>
 <value>eCoin Research Spider</value>
</property>

4,创建 URL seed list

在 apache-nutch-1.14/urls/seed.txt 文件(可能需要创建目录)中,添加经常访问的,有实质内容的地址,例如:

http://www.8btc.com/
http://www.bishijie.com/
http://www.jinse.com/
https://support.okex.com/hc

5,限制访问的URL

其实只需要爬那些自己认为还不错的网站,好的网站不多,有用的信息也没有想象那么多。

在 apache-nutch-1.14/conf/regex-urlfilter.txt 文件中,添加:

+^https?://([a-z0-9-]+\.)*8btc\.com/
+^https?://([a-z0-9-]+\.)*bishijie\.com/
+^https?://([a-z0-9-]+\.)*jinse\.com/
+^https?://([a-z0-9-]+\.)*okex\.com/

6,加入时间索引字段

这是一个重点,时间信息很重要,这里采用建立索引的时间作为url的一个属性。从html中解析出时间,不大可靠。相比之下,这个时间稍准一些。

修改文件 apache-nutch-1.14/conf/schema.xml,如下

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

7,配置集成Solr

完全按照上面官方文档,摘录如下:

  • create resources for a new nutch solr core cp -r ${APACHE_SOLR_HOME}/server/solr/configsets/basic_configs ${APACHE_SOLR_HOME}/server/solr/configsets/nutch
  • copy the nutch schema.xml into the conf directory cp ${NUTCH_RUNTIME_HOME}/conf/schema.xml ${APACHE_SOLR_HOME}/server/solr/configsets/nutch/conf
  • make sure that there is no managed-schema "in the way": rm ${APACHE_SOLR_HOME}/server/solr/configsets/nutch/conf/managed-schema
  • start the solr server ${APACHE_SOLR_HOME}/bin/solr start
  • create the nutch core ${APACHE_SOLR_HOME}/bin/solr create -c ecoins -d server/solr/configsets/nutch/conf/
  • add the core name to the Solr server URL: -Dsolr.server.url=http://localhost:8983/solr/nutch

8, 可以试试了

在目录 apache-nutch-1.14 下,运行:

./bin/crawl -i -D "solr.server.url=http://localhost:8983/solr/ecoins" -s urls/ ecoinscrawl/  2

在 浏览器中访问 http://localhost:8983/solr ,可看到Solr的页面

问题1 使用Boilerpipe提取正文

默认时提取所有 HTML,需要去除菜单,广告等内容,故采用久仰的Boilerpipe, Nutch已经集成。需要如下配置:

在 apache-nutch-1.14/conf/nutch-sites.xml 文件中,添加

<property>
  <name>tika.extractor</name>
  <value>boilerpipe</value>
  <description>
  Which text extraction algorithm to use. Valid values are: boilerpipe or none.
  </description>
</property>

<property>
  <name>tika.extractor.boilerpipe.algorithm</name>
  <value>ArticleExtractor</value>
  <description>
  Which Boilerpipe algorithm to use. Valid values are: DefaultExtractor, ArticleExtractor
  or CanolaExtractor.
  </description>
</property>

问题2,分词

这个问题一直迷惑不解,个人认为按字分词是最好的,现在可以记录字的位置,非常便于做整句查询,这对查询领导讲话太重要了。默认配置就很好,空间也不是问题。所以没有对分词做额外配置。

欢迎大家指教,一同探讨。

猜你喜欢

转载自my.oschina.net/hyperichq/blog/1647366
今日推荐