
2、良好的程序设计,一定是至少将这3个模块分开,其实还要划分出更多的模块。我上个月刚用nutch做了一个网络爬虫,效果还不错。
3、像你的这种情况,要分 步走:
一,把nutch的源码看个大概,至少要把整个的数据流搞清。
二,将数据流截断,让其流向自己所要处理的模块。
试试看吧。
前提条件:配置ant
1. 下载nutch(例如:我的是apache-nutch-2.2.1-src.tar.gz)
解压,重命名nutch文件夹(命名为nutch),然后移动文件夹到/home文件夹下
2. 编译nutch
cd nutch
ant
2.1 你可能会遇到这种错误:
Trying to override old definition of task javac
[taskdef] Could not load definitions from resource org/sonar/ant/antlib.xml. It could not be found.
ivy-probe-antlib:
ivy-download:
[taskdef] Could not load definitions from resource org/sonar/ant/antlib.xml. It could not be found.
原因:缺少相应的jar文件
解决方法:
(1)下载sonar-ant-task-2.1.jar,并放到nutch文件夹目录下
(2)修改build.xml文件,从而引入这个新的jar
<!-- Define the Sonar task if this hasn't been done in a common script -->
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="${ant.library.dir}" />
<classpath path="${mysql.library.dir}" />
<classpath><fileset dir="." includes="sonar*.jar" /></classpath>
</taskdef>
//找到相应的地方,增加多出的内容即可。
2.2 编译时间过长
nutch使用ivy进行构建,故编译时间长。如果时间过长,可使用该办法解决。
修改该文件:ivy/ivysettings.xml
http://mirrors.ibiblio.org/maven2/
替换
http://repo1.maven.org/maven2/
2.3 编译之后的目录:
3. 修改nutch配置文件
Nutch2.x版本存储采用Gora访问Cassandra、HBase、Accumulo、Avro等,需要在该文件中制定Gora属性。
3.1修改 conf/nutch-site.xml
<property>
<name>storage.data.store.class</name>
<value>org.apache.gora.hbase.store.HBaseStore</value>
<description>Default class for storing data</description>
</property>
3.2 修改 ivy/ivy.xml
<!-- Uncomment this to use HBase as Gora backend. -->
<dependency org="org.apache.gora" name="gora-hbase" rev="0.3" conf="*->default" />
3.3 修改 conf/gora.properties
gora.datastore.default=org.apache.gora.hbase.store.HBaseStore
配置nutch
(nutch文件夹已在/home目录下)
1. 修改系统环境变量
sudo gedit /etc/profile
//增加
#set nutch
export PATH=/home/nutch/runtime/local/bin:$PATH
2. 测试(nutch/runtime/local/bin中./nutch & ./crawl)
一个是schema.xml,在其中的fields标签下加入如下代码:Java代码
<field name="test1" type="date" stored="true" indexed="true"/>
ltfield name="test2" type="string" stored="true" indexed="true"/>
其中的stored表示这个字段的值要存储在lucene的索引中
其中的indexed表示这个字段的值是不是要进行分词查询
还有一个是solrindex-mapping.xml文件,这个文件的作用是把索引过滤器中生成的字段名与schema.xml中的做一个对应关系,要在其fields标签中加入如下代码:
Java代码
<field dest="test1" source="fetchTime"/>
<field dest="test2" source="metadata"/>
这样自定义索引过滤插件就算完成了,记得这里的schema.xml文件是在solr/conf目录下的,修改以后要重启一下,不知道solr支不支持修改了配置文件后不重启就可以生效。
bin/nutch solrindex http://localhost:8080/solr/ crawldb -linkdb crawldb/linkdb crawldb/segments/*
solr的索引文件在solr/data/index中,你可以用luke这个工具加开其索引文件,看一下其中的一些元信息,这个时候你就应该可以看到test1与test2这两个字段了.
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)