Apache Nutch is an extensible and scalable web crawler
Adding some continuous crawl goodies to the crawl script NUTCH-2036
Julien Niocheb14a6d53a436
diff --git a/CHANGES.txt b/CHANGES.txtindex 0e29e704f..22ac2b180 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,8 @@ Nutch Change LogNutch Current Development 1.11-SNAPSHOT+* NUTCH-2036 Adding some continuous crawl goodies to the crawl script (jorge, snagel)+* NUTCH-2039 Relevance based scoring filter (Sujen Shah, lewismc via mattmann)* NUTCH-2037 Job endpoint to support Indexing from the REST API (Sujen Shah via mattmann)diff --git a/src/bin/crawl b/src/bin/crawlindex 4d6e954f6..57475b8d4 100644--- a/src/bin/crawl+++ b/src/bin/crawl@@ -14,20 +14,48 @@# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.-#-# Usage: crawl [-i|--index] [-D "key=value"] <Seed Dir> <Crawl Dir> <Num Rounds>+#+# Usage: crawl [-i|--index] [-D "key=value"] [-w|--wait] <Seed Dir> <Crawl Dir> <Num Rounds># -i|--index Indexes crawl results into a configured indexer+# -w|--wait NUMBER[SUFFIX] Time to wait before generating a new segment when no URLs+# are scheduled for fetching. Suffix can be: s for second,+# m for minute, h for hour and d for day. If no suffix is+# specified second is used by default.# -D A Java property to pass to Nutch calls# Seed Dir Directory in which to look for a seeds file# Crawl Dir Directory where the crawl/link/segments dirs are saved# Num Rounds The number of rounds to run this crawl for#-#-# UNLIKE THE NUTCH ALL-IN-ONE-CRAWL COMMAND THIS SCRIPT DOES THE LINK INVERSION AND+#+# UNLIKE THE NUTCH ALL-IN-ONE-CRAWL COMMAND THIS SCRIPT DOES THE LINK INVERSION AND# INDEXING FOR EACH SEGMENTINDEXFLAG=falseJAVA_PROPERTIES=""+WAIT=-1 # don't wait if there are no URLs to fetch++function __to_seconds() {+ NUMBER=$(echo $1 | tr -dc '0-9')+ MODIFIER=$(echo $1 | tr -dc '[^s|h|m|d]]')++ case $MODIFIER in+ m|M)+ SECONDS=`expr $NUMBER \* 60`+ ;;+ h|H)+ SECONDS=`expr $NUMBER \* 120`+ ;;+ d|D)+ SECONDS=`expr $NUMBER \* 86400`+ ;;+ s|S|*)+ SECONDS=$NUMBER+ ;;+ esac++ echo $SECONDS+}+while [[ $# > 0 ]]docase $1 in@@ -39,6 +67,10 @@ doJAVA_PROPERTIES="-D${2} ${JAVA_PROPERTIES}"shift 2;;+ -w|--wait)+ WAIT="${2}"+ shift 2+ ;;*)break;;@@ -46,9 +78,13 @@ dodoneif [[ $# != 3 ]]; then- echo "Usage: crawl [-i|--index] [-D \"key=value\"] <Seed Dir> <Crawl Dir> <Num Rounds>"+ echo "Usage: crawl [-i|--index] [-D \"key=value\"] [-w|--wait] <Seed Dir> <Crawl Dir> <Num Rounds>"echo -e "\t-i|--index\tIndexes crawl results into a configured indexer"echo -e "\t-D\t\tA Java property to pass to Nutch calls"+ echo -e "\t-w|--wait\tNUMBER[SUFFIX] Time to wait before generating a new segment when no URLs"+ echo -e "\t\t\tare scheduled for fetching. Suffix can be: s for second,"+ echo -e "\t\t\tm for minute, h for hour and d for day. If no suffix is"+ echo -e "\t\t\tspecified second is used by default."echo -e "\tSeed Dir\tDirectory in which to look for a seeds file"echo -e "\tCrawl Dir\tDirectory where the crawl/link/segments dirs are saved"echo -e "\tNum Rounds\tThe number of rounds to run this crawl for"@@ -59,6 +95,12 @@ SEEDDIR="$1"CRAWL_PATH="$2"LIMIT="$3"+# convert wait time to seconds for compatibility reasons+if [ "$WAIT" != "-1" ]; then+ WAIT=$( __to_seconds "$WAIT" )+ echo "Time to wait (--wait) = $WAIT sec."+fi+############################################## MODIFY THE PARAMETERS BELOW TO YOUR NEEDS ##############################################@@ -91,11 +133,11 @@ if [ -f "${bin}"/../*nutch*.job ]; thenmode=distributedfi-# note that some of the options listed here could be set in the-# corresponding hadoop site xml param file+# note that some of the options listed here could be set in the+# corresponding hadoop site xml param filecommonOptions="-D mapred.reduce.tasks=$numTasks -D mapred.child.java.opts=-Xmx1000m -D mapred.reduce.tasks.speculative.execution=false -D mapred.map.tasks.speculative.execution=false -D mapred.compress.map.output=true"- # check that hadoop can be found on the path+ # check that hadoop can be found on the pathif [ $mode = "distributed" ]; thenif [ $(which hadoop | wc -l ) -eq 0 ]; thenecho "Can't find Hadoop executable. Add HADOOP_HOME/bin to the path or run in local mode."@@ -126,9 +168,8 @@ function __bin_nutch {echo "Injecting seed URLs"__bin_nutch inject "$CRAWL_PATH"/crawldb "$SEEDDIR"-# main loop : rounds of generate - fetch - parse - update-for ((a=1; a <= LIMIT ; a++))+for ((a=1; ; a++))doif [ -e ".STOP" ]then@@ -136,7 +177,15 @@ dobreakfi- echo `date` ": Iteration $a of $LIMIT"+ if [ $LIMIT -ne -1 ]; then+ if [ $a -gt $LIMIT ]; then+ echo `date` ": Finished loop with $LIMIT iterations"+ break+ fi+ echo `date` ": Iteration $a of $LIMIT"+ else+ echo `date` ": Iteration $a"+ fiecho "Generating a new segment"generate_args=($commonOptions "$CRAWL_PATH"/crawldb "$CRAWL_PATH"/segments -topN $sizeFetchlist -numFetchers $numSlaves -noFilter)@@ -147,8 +196,15 @@ do: # ok: no errorelif [ $RETCODE -eq 1 ]; thenecho "Generate returned 1 (no new segments created)"- echo "Escaping loop: no more URLs to fetch now"- break++ if [ "$WAIT" -ne -1 ]; then+ echo "Waiting for $WAIT sec. ..."+ sleep $WAIT+ continue+ else+ echo "Escaping loop: no more URLs to fetch now"+ break+ fielseecho "Error running:"echo " $bin/nutch generate ${generate_args[@]}"@@ -165,7 +221,7 @@ doelseSEGMENT=`hadoop fs -ls "$CRAWL_PATH"/segments/ | grep segments | sed -e "s/\//\\n/g" | egrep 20[0-9]+ | sort -n | tail -n 1`fi-+echo "Operating on segment : $SEGMENT"# fetching the segment@@ -174,7 +230,7 @@ do# parsing the segmentecho "Parsing : $SEGMENT"- # enable the skipping of records for the parsing so that a dodgy document+ # enable the skipping of records for the parsing so that a dodgy document# so that it does not fail the full taskskipRecordsOptions="-D mapred.skip.attempts.to.start.skipping=2 -D mapred.skip.map.max.skip.records=1"__bin_nutch parse $commonOptions $skipRecordsOptions "$CRAWL_PATH"/segments/$SEGMENT@@ -183,7 +239,7 @@ doecho "CrawlDB update"__bin_nutch updatedb $commonOptions "$CRAWL_PATH"/crawldb "$CRAWL_PATH"/segments/$SEGMENT-# note that the link inversion - indexing routine can be done within the main loop+# note that the link inversion - indexing routine can be done within the main loop# on a per segment basisecho "Link inversion"__bin_nutch invertlinks "$CRAWL_PATH"/linkdb "$CRAWL_PATH"/segments/$SEGMENT@@ -194,13 +250,13 @@ doif $INDEXFLAG; thenecho "Indexing $SEGMENT to index"__bin_nutch index $JAVA_PROPERTIES "$CRAWL_PATH"/crawldb -linkdb "$CRAWL_PATH"/linkdb "$CRAWL_PATH"/segments/$SEGMENT-+echo "Cleaning up index if possible"__bin_nutch clean $JAVA_PROPERTIES "$CRAWL_PATH"/crawldbelseecho "Skipping indexing ..."fi-+######################################################## The following commands fall into WebGraph territory# and should be uncommented based on your requirements@@ -223,4 +279,3 @@ dodoneexit 0-