views:

529

answers:

2

I haven't looked at Nutch for a year or so and it looks like it has changed significantly. The documentation on re-crawling isn't clear. What is the best way to update an existing Nutch index?

+1  A: 

This script is based loosely on the one in the Nutch FAQ, which didn't work for me at first:

#!/bin/sh
#
# Automate crawling my site
#
crawldir=./crawl
urldir=./urls
NUTCH_HOME=${NUTCH_HOME:=.}

nutch=$NUTCH_HOME/bin/nutch

# Make sure the crawl directories exist
mkdir -p $crawldir/crawldb $crawldir/segments $crawldir/linkdb

# Inject the initial urls
$nutch inject $crawldir/crawldb $urldir

depth=1
while(true) ; do
  echo "beginning crawl at depth $depth"
  echo "-generate"
  $nutch generate $crawldir/crawldb $crawldir/segments
  if [ $? -ne 0 ] ; then
    echo "finishing at depth $depth - no more urls"
    break
  fi

  segment=`/bin/ls -rtd $crawldir/segments/*|tail -1`

  echo "$nutch fetch $segment"
  $nutch fetch $segment
  if [ $? -ne 0 ] ; then
    echo "fetch failed at depth $depth, deleting segment"
    rm -rf $segment
    continue;
  fi

  echo "$nutch updatedb $crawldir/crawldb $segment"
  $nutch updatedb $crawldir/crawldb $segment
  depth=`expr $depth + 1`
done

echo "$nutch mergesegs $crawldir/MERGEDsegs $crawldir/segments/*"
$nutch mergesegs $crawldir/MERGEDsegs $crawldir/segments/*
if [ $? -eq 0 ] ; then
  rm -rf $crawldir/segments/*
  mv $crawldir/MERGEDsegs/* $crawldir/segments
  rmdir $crawldir/MERGEDsegs
else
  echo "Something went wrong"
  exit
fi

echo "$nutch invertlinks $crawldir/linkdb -dir $crawldir/segments"
$nutch invertlinks $crawldir/linkdb -dir $crawldir/segments

echo "$nutch index $crawldir/NEWindexes $crawldir/crawldb $crawldir/linkdb $crawldir/segments/*"
$nutch index $crawldir/NEWindexes $crawldir/crawldb $crawldir/linkdb \
$crawldir/segments/*

echo "$nutch dedup $crawldir/NEWindexes"
$nutch dedup $crawldir/NEWindexes

echo "$nutch merge $crawldir/MERGEDindexes $crawldir/NEWindexes"
$nutch merge $crawldir/MERGEDindexes $crawldir/NEWindexes

mv $crawldir/index $crawldir/OLDindexes
mv $crawldir/MERGEDindexes $crawldir/index
Paul Tomblin
A: 

We are using nutch in combination with solr. Our Nutch index is appr. 80 MB conatin arround 5000 Websites. So far, the best way to recrawl is to delete the index and create it from scratch.

svenkubiak