由于信息所有很大的容量、带宽资源闲置,要将其利用起来,在网络上收集与特定领域相关的资料,这就需要使用到网罗爬虫方面的技术了。在经过一段时间的调研之后,发现Apache已经有一个开源的搜索引擎---Nutch了,对其特定需求地改造将为我们节约了很多的时间与精力。
    在java.net社区中有两篇文章对Nutch进行了详尽的介绍。
Introduction to Nutch, Part 1: Crawling
Introduction to Nutch, Part 2: Searching
如有需求请好好研究它
    在nutch0.8的源代码org.apache.nutch.crawl包中包含了nutch爬虫最开始调用的类---cralw,在其main函数中,分别调用了
Injector(job).inject(crawlDb, rootUrlDir);
Generator(job).generate(crawlDb, segments, -1, topN, System.currentTimeMillis());
Fetcher(job).fetch(segment, threads, Fetcher.isParsing(job));
ParseSegment(job).parse(segment);
CrawlDb(job).update(crawlDb, segment);
LinkDb(job).invert(linkDb, segments);
Indexer(job).index(indexes, crawlDb, linkDb, fs.listPaths(segments));
DeleteDuplicates(job).dedup(new Path[] { indexes });
IndexMerger(fs, fs.listPaths(indexes), index, tmpDir, job).merge();
    以上方法,其中Generator、Fetcher、ParseSegment、CrawlDb是根据输入的参数循环运行的,根据爬行日志我们可以看到各个类及其方法的调用过程。
    Nutch是支持插件扩展的,这样就可以满足各个不同使用群体的特定需求,例如是要做垂直搜索,并收集特定信息的收集,那么我们可以在其nutch-default.xml文件中找到如下一段:
 1 <property>
 2   <name>plugin.includes</name>
 3   <value>protocol-http|urlfilter-regex|parse-(text|html|js)|index-basic|query-(basic|site|url)|summary-basic|scoring-opic</value>
 4   <description>Regular expression naming plugin directory names to
 5   include.  Any plugin not matching this expression is excluded.
 6   In any case you need at least include the nutch-extensionpoints plugin. By
 7   default Nutch includes crawling just HTML and plain text via HTTP,
 8   and basic indexing and search plugins.
 9   </description>
10 </property>
11 
12 <property>
13   <name>plugin.excludes</name>
14   <value></value>
15   <description>Regular expression naming plugin directory names to exclude.  
16   </description>
17 </property>

    并将plugin.includes拷贝到nutch-site.xml文件中,在plugin.includes的value中加入自己编写的插件即可。
    要进行Nutch的二次开发,在国内首先要解决的问题是中文的分词问题。这是各大搜索公司非常重视的问题,对于我现在所属的单位来说,分词的精度不需要达到那么高,能够将特定领域中的词语分析出来即可,而且对于本领域来说词汇比较特殊,能够很好的和其他词汇区分开来,而且不容易有歧义发生,但是要求的分词速度需要达到一定程度才能够有实用价值。因此,多线程方面的分词程序势在必行,能够达到每秒20万字以上的分词速度才能满足一般需求。




本文依据《创作共用约定》之“署名-禁止派生-非商业用途”方式发布,即你可以免费拷贝、分发、呈现和表演当前作品,但是必须基于以下条款:

  • 署名:你必须明确标明作者的名字。

  • 非商业用途:你不可将当前作品用于商业目的。

  • 禁止派生:你不可更改、转变或者基于此作品重新构造为新作品。

对于任何二次使用或分发,你必须让其他人明确当前作品的授权条款。

在得到作者的明确允许下,这里的某些条款可以放弃。