[原创]Nutch_0.8实践(1)

 

Nutch_<st1:chmetcnv hasspace="True" numbertype="1" negative="False" sourcevalue=".8" unitname="in" w:st="on" tcsc="0">0.8实践</st1:chmetcnv> (1)<o:p></o:p>

<st1:chsdate w:st="on" month="5" islunardate="False" day="21" year="2007" isrocdate="False">2007-5-21</st1:chsdate><o:p></o:p>

<o:p> </o:p>

Key Word: Nutch Lucene<o:p></o:p>

(一)前言<o:p></o:p>

1.         概述

       为了完成本地的全文检索,并在以后中可以升级到对其他网站的全文检索的功能。采用了Lucene搜索引擎来尝试,如果效果好的话,可以普及到以后的产品或项目中。

   整个过程中,发现网上的资源良莠不齐,才决定写该文档,供大家参考研究讨论。

<o:p></o:p>

2.         作业环境<o:p></o:p>

        WIN SERVER 2003 Enterprise Editon + WAS6.0(自带JRE <st1:chsdate w:st="on" month="12" islunardate="False" day="30" year="1899" isrocdate="False">1.4.2</st1:chsdate>)

<o:p></o:p>

3.         测试开发环境<o:p></o:p>

        WIN XP Pro + JRE <st1:chsdate w:st="on" month="12" islunardate="False" day="30" year="1899" isrocdate="False">1.4.2</st1:chsdate>_03 + Tomcat 5.0

 

(二)开发

 

1.         前提条件<o:p></o:p>

       Cygwin下载:cygwin官方http://www.cygwin.com

       Nutch 0.8下载:nutch官方http://lucene.apache.org/nutch/

       Lukeall 0.6下载:http://www.getopt.org/luke/(查看Nutch Crawl工具,非必要)

      

       建议:下载http://www.cygwin.com/setup.exe,点击setup.exe建议选择第二项(“Download Without Installing”),选择一个.tw的镜像下载;下载完毕后,在点击steup.exe,选择第三项(“Install from Local Direction”),完成Cygwin的安装。

       插曲一:由于作业环境和测试开发环境是JRE1.4的,在安装nutch0.9之后即报错版本不兼容,打开源程序一看是JRE1.5的代码,只好忍痛舍弃最近更新的lucene<st1:chsdate w:st="on" month="12" islunardate="False" day="30" year="1899" isrocdate="False">2.1.0</st1:chsdate>,重新安装nutch0.8lukeall-0.7.jar也是基于JRE1.5,使用lukeall-0.6.jar

       插曲二:默认cygwin是没有vimorecrontab的功能(可惜...),建议都下载cron安装后,再继续配置nutch

<o:p> </o:p>

2.         配置<o:p></o:p>

       先将nutch下载后全部解压存放到$cygwin_home/home/$user/nutch下,设置环境变量NUTCH_JAVA_HOME=$JAVA_HOME

2.1.        修改$cygwin_home/home/$user/nutch/conf/crawl-urlfilter.txt<o:p></o:p>

<o:p></o:p>

<o:p>      shell</o:p><o:p>代码</o:p>

  1. # accept hosts in MY.DOMAIN.NAME  
  2.  
  3. #+^http://([a-z0-9]*\.)*MY.DOMAIN.NAME/   
  4.   
  5. +^http://192.168.0.92:8080/   

(注:根据实际情况配置)

2.2.        添加$cygwin_home/home/$user/nutch/urls/url.txt文件

<o:p>            增加代码:</o:p>

<o:p>
txt代码
</o:p> <o:p>
  1. http://192.168.0.92:8080/nbtravel/index.html  

(注:根据实际情况配置)

2.3.        修改$cygwin_home/home/$user/nutch/conf/nutch-site.xml<o:p></o:p>

            修改代码:

  1. <?xml version="1.0"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3.   
  4. <!-- Put site-specific property overrides in this file. -->  
  5.   
  6. <configuration>  
  7.     <property>  
  8.       <name>http.agent.name</name>  
  9.       <value>Nutch</value>  
  10.       <description>HTTP 'User-Agent' request header. MUST NOT be empty -    
  11.       please set this to a single word uniquely related to your organization.   
  12.   
  13.       NOTE: You should also check other related properties:   
  14.   
  15.         http.robots.agents   
  16.         http.agent.description   
  17.         http.agent.url   
  18.         http.agent.email   
  19.         http.agent.version   
  20.   
  21.       and set their values appropriately.   
  22.   
  23.       </description>  
  24.     </property>  
  25.   
  26.     <property>  
  27.       <name>http.robots.agents</name>  
  28.       <value>Nutch,*</value>  
  29.       <description>The agent strings we'll look for in robots.txt files,   
  30.       comma-separated, in decreasing order of precedence. You should   
  31.       put the value of http.agent.name as the first agent name, and keep the   
  32.       default * at the end of the list. E.g.: BlurflDev,Blurfl,*   
  33.       </description>  
  34.     </property>  
  35.   
  36.     <property>  
  37.       <name>http.agent.description</name>  
  38.       <value>Nutch Search Engineer</value>  
  39.       <description>Further description of our bot- this text is used in   
  40.       the User-Agent header.  It appears in parenthesis after the agent name.   
  41.       </description>  
  42.     </property>  
  43.   
  44.     <property>  
  45.       <name>http.agent.url</name>  
  46.       <value>http://lucene.apache.org/nutch/bot.html</value>  
  47.       <description>A URL to advertise in the User-Agent header.  This will    
  48.        appear in parenthesis after the agent name. Custom dictates that this   
  49.        should be a URL of a page explaining the purpose and behavior of this   
  50.        crawler.   
  51.       </description>  
  52.     </property>  
  53.   
  54.     <property>  
  55.       <name>http.agent.email</name>  
  56.       <value>nutch-agent@lucene.apache.org</value>  
  57.       <description>An email address to advertise in the HTTP 'From' request   
  58.        header and User-Agent header. A good practice is to mangle this   
  59.        address (e.g. 'info at example dot com') to avoid spamming.   
  60.       </description>  
  61.     </property>  
  62.   
  63. </configuration>  
 
 
2.4.        修改$tomcat_home/conf/server.xml
 
2.4.1.       Connector
 
xml 代码
<Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"       enableLookups="false" redirectPort="8443" acceptCount="100"       debug="0" connectionTimeout="20000"         disableUploadTimeout="true" URIEncoding="UTF-8"/>     
 
2.4.2.       Context
xml 代码
<Context path="/nutch" docBase="$cygwin_home\home\$user\nutch\nutch-0.8.1.war" debug="0" reloadable="true" crossContext="true" />       <Context path="/pub" docBase="D:\workspace\nbpub" debug="0" reloadable="true" crossContext="true" />       <Context path="/nbtravel" docBase="D:\workspace\nbtravel\nbtravel" debug="0" reloadable="true" crossContext="true" />  

      

 (注:根据实际情况配置,pub和nbtravel为我的目标项目)
 
 2.5.        启动TOMCAT
2.6.        修改$tomcat_home/webapps/nutch/WEB-INF/classes/nutch-site.xml
            修改代码:
 
xml 代码
<?xml version="1.0"?>   <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>      <!-- Put site-specific property overrides in this file. -->      <configuration>   <property>   <name>searcher.dir</name>   <value>D:\cygwin\home\Howard\nutch\crawl</value>   </property>   </configuration>  
 
 
2.7.        增加$cygwin_home\home\$user\nutch\cron.sh文件
            增加代码:
 
shell代码
bin/nutch crawl urls -dir crawl -depth 7 -topN 50  
 
(注:根据实际情况配置)
 
2.8.        $cygwin_home\home\$user\nutch\下执行,“./cron.sh”,开始爬,直到提示“crawl finished: crawl
 
2.9.        执行http://192.168.0.92:8080/nutch/ ,查询效果如下:

 
图表 1查询结果
 
 
3.         遗留问题
        问题一:必须关闭TOMCAT才能执行删除索引,那么如果放到生产环境上是否也存在类似问题。
        问题二:分词问题,命中率并不是很高,如图1Lucene将“统计”,拆分成“统计”、“统”和“计”,如何优化。
        问题三:不能对索引进行Update,只能删除重建,影响效率。
        问题四:还没有安装cron,没有把爬虫放在后台执行队列中。     
     
To be continu…

xml 代码
</o:p>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值