UNC
School of Information and Library Science
INLS760 – Web Databases, Spring 2007
INLS 760

Main Page

Announcements

Calendar/Notes

Assignments

Links

Course Policies

Grades

Getting and Using the Lucene Search Engine in Linux

This is a brief outline of how to get, install, and use the Lucene search engine in Linux.

Note: You must already have java installed on your Linux machine.


Get the .jar files

Lucene is written in Java. For basic usage, we can use the pre-compiled .jar files available from either the Apache Lucene web site, or one of the mirror sites such as ibiblio. As of this writing, lucene-2.1.0.tar.gz is a gzipped-tar file with the most recent .jar files.

In your Linux account, create a directory called lucene. Download the lucene-2.1.0.tar.gz file and place it in the lucene directory.

Unpack the .tar.gz file in the lucene directory:

   tar xvzf lucene-2.1.0.tar.gz
This should create a lucene-2.1.0 directory that contains the Lucene .tar files. cd into this directory and make sure these two files are present:
   lucene-core-2.1.0.jar
   lucene-demos-2.1.0.jar

Set your CLASSPATH

Since Lucene is written in Java, you must set the CLASSPATH environment variable so that Java will know where to find the Lucene classes. If you are using the bash shell, the following command can be used (replace youraccount with your account login name):

Note: you can copy and paste this command as-is into a bash shell. However, if you are TYPING it, you should type it as ONE line and NOT INCLUDE the '\' characters at the end of the first two lines.

export CLASSPATH=$CLASSPATH:\
~youraccount/lucene/lucene-2.1.0/lucene-core-2.1.0.jar:\
~youraccount/lucene/lucene-2.1.0/lucene-demos-2.1.0.jar 

Test it

Select a directory that has files that you would like to index.

cd to that directory and type the following command:

   java org.apache.lucene.demo.IndexFiles .
This will create an index of the files in that directory and its subdirectories.

To search the index, type:

   java org.apache.lucene.demo.SearchFiles
And type in a query at the prompt.

More details

For more details of how these programs work, see Building and Installing the Basic Demo on the Apache Lucene web site.