xiaodaoxiaodao——蓝小刀的自言自语

黑夜给了我寂寞的心情,我却用它来寻找爱情~~

原创 浅入浅出nutch 0.8使用指南4windows收藏

版权所有:(xiaodaoxiaodao)蓝小刀 http://blog.csdn.net/xiaodaoxiaodao/archive/2006/10/20/1342433.aspx

转载请注明来源/作者

浅入浅出nutch 0.8使用指南4windows

 

Nutch是一个搜索引擎,昨天刚从一个朋友那里知道,前一阵子接触了lucene,对搜索的东西跃跃欲试,趁着周末试用了一把,感觉蛮新鲜,网上的例子多是基于0.7版本的,找到了一些0.8的就是跑不起来,忽悠忽悠试了半天,写下一点感觉~~

 

系统环境:Tomcat 5.0.12/JDK1.5/nutch0.8.1/cygwin-cd-release-20060906.iso

使用过程:

 

1. 因为nutch的运行需要unix环境,所以对于windows用户,要先下载一个cygwin,它是一个自由软件,可在windows下模拟unix环境,你可以到http://www.cygwin.com下载在线安装程序,也可以到http://www-inst.eecs.berkeley.edu/~instcd/iso/下载完整安装程序(我下下来有1.27G,呵呵,要保证硬盘空间足够大~~),安装时一路next即可~~~

2. 下载nutch0.8.1,下载地址http://apache.justdn.org/lucene/nutch/,我下载后是解压到D:\ nutch-0.8.1

3. nutch-0.8.1新建文件夹urls,在urls建一文本文件,文件名任意,添加一行内容:http://lucene.apache.org/nutch,这是要搜索的网址

4. 打开nutch-0.8.1下的conf,找到crawl-urlfilter.txt,找到这两行

# accept hosts in MY.DOMAIN.NAME

+^http://([a-z0-9]*\.)*MY.DOMAIN.NAME/

红色部分是一个正则,你要搜索的网址要与其匹配,在这里我改为+^http://([a-z0-9]*\.)*apache.org/

5. OK,下面开始对搜索网址建立索引,运行cygwin,会打开一个命令窗口,输入cd cygdrive/d/ nutch-0.8.1,转到nutch-0.8.1目录

 

6. 执行bin/nutch crawl urls -dir crawled -depth 2 -threads 5 >& crawl.log

参数意义如下(来自apache网站http://lucene.apache.org/nutch/tutorial8.html ):

-dir dir names the directory to put the crawl in.

-threads threads determines the number of threads that will fetch in parallel.

-depth depth indicates the link depth from the root page that should be crawled.

-topN N determines the maximum number of pages that will be retrieved at each level up to the depth.

crawl.log日志文件

 

执行后可以看到nutch-0.8.1下新增一个crawled文件夹,它下面有5个文件夹:

/ crawldb/ linkdbweb link目录,存放url url的互联关系,作为爬行与重新爬行的依据,页面默认30天过期(可以在nutch-site.xml中配置,后面会提到)

 

segments一存放抓取的页面,与上面链接深度depth相关,depth设为2则在segments下生成两个以时间命名的子文件夹,比如” 20061014163012”,打开此文件夹可以看到,它下面还有6个子文件夹,分别是(来自apache网站http://lucene.apache.org/nutch/tutorial8.html):

crawl_generate names a set of urls to be fetched

crawl_fetch contains the status of fetching each url

content contains the content of each url

parse_text contains the parsed text of each url

parse_data contains outlinks and metadata parsed from each url

crawl_parse contains the outlink urls, used to update the crawldb

 

indexes索引目录,我运行时生成了一个 part-00000”的文件夹,

indexlucene的索引目录(nutch是基于lucene,在nutch-0.8.1\lib下可以看到lucene-core-1.9.1.jar最后有luke工具的简单使用方法),是indexs里所有index合并后的完整索引,注意索引文件只对页面内容进行索引,没有进行存储,因此查询时要去访问segments目录才能获得页面内容

 

7. 进行简单测试,在cygwin中输入bin/nutch org.apache.nutch.searcher.NutchBean apache,即调用NutchBeanmain方法搜索关键字”apache”,在cygwin可以看到搜索出:Total hits: 29hits相当于JDBCresults

注意:如果发现搜索结果始终为0,则需要配置一下nutch-0.8.1\confnutch-site.xml,配置内容和下面过程9的配置相同(另外,过程6depth如果设为1也可能造成搜索结果为0),然后重新执行过程6

8. 下面我们要在Tomcat下进行测试,nutch-0.8.1下面有nutch-0.8.1.war,拷贝到Tomcat\webapps下,可以直接用winrar解压到此目录下,我是用Tomcat启动后解压的,解压文件夹名为:nutch

 

9. 打开nutch\WEB-INF\classesnutch-site.xml文件,下面红色为需要新增的内容,其他为原nutch-site.xml内容

 

<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>

<!-- HTTP properties -->

 

<property>

  <name>http.agent.name</name>

  <value>*</value>

  <description></description>

</property>

 

<!-- file properties -->

 

<property>

  <name>searcher.dir</name>

  <value>D:\nutch-0.8.1\crawled</value>

  <description></description>

</property>

</configuration>

 

http.agent.name必须如果去掉这个property查询结果始终为0

searcher.dir:指定前面在cygwin中生成的crawled路径

 

其中我们还可以设置重新爬行时间(在过程6提到:页面默认30天过期

<property>

 <name>fetcher.max.crawl.delay</name>

 <value>30</value>

 <description></description>

</property>

另外还有很多参数可以在nutch-0.8.1\conf下的nutch-default.xml查询,nutch-default.xml中的property配置都带有注释,有兴趣的可以分别拷贝到Tomcat\webapps\nutch\WEB-INF\classes\nutch-site.xml中进行调试

 

10.             打开http://localhost:8081/nutch ,输入”apache”,可以看到 共有 29 项查询结果,和上面在过程7进行简单测试的结果一致

 

Luke介绍:

Luke 是查询lucene索引文件的图形化工具,可以比较直观的看到索引创建情况,它需要结合lucene包一起用

使用过程:

1. 下载地址http://www.getopt.org/luke 它提供3种下载:

standalone full JAR lukeall.jar

standalone minimal JARlukemin.jar

separate JARsluke.jar (~113kB)

lucene-1.9-rc1-dev.jar (~380kB)

analyzers-dev.jar (~348kB)

snowball-1.1-dev.jar (~88kB)

js.jar (~492kB)

我们只需下载”separate JARs”luke.jar即可

 

2. 下载后新建一个文件夹,比如叫”luke_run”,把luke.jar放在文件夹下,同时从nutch-0.8.1\lib下拷贝lucene-core-1.9.1.jar到此文件夹下

3. cmd命令行中转到”luke_run”目录,输入 java -classpath luke.jar;lucene-core-1.9.1.jar org.getopt.luke.Luke,可以看到打开luke图形界面,从”File”==>”Open Lucene index”,打开nutch-0.8.1\crawled\index文件夹(在上面过程6已创建),然后可以在luke中看到索引创建的详细信息

 

4. 附上一点闲言:)使用中发现一个问题(lucene-core-1.9.1.jar中不存在,所以luke不会抛此Exception),就是”Documents””Reconstruct&Edit” 按钮只要一点,就会抛一个Exception

Exception in thread "Thread-12" java.lang.NoSuchMethodError: org.apache.lucene.d

ocument.Field.<init>(Ljava/lang/String;Ljava/lang/String;ZZZZ)V

        at org.getopt.luke.Luke$2.run(Unknown Source)

呵呵,我用的是lucene-core-2.0.0.jar,看起来应该是在这个版本中去掉了某个方法造成的 ,很多时候新版本的出现总是会带来一些细节问题 ~~~~~

 

发表于 @ 2006年10月20日 12:22:00|评论(loading...)

新一篇: eclipse3.2.1及插件安装基础教程 | 旧一篇: JSF中如何在弹出窗口中显示编辑页面

用户操作
[即时聊天] [发私信] [加为好友]
蓝瞳——小刀小刀小小刀
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
蓝瞳——小刀小刀小小刀的公告
个人简介
网名:
xiaodaoxiaodao(蓝小刀)
QQ:
68582844
Gmail:
xiaodaoxiaodao@gmail.com


BLOG转移到Blogjava:
http://www.blogjava.net/xiaodaoxiaodao

来自:苏州
--------------------------------------------------
访问量:
文章分类
    收藏
    博客网
    博客中国
    博客动力
    博客园-专注于.NET技术
    博客联盟
    技术站点
    LinuxAid技术支持论坛
    LinuxByte
    中国黑客同盟
    闪客帝国
    维客网
    CSDN&DoNews
    天下维客
    维库
    网络天书
    文学站点
    小说原创门户--起点中文网
    榕树下-生活·感受·随想
    洪恩在线网上交流
    红袖添香 - 最具影响力的文学网站
    存档
    软件项目交易
    Csdn Blog version 3.1a
    Copyright © 蓝瞳——小刀小刀小小刀