小菜毛毛技術分享

          與大家共同成長

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            164 Posts :: 141 Stories :: 94 Comments :: 0 Trackbacks

          前幾天看到盧亮的 Larbin 一種高效的搜索引擎爬蟲工具 一文提到 Nutch,很是感興趣,但一直沒有時間進行測試研究。趁著假期,先測試一下看看。用搜索引擎查找了一下,發現中文技術社區對 Larbin 的關注要遠遠大于 Nutch 。只有一年多前何東在他的竹筍炒肉中對 Nutch 進行了一下介紹

          Nutch vs Lucene
          Lucene 不是完整的應用程序,而是一個用于實現全文檢索的軟件庫。
          Nutch 是一個應用程序,可以以 Lucene 為基礎實現搜索引擎應用。

          Nutch vs GRUB
          GRUB 是一個分布式搜索引擎(參考)。用戶只能得到客戶端工具(只有客戶端是開源的),其目的在于利用用戶的資源建立集中式的搜索引擎。
          Nutch 是開源的,可以建立自己內部網的搜索引擎,也可以針對整個網絡建立搜索引擎。自由(Free)而免費(Free)。

          Nutch vs Larbin
          "Larbin只是一個爬蟲,也就是說larbin只抓取網頁,至于如何parse的事情則由用戶自己完成。另外,如何存儲到數據庫以及建立索引的事情 larbin也不提供。[引自這里
          Nutch 則還可以存儲到數據庫并建立索引。
          Nutch Architecture.png
          [引自這里

          Nutch 的早期版本不支持中文搜索,而最新的版本(2004-Aug-04 發布了 0.5)已經做了很大的改進。相對先前的 0.4 版本,有 20 多項的改進,結構上也更具備擴展性。0.5 版經過測試,對中文搜索支持的也很好。

          下面是我的測試過程。

          前提條件(這里Linux 為例,如果是 Windows 參見手冊):

          • Java 1.4.x 。因為我的系統上安裝的Oracle 10g 已經有 Java 了。設定環境變量:NUTCH_JAVA_HOME 。
            [root@fc3 ~]# export NUTCH_JAVA_HOME=/u01/app/oracle/product/10.1.0/db_1/jdk/jre
                
          • Tomcat 4.x 。從這里下載。
          • 足夠的磁盤空間。我預留了 4G 的空間。

          首先下載最新的穩定版:

          [root@fc3 ~]# wget http://www.nutch.org/release/nutch-0.5.tar.gz
          

          解壓縮:

          [root@fc3 ~]# tar -zxvf nutch-0.5.tar.gz
          ......
          [root@fc3 ~]# mv nutch-0.5 nutch
          

          測試一下 nutch 命令:

          [root@fc3 nutch]# bin/nutch
          Usage: nutch COMMAND
          where COMMAND is one of:
          crawl             one-step crawler for intranets
          admin             database administration, including creation
          inject            inject new urls into the database
          generate          generate new segments to fetch
          fetchlist         print the fetchlist of a segment
          fetch             fetch a segment's pages
          dump              dump a segment's pages
          index             run the indexer on a segment's fetcher output
          merge             merge several segment indexes
          dedup             remove duplicates from a set of segment indexes
          updatedb          update database from a segment's fetcher output
          mergesegs         merge multiple segments into a single segment
          readdb            examine arbitrary fields of the database
          analyze           adjust database link-analysis scoring
          server            run a search server
          or
          CLASSNAME         run the class named CLASSNAME
          Most commands print help when invoked w/o parameters.
          [root@fc3 nutch]#
          

          Nutch 的爬蟲有兩種方式

          • 爬行企業內部網(Intranet crawling)。針對少數網站進行。用 crawl 命令。
          • 爬行整個互聯網。 使用低層的 inject, generate, fetchupdatedb 命令。具有更強的可控制性。

          以本站(http://www.dbanotes.net)為例,先進行一下針對企業內部網的測試。

          在 nutch 目錄中創建一個包含該網站頂級網址的文件 urls ,包含如下內容:
          http://www.dbanotes.net/
          

          然后編輯conf/crawl-urlfilter.txt 文件,設定過濾信息,我這里只修改了MY.DOMAIN.NAME:

          # accept hosts in MY.DOMAIN.NAME
          +^http://([a-z0-9]*\.)*dbanotes.net/
          

          運行如下命令開始抓取分析網站內容:

          [root@fc3 nutch]# bin/nutch crawl urls -dir crawl.demo -depth 2 -threads 4 >& crawl.log
          

          depth 參數指爬行的深度,這里處于測試的目的,選擇深度為 2 ;
          threads 參數指定并發的進程 這是設定為 4 ;

          在該命令運行的過程中,可以從 crawl.log 中查看 nutch 的行為以及過程:

          ......
          050102 200336 loading file:/u01/nutch/conf/nutch-site.xml
          050102 200336 crawl started in: crawl.demo
          050102 200336 rootUrlFile = urls
          050102 200336 threads = 4
          050102 200336 depth = 2
          050102 200336 Created webdb at crawl.demo/db
          ......
          050102 200336 loading file:/u01/nutch/conf/nutch-site.xml
          050102 200336 crawl started in: crawl.demo
          050102 200336 rootUrlFile = urls
          050102 200336 threads = 4
          050102 200336 depth = 2
          050102 200336 Created webdb at crawl.demo/db
          050102 200336 Starting URL processing
          050102 200336 Using URL filter: net.nutch.net.RegexURLFilter
          ......
          050102 200337 Plugins: looking in: /u01/nutch/plugins
          050102 200337 parsing: /u01/nutch/plugins/parse-html/plugin.xml
          050102 200337 parsing: /u01/nutch/plugins/parse-pdf/plugin.xml
          050102 200337 parsing: /u01/nutch/plugins/parse-ext/plugin.xml
          050102 200337 parsing: /u01/nutch/plugins/parse-msword/plugin.xml
          050102 200337 parsing: /u01/nutch/plugins/query-site/plugin.xml
          050102 200337 parsing: /u01/nutch/plugins/protocol-http/plugin.xml
          050102 200337 parsing: /u01/nutch/plugins/creativecommons/plugin.xml
          050102 200337 parsing: /u01/nutch/plugins/language-identifier/plugin.xml
          050102 200337 parsing: /u01/nutch/plugins/query-basic/plugin.xml
          050102 200337 logging at INFO
          050102 200337 fetching http://www.dbanotes.net/
          050102 200337 http.proxy.host = null
          050102 200337 http.proxy.port = 8080
          050102 200337 http.timeout = 10000
          050102 200337 http.content.limit = 65536
          050102 200337 http.agent = NutchCVS/0.05 (Nutch; http://www.nutch.org/docs/en/bot.html; n
          utch-agent@lists.sourceforge.net)
          050102 200337 fetcher.server.delay = 1000
          050102 200337 http.max.delays = 100
          050102 200338 http://www.dbanotes.net/: setting encoding to GB18030
          050102 200338 CC: found http://creativecommons.org/licenses/by-nc-sa/2.0/ in rdf of http:
          //www.dbanotes.net/
          050102 200338 CC: found text in http://www.dbanotes.net/
          050102 200338 status: 1 pages, 0 errors, 12445 bytes, 1067 ms
          050102 200338 status: 0.9372071 pages/s, 91.12142 kb/s, 12445.0 bytes/page
          050102 200339 Updating crawl.demo/db
          050102 200339 Updating for crawl.demo/segments/20050102200336
          050102 200339 Finishing update
          64,1           7%
          050102 200337 parsing: /u01/nutch/plugins/query-basic/plugin.xml
          050102 200337 logging at INFO
          050102 200337 fetching http://www.dbanotes.net/
          050102 200337 http.proxy.host = null
          050102 200337 http.proxy.port = 8080
          050102 200337 http.timeout = 10000
          050102 200337 http.content.limit = 65536
          050102 200337 http.agent = NutchCVS/0.05 (Nutch; http://www.nutch.org/docs/en/bot.html;
          nutch-agent@lists.sourceforge.net)
          050102 200337 fetcher.server.delay = 1000
          050102 200337 http.max.delays = 100
          ......
          

          之后配置 Tomcat (我的 tomcat 安裝在 /opt/Tomcat) ,

          [root@fc3 nutch]# rm -rf /opt/Tomcat/webapps/ROOT*
          [root@fc3 nutch]# cp nutch*.war /opt/Tomcat/webapps/ROOT.war
          [root@fc3 webapps]# cd /opt/Tomcat/webapps/
          [root@fc3 webapps]# jar xvf ROOT.war
          [root@fc3 webapps]# ../bin/catalina.sh start
          

          瀏覽器中輸入 http://localhost:8080 查看結果(遠程查看需要將 localhost 換成相應的IP):

          nutch web search interface.png

          搜索測試:

          nutch web search result.png

          可以看到,Nutch 亦提供快照功能。下面進行中文搜索測試:

          nutch web Chinese search result.png

          注意結果中的那個“評分詳解”,是個很有意思的功能(Nutch 具有一個鏈接分析模塊),通過這些數據可以進一步理解該算法。

          考慮到帶寬的限制,暫時不對整個Web爬行的方式進行了測試了。值得一提的是,在測試的過程中,nutch 的爬行速度還是不錯的(相對我的糟糕帶寬)。

          Nutch 目前還不支持 PDF(開發中,不夠完善) 與 圖片 等對象的搜索。中文分詞技術還不夠好,通過“評分詳解”可看出,對中文,比如“數據庫管理員”,是分成單獨的字進行處理的。但作為一個開源搜索引擎軟件,功能是可圈可點的。畢竟,主要開發者 Doug Cutting 就是開發 Lucene 的大牛

          參考信息

          posted on 2009-09-24 12:58 小菜毛毛 閱讀(480) 評論(0)  編輯  收藏 所屬分類: 搜索引擎
          主站蜘蛛池模板: 玉环县| 嘉鱼县| 临汾市| 中方县| 满洲里市| 巴里| 石渠县| 大石桥市| 灵寿县| 得荣县| 当雄县| 汪清县| 青冈县| 文昌市| 惠水县| 葵青区| 库车县| 宣化县| 墨玉县| 安国市| 中卫市| 八宿县| 广饶县| 通河县| 昔阳县| 台中市| 龙川县| 兴城市| 永川市| 嵊泗县| 成都市| 新宾| 廉江市| 嘉义县| 安达市| 永修县| 乐至县| 阜新市| 桐乡市| 英山县| 中方县|