Apache > Lucene
 

Apache Lucene - Building and Installing the Basic Demo

About this Document

This document is intended as a "getting started" guide to installing and running the Lucene web application demo. This guide assumes that you have read the information in the previous two examples. We'll use Tomcat as our reference web container. These demos should work with nearly any container, but you may have to adapt them appropriately.

About the Demos

The Lucene Web Application demo is a template web application intended for deployment on Tomcat or a similar web container. It's NOT designed as a "best practices" implementation by ANY means. It's more of a "hello world" type Lucene Web App. The purpose of this application is to demonstrate Lucene. With that being said, it should be relatively simple to create a small searchable website in Tomcat or a similar application server.

Indexing Files

Once you've gotten this far you're probably itching to go. Let's start by creating the index you'll need for the web examples. Since you've already set your CLASSPATH in the previous examples, all you need to do is type:

    java org.apache.lucene.demo.IndexHTML -create -index {index-dir} ..
You'll need to do this from a (any) subdirectory of your {tomcat}/webapps directory (make sure you didn't leave off the .. or you'll get a null pointer exception). {index-dir} should be a directory that Tomcat has permission to read and write, but is outside of a web accessible context. By default the webapp is configured to look in /opt/lucene/index for this index.

Deploying the Demos

Located in your distribution directory you should see a war file called luceneweb.war. If you're working with a Subversion checkout, this will be under the build subdirectory. Copy this to your {tomcat-home}/webapps directory. You may need to restart Tomcat.

Configuration

From your Tomcat directory look in the webapps/luceneweb subdirectory. If it's not present, try browsing to http://localhost:8080/luceneweb (which causes Tomcat to deploy the webapp), then look again. Edit a file called configuration.jsp. Ensure that the indexLocation is equal to the location you used for your index. You may also customize the appTitle and appFooter strings as you see fit. Once you have finished altering the configuration you may need to restart Tomcat. You may also wish to update the war file by typing jar -uf luceneweb.war configuration.jsp from the luceneweb subdirectory. (The -u option is not available in all versions of jar. In this case recreate the war file).

Running the Demos

Now you're ready to roll. In your browser set the url to http://localhost:8080/luceneweb enter test and the number of items per page and press search.

You should now be looking either at a number of results (provided you didn't erase the Tomcat examples) or nothing. If you get an error regarding opening the index, then you probably set the path in configuration.jsp incorrectly or Tomcat doesn't have permissions to the index (or you skipped the step of creating it). Try other search terms. Depending on the number of items per page you set and results returned, there may be a link at the bottom that says More Results>>; clicking it takes you to subsequent pages.

About the code...

If you want to know more about how this web app works or how to customize it then read on>>>.