搜尋引擎Nutch 0.7.2 試用筆記

來源:互聯網
上載者:User
我的jdk 是1.5.x ,Tomcat是5.0.x

1 下載0.7.2 版本的包:裡面已經包含了war檔案,所以不需要Ant編譯了

2 安裝Cygwin,這個沒什麼好說的。

3 把Nutch借壓縮到D:/nutch

4 在D:/nutch下面建立一個檔案 urls (沒有尾碼)

http://www.xxx.edu.cn/

5 在D:/nutch/conf/crawl-urlfilter.txt裡面,加入

+^http://www.xxx.edu.cn/

6 環境變數加入

NUTCH_JAVA_HOME = D:/jdk1.5.0_06

7 開啟cygwin視窗,

cd D:/nutch

在D:/nutch下面執行

bin/nutch crawl urls -dir crawled -depth 3 >& crawl.log
這個命令會在目前的目錄下建立一個crawled的檔案夾,然後對剛才的www.xxx.edu.cn的網站開始檢索。
層數是3層,一般最好10層。然後結果輸出在crawl.log裡面
8 將nutch-0.7.2.war拷貝到tomcat/webapps下面,改名nutch
9 在D:/tomcat/conf/Catalina/localhost/ 建立nutch.xml
<Context path="" debug="5" privileged="true" docBase="nutch"/>
10 啟動tomcat,等war解開以後,開啟
D:/tomcat/webapps/nutch/WEB-INF/classes/nutch-site.xml
修改如下
<nutch-conf><property>    <name>searcher.dir</name>    <value>D:/nutch/crawled/</value></property></nutch-conf>
11 D:/tomcat/webapps/nutch/zh/include 下面建立header.jsp,內容就是複製header.html,但是
前面加上
<%@ page   contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
在D:/tomcat/webapps/nutch/search.jsp裡面,找到並修改為
<jsp:include page="<%= language + "/include/header.jsp"%>"/>
順便把下面js注釋掉
function queryfocus() {
//search.query.focus();  }
12 D:/tomcat/conf/server.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" useBodyEncodingForURI="true" />
好了,到此,重啟tomcat,訪問 http://localhost:8080 就可以看到搜尋首頁了,而且搜尋支援中文
和分詞,雖然分得不是很好。
13 接下來一個重要的功能就是累加式更新索引。
在D:/nutch下建立recrawl.sh 。內容為
#!/bin/bash
# A simple script to run a Nutch re-crawl
if [ -n "$1" ]then  crawl_dir=$1else  echo "Usage: recrawl crawl_dir [depth] [adddays]"  exit 1fi
if [ -n "$2" ]then  depth=$2else  depth=5fi
if [ -n "$3" ]then  adddays=$3else  adddays=0fi
webdb_dir=$crawl_dir/dbsegments_dir=$crawl_dir/segmentsindex_dir=$crawl_dir/index
# The generate/fetch/update cyclefor ((i=1; i <= depth ; i++))do  bin/nutch generate $webdb_dir $segments_dir -adddays $adddays  segment=`ls -d $segments_dir/* | tail -1`  bin/nutch fetch $segment  bin/nutch updatedb $webdb_dir $segmentdone
# Update segmentsmkdir tmpbin/nutch updatesegs $webdb_dir $segments_dir tmprm -R tmp
# Index segmentsfor segment in `ls -d $segments_dir/* | tail -$depth`do  bin/nutch index $segmentdone
# De-duplicate indexes# "bogus" argument is ignored but needed due to# a bug in the number of args expectedbin/nutch dedup $segments_dir bogus
# Merge indexesls -d $segments_dir/* | xargs bin/nutch merge $index_dir
在cygwin裡面,執行
./recrawl crawled 8
意思是更新索引,目錄是crawled,層數8 。還可以把天數跟在後面。執行完畢後要重啟Tomcat,因為
Nutch.war裡面對查詢有緩衝。
 
最後可以把這個指令碼放到crontab裡面,每天夜裡2點執行,執行完畢後重新啟動Tomcat。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.