- 浏览: 1637902 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (405)
- C/C++ (16)
- Linux (60)
- Algorithm (41)
- ACM (8)
- Ruby (39)
- Ruby on Rails (6)
- FP (2)
- Java SE (39)
- Java EE (6)
- Spring (11)
- Hibernate (1)
- Struts (1)
- Ajax (5)
- php (2)
- Data/Web Mining (20)
- Search Engine (19)
- NLP (2)
- Machine Learning (23)
- R (0)
- Database (10)
- Data Structure (6)
- Design Pattern (16)
- Hadoop (2)
- Browser (0)
- Firefox plugin/XPCOM (8)
- Eclise development (5)
- Architecture (1)
- Server (1)
- Cache (6)
- Code Generation (3)
- Open Source Tool (5)
- Develope Tools (5)
- 读书笔记 (7)
- 备忘 (4)
- 情感 (4)
- Others (20)
- python (0)
最新评论
-
532870393:
请问下,这本书是基于Hadoop1还是Hadoop2?
Hadoop in Action简单笔记(一) -
dongbiying:
不懂呀。。
十大常用数据结构 -
bing_it:
...
使用Spring MVC HandlerExceptionResolver处理异常 -
一别梦心:
按照上面的执行,文件确实是更新了,但是还是找不到kernel, ...
virtualbox 4.08安装虚机Ubuntu11.04增强功能失败解决方法 -
dsjt:
楼主spring 什么版本,我的3.1 ,xml中配置 < ...
使用Spring MVC HandlerExceptionResolver处理异常
今天我们看看Nutch网页抓取,所用的几种数据结构:
主要涉及到了这几个类:FetchListEntry,Page,
首先我们看看FetchListEntry类:
public final class FetchListEntry implements Writable, Cloneable
实现了Writable, Cloneable接口,Nutch许多类实现了Writable, Cloneable。
自己负责自己的读写操作其实是个很合理的设计方法,分离出来反倒有很琐碎
的感觉。
看看里面的成员变量:
我们看看如何读取各个字段的,也就是函数
public final void readFields(DataInput in) throws IOException
读取version 字段,并判断如果版本号是否大约当前的版本号,则抛出版本不匹配的异常,
然后读取fetch 和page 字段。
判断如果版本号大于1,说明anchors已经保存过了,读取anchors,否则直接赋值一个空的字符串
代码如下:
同时还提供了一个静态的读取各个字段的函数,并构建出FetchListEntry对象返回:
写得代码则比较易看,分别写每个字段:
其他的clone和equals函数实现的也非常易懂。
下面我们看看Page类的代码:
public class Page implements WritableComparable, Cloneable
和FetchListEntry一样同样实现了Writable, Cloneable接口,我们看看Nutch的注释,我们就非常容易知道各个字段的意义了:
各个字段:
同样看看他是如何读取自己的各个字段的,其实代码加上本来提供的注释,使很容易看懂的,不再详述:
写各个字段也很直接:
我们顺便看看提供方便读写Fetch到的内容的类FetcherOutput:这个类通过委托前面介绍的两个类的读写,提供了Fetche到的
各种粒度结构的读写功能,代码都比较直接,不再详述。
下次我们看看parse-html插件,看看Nutch是如何提取html页面的。
主要涉及到了这几个类:FetchListEntry,Page,
首先我们看看FetchListEntry类:
public final class FetchListEntry implements Writable, Cloneable
实现了Writable, Cloneable接口,Nutch许多类实现了Writable, Cloneable。
自己负责自己的读写操作其实是个很合理的设计方法,分离出来反倒有很琐碎
的感觉。
看看里面的成员变量:
public static final String DIR_NAME = "fetchlist";//要写入磁盘的目录 private final static byte CUR_VERSION = 2;//当前的版本号 private boolean fetch;//是否抓取以便以后更新 private Page page;//当前抓取的页面 private String[] anchors;//抓取到的该页面包含的链接
我们看看如何读取各个字段的,也就是函数
public final void readFields(DataInput in) throws IOException
读取version 字段,并判断如果版本号是否大约当前的版本号,则抛出版本不匹配的异常,
然后读取fetch 和page 字段。
判断如果版本号大于1,说明anchors已经保存过了,读取anchors,否则直接赋值一个空的字符串
代码如下:
byte version = in.readByte(); // read version if (version > CUR_VERSION) // check version throw new VersionMismatchException(CUR_VERSION, version); fetch = in.readByte() != 0; // read fetch flag page = Page.read(in); // read page if (version > 1) { // anchors added in version 2 anchors = new String[in.readInt()]; // read anchors for (int i = 0; i < anchors.length; i++) { anchors[i] = UTF8.readString(in); } } else { anchors = new String[0]; }
同时还提供了一个静态的读取各个字段的函数,并构建出FetchListEntry对象返回:
public static FetchListEntry read(DataInput in) throws IOException { FetchListEntry result = new FetchListEntry(); result.readFields(in); return result; }
写得代码则比较易看,分别写每个字段:
public final void write(DataOutput out) throws IOException { out.writeByte(CUR_VERSION); // store current version out.writeByte((byte)(fetch ? 1 : 0)); // write fetch flag page.write(out); // write page out.writeInt(anchors.length); // write anchors for (int i = 0; i < anchors.length; i++) { UTF8.writeString(out, anchors[i]); } }
其他的clone和equals函数实现的也非常易懂。
下面我们看看Page类的代码:
public class Page implements WritableComparable, Cloneable
和FetchListEntry一样同样实现了Writable, Cloneable接口,我们看看Nutch的注释,我们就非常容易知道各个字段的意义了:
/********************************************* * A row in the Page Database. * <pre> * type name description * --------------------------------------------------------------- * byte VERSION - A byte indicating the version of this entry. * String URL - The url of a page. This is the primary key. * 128bit ID - The MD5 hash of the contents of the page. * 64bit DATE - The date this page should be refetched. * byte RETRIES - The number of times we've failed to fetch this page. * byte INTERVAL - Frequency, in days, this page should be refreshed. * float SCORE - Multiplied into the score for hits on this page. * float NEXTSCORE - Multiplied into the score for hits on this page. * </pre> * * @author Mike Cafarella * @author Doug Cutting *********************************************/
各个字段:
private final static byte CUR_VERSION = 4; private static final byte DEFAULT_INTERVAL = (byte)NutchConf.get().getInt("db.default.fetch.interval", 30); private UTF8 url; private MD5Hash md5; private long nextFetch = System.currentTimeMillis(); private byte retries; private byte fetchInterval = DEFAULT_INTERVAL; private int numOutlinks; private float score = 1.0f; private float nextScore = 1.0f;
同样看看他是如何读取自己的各个字段的,其实代码加上本来提供的注释,使很容易看懂的,不再详述:
ublic void readFields(DataInput in) throws IOException { byte version = in.readByte(); // read version if (version > CUR_VERSION) // check version throw new VersionMismatchException(CUR_VERSION, version); url.readFields(in); md5.readFields(in); nextFetch = in.readLong(); retries = in.readByte(); fetchInterval = in.readByte(); numOutlinks = (version > 2) ? in.readInt() : 0; // added in Version 3 score = (version>1) ? in.readFloat() : 1.0f; // score added in version 2 nextScore = (version>3) ? in.readFloat() : 1.0f; // 2nd score added in V4 }
写各个字段也很直接:
public void write(DataOutput out) throws IOException { out.writeByte(CUR_VERSION); // store current version url.write(out); md5.write(out); out.writeLong(nextFetch); out.write(retries); out.write(fetchInterval); out.writeInt(numOutlinks); out.writeFloat(score); out.writeFloat(nextScore); }
我们顺便看看提供方便读写Fetch到的内容的类FetcherOutput:这个类通过委托前面介绍的两个类的读写,提供了Fetche到的
各种粒度结构的读写功能,代码都比较直接,不再详述。
下次我们看看parse-html插件,看看Nutch是如何提取html页面的。
评论
3 楼
sharong
2008-03-17
或者是要安装一些nutch的插件?
2 楼
fuliang
2007-12-15
另外补充一下Content类:
public final class Content extends VersionedWritable
我们看到继承了VersionedWritable类。VersionedWritable类实现了版本字段的读写功能。
我们先看看成员变量:
DIR_NAME 为Content保存的目录,
VERSION 为版本常量
url为该Content所属页面的url
base为该Content所属页面的base url
contentType为该Content所属页面的contentType
metadata为该Content所属页面的meta信息
下面我们看看Content是如何读写自身的字段的:
public final void readFields(DataInput in) throws IOException
这个方法功能为读取自身的各个字段
代码加注释之后基本上比较清晰了.
super.readFields(in);
这句调用父类VersionedWritable读取并验证版本号
写的代码也比较简单:
其实这些类主要是它的字段.以及怎样划分各个域模型的
public final class Content extends VersionedWritable
我们看到继承了VersionedWritable类。VersionedWritable类实现了版本字段的读写功能。
我们先看看成员变量:
public static final String DIR_NAME = "content"; private final static byte VERSION = 1; private String url; private String base; private byte[] content; private String contentType; private Properties metadata;
DIR_NAME 为Content保存的目录,
VERSION 为版本常量
url为该Content所属页面的url
base为该Content所属页面的base url
contentType为该Content所属页面的contentType
metadata为该Content所属页面的meta信息
下面我们看看Content是如何读写自身的字段的:
public final void readFields(DataInput in) throws IOException
这个方法功能为读取自身的各个字段
super.readFields(in); // check version url = UTF8.readString(in); // read url base = UTF8.readString(in); // read base content = WritableUtils.readCompressedByteArray(in); contentType = UTF8.readString(in); // read contentType int propertyCount = in.readInt(); // read metadata metadata = new Properties(); for (int i = 0; i < propertyCount; i++) { metadata.put(UTF8.readString(in), UTF8.readString(in)); }
代码加注释之后基本上比较清晰了.
super.readFields(in);
这句调用父类VersionedWritable读取并验证版本号
写的代码也比较简单:
public final void write(DataOutput out) throws IOException { super.write(out); // write version UTF8.writeString(out, url); // write url UTF8.writeString(out, base); // write base WritableUtils.writeCompressedByteArray(out, content); // write content UTF8.writeString(out, contentType); // write contentType out.writeInt(metadata.size()); // write metadata Iterator i = metadata.entrySet().iterator(); while (i.hasNext()) { Map.Entry e = (Map.Entry)i.next(); UTF8.writeString(out, (String)e.getKey()); UTF8.writeString(out, (String)e.getValue()); } }
其实这些类主要是它的字段.以及怎样划分各个域模型的
1 楼
fuliang
2007-12-15
dfgdfg
发表评论
-
Lucene 索引格式
2013-06-25 20:11 0索引结构: 索引层次 ... -
计算广告学
2012-08-12 13:53 0计算广告学一: 1、核 ... -
《Lucene in Action》简单笔记
2011-12-22 09:19 0第一章 Meet Lucene -
Information Retrieval Resources
2011-04-07 16:40 1370Information Retrieval Resource ... -
使用Jsoup抽取数据
2011-03-20 19:22 4918Jsoup是一个Java的HTML解析器,提供了非常方便的抽取 ... -
常见文件类型识别
2010-09-22 20:09 11791根据文件的后缀名识别文件类型并不准确,可以使用文件的头信息进行 ... -
(zz)信息检索领域资料整理
2010-06-05 13:05 3137A Guide to Information Retrieva ... -
Introduce to Inforamtion Retrieval读书笔记(2)
2009-10-31 13:02 1893The term vocabulary and posting ... -
Introduce to Inforamtion Retrieval读书笔记(1)
2009-10-25 23:49 2013很好的一本书,介绍的非常全面,看了很久了,还没有看完,刚看完前 ... -
Query Log Mining notes
2009-10-02 18:08 1246Enhancing Efficiency of Search ... -
百度搜索的一些高级语法
2009-08-27 20:06 18951.title语法 就是在title ... -
Hadoop好书推荐:Hadoop The Definitive Guide
2009-08-16 22:49 3616第一本详细介绍Hadoop的书籍,从网上下来看了几章,作者是H ... -
Java开源搜索引擎[收藏]
2008-04-24 00:09 2881Egothor Egothor是一个用Java编写的开 ... -
分享一本斯坦福的信息检索的教材
2008-01-04 23:59 2434斯坦福的信息检索的教材,还没出版,先分享一下电子版原稿. 对于 ... -
分享一本搜索引擎的电子书
2007-12-29 19:42 2498还没有来得及看,但搜索引擎的书不是很好找,先放上,希望对大家能 ... -
分享一个Nutch入门学习的资料
2007-12-18 20:49 4244分享一个Nutch入门学习的资料,感觉写的还不错. -
搜索引擎Nutch源代码研究之一 网页抓取(4)
2007-12-17 22:37 8356今天来看看Nutch如何Parse网页的: Nutch使用了两 ... -
[转]MAP/REDUCE:Google和Nutch实现异同及其他
2007-12-15 19:21 2953设计要素 nutch包含以下几个部分: 辅助类 Log:记载运 ... -
Nutch源代码学习小小总结一下
2007-12-15 19:13 4425我现在看得源码主要是网页抓取部分,这部分相对比较容易。我首先定 ... -
搜索引擎Nutch源代码研究之一 网页抓取(2)
2007-12-15 00:36 5528今天我们来看看Nutch的源代码中的protocol-h ...
相关推荐
《Lucene+nutch搜索引擎开发》书附带的源代码
nutch 源代码的详细分析,对于自己实现自己的搜索引擎很有帮助,尤其是将nutch项目嵌入到 自己的项目 当中很有帮助!
lucene nutch 搜索引擎 开发 实例 源代码 源码 包含lucene使用的所有源代码,从建立索引,搜索,删除,排序,都有,非常齐全 还有PDF 解析,WORD解析 ,EXCEL,ppt,xml解析等,,都有源码实现 还有nutch源码,spider...
Nutch是一个优秀的开放源代码的Web搜索引擎。虽然Nutch的页面排序方法比较合理,但是很多情况下仍然不能 满足需要。分析开源搜索引擎Nutch代码,研究了Nutch的页面排序方法。在Nutch原有的结构基础上提出了3种修改...
图解搜索引擎nutch配置,自己制作的教程。因为在网上搜索到的教程很多都是粗略,对于初学nutch搜索引擎很难配置好,所以自己亲自打造了一篇图解教程!希望你能够配置成功!
licene 实例代码 nutch实例代码 lucene+nutch搜索引擎开发实例代码(王学松版)
基于Java的搜索引擎Nutch中文搜索技术研究 摘要:Nutch是一个优秀的基于Java的开放源码搜索引擎,为了使它能够支持中文搜索,本文在分析了Nutch结构的基础上,采用词表分词技术和前向匹配分词算法对中文信息进行分词...
Lucene+nutch搜索引擎开发(源代码),内含本书的PDF电子下载地址。
Nutch 是一个开源的、Java 实现的搜索引擎。它提供了我们运行自己的搜索引擎所需的全部工具。 nutch 1.0
Nutch 是一个开源Java 实现的搜索引擎。它提供了我们运行自己的搜索引擎所需的全部工具。包括全文搜索和Web爬虫。 本资源官网上下的源代码。 nutch-2.1 适用于windows系统
相对于那些商用的搜索引擎, Nutch作为开放源代码 搜索引擎将会更加透明, 从而更值得大家信赖. 现在所有主要的搜索引擎都采用私有的排序算法, 而不会解释为什么一个网页会排在一个特定的位置. 除此之外, 有的搜索...
nutch源代码,共享给大家。nutch是一个开源的搜索引擎
这里是在网上搜到的Nutch配置的博客,比较详细,担心自己以后配置的时候忘了,所以传到csdn,顺便分享给大家。
其中内容均为前段时间研究开源搜索引擎时搜集参考的资料,非常齐全包含的内容有: Computing PageRank Using Hadoop.ppt Google的秘密PageRank彻底解说中文版.doc JAVA_Lucene_in_Action教程完整版.doc Java开源搜索...
Nutch搜索引擎·Nutch简介及安装(第1期) Nutch搜索引擎·Solr简介及安装(第2期) Nutch搜索引擎·Nutch简单应用(第3期) Nutch搜索引擎·Eclipse开发配置(第4期) Nutch搜索引擎·Nutch浅入分析(第5期)
基于Nutch的搜索引擎系统的研究与实现
Lucene+Nutch搜索引擎开发
非常实用的分布式搜索引擎开发工具nutch,有兴趣的赶紧下吧!
Nutch搜索引擎数据获取1、 基本原理2、网络蜘蛛3、局域网抓取