版權所有:(xiaodaoxiaodao)藍小刀
??
xiaodaoxiaodao@gmail.com
http://www.aygfsteel.com/xiaodaoxiaodao/articles/103441.html
??
轉載請注明來源/作者
淺入淺出nutch 0.8使用指南4windows
Nutch
是一個搜索引擎,昨天剛從一個朋友那里知道,前一陣子接觸了
lucene
,對搜索的東西躍躍欲試,趁著周末試用了一把,感覺蠻新鮮,網上的例子多是基于
0.7
版本的,找到了一些
0.8
的就是跑不起來,忽悠忽悠試了半天,寫下一點感覺
~~
系統環境:
Tomcat
使用過程:
1.
因為
nutch
的運行需要
unix
環境,所以對于
windows
用戶,要先下載一個
cygwin
,它是一個自由軟件,可在
windows
下模擬
unix
環境,你可以到
http://www.cygwin.com/
下載在線安裝程序,也可以到
http://www-inst.eecs.berkeley.edu/~instcd/iso/
下載完整安裝程序(我下下來有
2.
下載
nutch
3.
在
nutch-
4.
打開
nutch-
# 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-
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-
①
/
②
crawldb/ linkdb
:
web 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
⑤
index
:
lucene
的索引目錄(
nutch
是基于
lucene
的
,在
nutch-
7.
進行簡單測試,在
cygwin
中輸入
”bin/nutch org.apache.nutch.searcher.NutchBean apache”
,即調用
NutchBean
的
main
方法搜索關鍵字
”apache”
,在
cygwin
可以看到搜索出:
Total hits: 29
(
hits
相當于
JDBC
的
results
)
注意:
如果發現搜索結果始終為
0
,則需要配置一下
nutch-
8.
下面我們要在
Tomcat
下進行測試,
nutch-
9.
打開
nutch\WEB-INF\classes
下
nutch-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-
? <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-
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 JAR
:
lukemin.jar
separate JARs
:
luke.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-
3.
在
cmd
命令行中轉到
”luke_run”
目錄,輸入
”
java -classpath luke.jar;lucene-core-
4.
附上一點閑言:)使用中發現一個問題(在
lucene-core-
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-
版權所有:(xiaodaoxiaodao)藍小刀
??
xiaodaoxiaodao@gmail.com