<inputvalue="lucene.apache.org"name="sitesearch"type="hidden"><inputonFocus="getBlank (this, 'Search the site with google');"size="25"name="q"id="query"type="text"value="Search the site with google">
Most of the functionality lies in <spanclass="codefrag">results.jsp</span>. Much of it is for paging the search
results, which we'll not cover here as it's commented well enough. The first thing in this page is
the actual imports for the Lucene classes and Lucene demo classes. These classes are loaded from
the jars included in the <spanclass="codefrag">WEB-INF/lib</span> directory in the <spanclass="codefrag">luceneweb.war</span> file.
</p>
<p>
You'll notice that this file includes the same header and footer as <spanclass="codefrag">index.jsp</span>. From
there it constructs an <spanclass="codefrag">IndexSearcher</span> with the
<spanclass="codefrag">indexLocation</span> that was specified in <spanclass="codefrag">configuration.jsp</span>. If there is an
error of any kind in opening the index, it is displayed to the user and the boolean flag
<spanclass="codefrag">error</span> is set to tell the rest of the sections of the jsp not to continue.
</p>
<p>
From there, this jsp attempts to get the search criteria, the start index (used for paging) and the
maximum number of results per page. If the maximum results per page is not set or not valid then it
and the start index are set to default values. If only the start index is invalid it is set to a
default value. If the criteria isn't provided then a servlet error is thrown (it is assumed that
this is the result of url tampering or some form of browser malfunction).
</p>
<p>
The jsp moves on to construct a <spanclass="codefrag">StandardAnalyzer</span> to
analyze the search text. This matches the analyzer used during indexing (<spanclass="codefrag">IndexHTML</span>), which is generally
recommended. This is passed to the <spanclass="codefrag">QueryParser</span> along with the
criteria to construct a <spanclass="codefrag">Query</span>
object. You'll also notice the string literal <spanclass="codefrag">"contents"</span> included. This specifies
that the search should cover the <spanclass="codefrag">contents</span> field and not the <spanclass="codefrag">title</span>,
<spanclass="codefrag">url</span> or some other field in the indexed documents. If there is any error in
constructing a <spanclass="codefrag">Query</span> object an
error is displayed to the user.
</p>
<p>
In the next section of the jsp the <spanclass="codefrag">IndexSearcher</span> is asked to search
given the query object. The results are returned in a collection called <spanclass="codefrag">hits</span>. If the
length property of the <spanclass="codefrag">hits</span> collection is 0 (meaning there were no results) then an
error is displayed to the user and the error flag is set.
</p>
<p>
Finally the jsp iterates through the <spanclass="codefrag">hits</span> collection, taking the current page into
account, and displays properties of the <spanclass="codefrag">Document</span> objects we talked about in
the first walkthrough. These objects contain "known" fields specific to their indexer (in this case
<spanclass="codefrag">IndexHTML</span> constructs a document
with "url", "title" and "contents").
</p>
<p>
Please note that in a real deployment of Lucene, it's best to instantiate <spanclass="codefrag">IndexSearcher</span> and <spanclass="codefrag">QueryParser</span> once, and then
share them across search requests, instead of re-instantiating per search request.
There are additional sources used by the web app that were not specifically covered by either
walkthrough. For example the HTML parser, the <spanclass="codefrag">IndexHTML</span> class and <spanclass="codefrag">HTMLDocument</span> class. These are very
similar to the classes covered in the first example, with properties specific to parsing and
indexing HTML. This is beyond our scope; however, by now you should feel like you're "getting
started" with Lucene.
</p>
</div>
<aname="N100E1"></a><aname="Where to go from here? (everyone!)"></a>
<h2class="boxed">Where to go from here? (everyone!)</h2>
<divclass="section">
<p>
There are a number of things this demo doesn't do or doesn't do quite right. For instance, you may
have noticed that documents in the root context are unreachable (unless you reconfigure Tomcat to
support that context or redirect to it), anywhere where the directory doesn't quite match the
context mapping, you'll have a broken link in your results. If you want to index non-local files or
have some other needs this isn't supported, plus there may be security issues with running the
indexing application from your webapps directory. There are a number of things left for you the
developer to do.
</p>
<p>
In time some of these things may be added to Lucene as features (if you've got a good idea we'd love
to hear it!), but for now: this is where you begin and the search engine/indexer ends. Lastly, one
would assume you'd want to follow the above advice and customize the application to look a little
more fancy than black on white with "Lucene Template" at the top. We'll see you on the Lucene
Users' or Developers' <ahref="mailinglists.html">mailing lists</a>!
</p>
</div>
<aname="N100F1"></a><aname="When to contact the Author"></a>
<h2class="boxed">When to contact the Author</h2>
<divclass="section">
<p>
Please resist the urge to contact the authors of this document (without bribes of fame and fortune
attached). First contact the <ahref="mailinglists.html">mailing lists</a>, taking care to <ahref="http://www.catb.org/~esr/faqs/smart-questions.html">Ask Questions The Smart Way</a>.
Certainly you'll get the most help that way as well. That being said, feedback, and modifications
to this document and samples are ever so greatly appreciated. They are just best sent to the lists