Apache > Lucene
 

Apache Lucene - Building and Installing the Basic Demo

About this Document

This document is intended as a "getting started" guide to using and running the Lucene demos. It walks you through some basic installation and configuration.

About the Demo

The Lucene command-line demo code consists of an application that demonstrates various functionalities of Lucene and how you can add Lucene to your applications.

Setting your CLASSPATH

First, you should download the latest Lucene distribution and then extract it to a working directory.

You need two JARs: the Lucene JAR, and the Lucene demo JAR. You should see the Lucene JAR file in the directory you created when you extracted the archive -- it should be named something like lucene-core-{version}.jar. You should also see a file called contrib/demo/lucene-demo-{version}.jar.

Put both of these files in your Java CLASSPATH.

Indexing Files

Once you've gotten this far you're probably itching to go. Let's build an index! Assuming you've set your CLASSPATH correctly, just type:

    java org.apache.lucene.demo.IndexFiles -docs {path-to-lucene}/src
This will produce a subdirectory called index which will contain an index of all of the Lucene source code.

To search the index type:

    java org.apache.lucene.demo.SearchFiles
You'll be prompted for a query. Type in a swear word and press the enter key. You'll see that the Lucene developers are very well mannered and get no results. Now try entering the word "string". That should return a whole bunch of documents. The results will page at every tenth result and ask you whether you want more results.

About the code...