Lucene 4 – Getting Started – Demo File Search

Download Lucene and Index Files


# set lucene version
version="4.4.0"

# set base directories
basedir=~/build/lucene/lucene-$version
indexdir=$basedir/data/index

# create direct for Lucene code and binaries
mkdir -p $indexdir
cd $basedir/..

# download lucene
if [ ! -e lucene-$version.zip ]; then
   wget http://apache.imsam.info/lucene/java/$version/lucene-$version.zip
fi;

# extract
unzip -oq lucene-$version.zip

# create directory to save the search index
mkdir -p $basedir/data/index

# start demo indexing
cd lucene-$version

# set classpath
classpath=$classpath:$basedir/demo/lucene-demo-$version.jar
classpath=$classpath:$basedir/core/lucene-core-$version.jar
classpath=$classpath:$basedir/analysis/common/lucene-analyzers-common-$version.jar

# Do index the directory with lucene documentation
java -classpath $classpath org.apache.lucene.demo.IndexFiles -index $indexdir -docs $basedir/docs

# check content of index directory
echo $indexdir
ls -lh  $indexdir

Demo – File Search

# set version
version="4.4.0"

# set base directories
basedir=~/build/lucene/lucene-$version
indexdir=$basedir/data/index

# set classpath
classpath=$classpath:$basedir/demo/lucene-demo-$version.jar
classpath=$classpath:$basedir/core/lucene-core-$version.jar
classpath=$classpath:$basedir/analysis/common/lucene-analyzers-common-$version.jar
classpath=$classpath:$basedir/queryparser/lucene-queryparser-$version.jar

# Do a Test Search against the created index
java -classpath $classpath org.apache.lucene.demo.SearchFiles -index $indexdir
# Enter a keyword, e.g.: lucene
# Press CTRL + C to quit the demo

References

1. http://lucene.apache.org/core/
2. http://lucene.apache.org/core/4_4_0/index.html