· Search engine NUTCH introduction (1) - use nutch

xiaoxiao2021-03-06  41

TUTORIAL

Requirements

Java 1.4.x, Either from sun or ibm on Linux is preferred. Set nutch_java_home to the root of your jvm installation. Apache's Tomcat 4.x. on Win32, Cygwin, for shell support. (If you plan to use cvs on Win32, Be sure to select the cvs and openssh packages when you install, in the "we" net "categories, respectiveness.) Up to a gigabyte of free disk space, a high-speted connection, and an hours or so.

Getting start

First, you need to get a copy of the nutch code from http://www.nutch.org/release/. Unpack the release and connect to its top-level directory. Or, check out the latest Source Code from Cvs and Build It with Ant.

Try The Following Command:

BIN / NUTCH

This Will Display The Documentation for The Nutch Command Script.

Now We're Ready to Crawl. There Are Two Approaches To Crawling:

IntraNet Crawling, With The Crawl Command. WHOLE-Web Crawling, With Much Greater Control, Using The Lower Level INJECT, Generate, Fetch and Updatedb Commands.

IntraN Crawling

Intranet crawling is more appropriate when INTEND TO CRAWL UP TO AROUND ONE MILON PAGES ON A HANDFUL OF Web Servers.

Intranet: Configuration

To Configure Things for intranet crawling you must:

Create a flat file of root urls. For example, to crawl the nutch.org site you might start with a file named urls containing just the Nutch home page. All other Nutch pages should be reachable from this page. The urls file would thus look LIKE: http://www.nutch.org/

Edit the file conf / crawl-urlfilter.txt and replace MY.DOMAIN.NAME with the name of the domain you wish to crawl For example, if you wished to limit the crawl to the nutch.org domain, the line should read.: ^ http: // ([A-Z0-9] * /.) * Nutch.org / this will include any url in the domain nutch.org.

Intranet: Running the Crawl

Once Things Are Configured, Running The Crawl IS Easy. Just Use The Crawl Command. Its Options Include:

-dir dir names the directory to put the crawl in. -depth depth indicates the link depth from the root page that should be crawled. -delay delay determines the number of seconds between accesses to each host. -threads threads determines the number of threads That Will Fetch in Parallel.

For Example, A Typical Call Might BE:

BIN / NUTCH CRAWL URLS -DIR CRAWL.TEST -DEPTH 3> & Crawl.log

Typically one starts testing one's configuration by crawling at low depths, and watching the output to check that desired pages are found. Once one is more confident of the configuration, then an appropriate depth for a full crawl is around 10.

Once Crawling Has Completed, One Can Skip to The Searching Section Below.

WHOLE-web crawling

WHOLE-Web Crawling is designed to Handle Very Large Crawls Which May Take Weeks To Complete, Running ON Multiple Machines.

Whole-Web: Concepts

NUTCH DATA IS of Two Types:

. The web database This contains information about every page known to Nutch, and about links between those pages A set of segments Each segment is a set of pages that are fetched and indexed as a unit Segment data consists of the following types...:

a fetchlist is a file that names a set of pages to be fetched the fetcher output is a set of files containing the fetched pages the index is a Lucene-format index of the fetcher output.In the following examples we will keep our web database in A Directory Named

DB

And our segments in a Directory Named

Segments

:

MKDir DB

Mkdir segments

Whole-Web: boostrapping the web database

The Admin Tool Is Used to Create A New, EMPTY DATABASE:

BIN / NUTCH Admin DB -CREATE

THE

Injector

Adds Urls Into The Database. Let's Inject Urls from The

DMOZ

Open Directory. First We Must Download and Uncompress The File Listing All of The DMOZ PAGE, SO this Will Take a Few Minutes.

Wget http://rdf.dmoz.org/rdf/content.rdf.u8.gz

Gunzip content.rdf.u8.gz

Next we inject a random subset of these pages into the web database. (We use a random subset so that everyone who runs this tutorial does not hammer the same sites.) DMOZ contains around three million URLs. We inject one out of every 3000 SO That We end Up with Around 1000 URLS:

BIN / NUTCH INJECT DB - DMOZFILE Content.rdf.u8 --subset 3000

This Also Takes A Few Minutes, AS It Must Parse The Full File.

Now We Have A Web Database with around 1000 as-yet unfetched urls in it.

WHOLE-Web: fetching

To Fetch, We First Generate A Fetchlist from the Database:

BIN / NUTCH Generate DB Segments

This generates a fetchlist for all of the pages due to be fetched. The fetchlist is placed in a newly created segment directory. The segment directory is named by the time it's created. We save the name of this segment in the shell variable

> S1

:

S1 = `ls -d segments / 2 * | tail -1`

ECHO $ ​​S1

Now We Run The Fetcher on this segment with:

BIN / NUTCH FETCH $ S1WHEN this is Complete, We Update The Database with the results of the fetch:

BIN / NUTCH UPDATEDB DB $ S1

Now The Database Has Entries for All of the page.

Next We Run Five Items of Link Analysis on The Database IN ORDER TO PRIORITI Which Pages To Next Fetch:

BIN / NUTCH Analyze DB 5

NOW We fetch a new segment with the top-scoring 1000 Pages:

BIN / NUTCH Generate DB Segments - Topn 1000

S2 = `ls -d segments / 2 * | tail -1`

Echo $ S2

BIN / NUTCH FETCH $ S2

BIN / NUTCH UPDATEDB DB $ S2

BIN / NUTCH Analyze DB 2

Let's fetch one more round:

BIN / NUTCH Generate DB Segments - Topn 1000

S3 = `ls -d segments / 2 * | tail -1`

Echo $ S3

BIN / NUTCH FETCH $ S3

BIN / NUTCH UPDATEDB DB $ S3

BIN / NUTCH Analyze DB 2

By this point we've fetched a few thousand pages. Let's index them!

Whole-Web: Indexing

To Index Each Segment WE Use T

Index

Command, As Follows:

BIN / NUTCH INDEX $ S1

BIN / NUTCH INDEX $ S2

BIN / NUTCH INDEX $ S3

THEN, BEFORE We can search a set of segments, We need to delete duplicate pages. This is done with:

BIN / NUTCH DEDUP Segments Dedup.TMP

Now We're Ready to Search!

Searching

To search you need to put the nutch war file into your servlet container. (If instead of downloading a Nutch release you checked the sources out of CVS, then you'll first need to build the war file, with the command ant war.)

Assuming You've Unpacked Tomcat As ~ / Local / Tomcat, The Nutch War File May BE Installed with The Commands:

Rm -rf ~ / local / tomcat / webapps / root *

Cp nutch * .war ~ / local / tomcat / webapps / root.war

The WebApp Finds ITS INDEXES in

./segments

, Relative to where you start Tomcat, so, if you've done intranet crawling, connect to your crawl directory, or, if you've done whole-web crawling, do not change directories, and give the command: ~ / local / Tomcat/bin/catalina.sh start

Then Visit

Http: // localhost: 8080 /

And has fun!

转载请注明原文地址:https://www.9cbs.com/read-76109.html

New Post(0)