lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Carlson <carl...@bookandhammer.com>
Subject Dev Release of SearchBean
Date Tue, 21 May 2002 06:56:00 GMT
I have started to convert my very quick and dirty SearchBean to a more
useful and generic bean.

It's designed to be used with a JSP page (or other presentation environment)
and wrap many of the common Lucene functions.

It supports:
1) Paging
2) Iterating through the search results a HitsIterator
3) Sorting by a field


It is organized into 5 classes

SearchBean - class used directly by outside callers
HitsIterator - Wraps the Hits results to support an iterator, sorting and
paging
SortedField - The field level data from the index used to quickly get the
data for sorting
IndividualHit - Class to use wrap a Hit (score and id) for use in sorting
CompareDocsByField - comparitor for IndividualHit used for sorting.

Note: I think this would go faster if I didn't create the IndividualHit for
each result, but I couldn't find a multiple array sorting algorithm and this
was easier. The speed loss is about 300ms for 15K results (the size of the
total docs in the index shouldn't make a difference).


Usage: 
    SearchBean sb = new SearchBean(index);
    HitsIterator hi = sb.search("metal");
    while (hi.hasNext()){
       Document doc = hi.next();
    }
    hi.getPageCount();
    sb.getSearchTime();

I am planning on adding a QueryType class to track query preferences such as
Directory, analyzer, and default field. This way you can setup a QueryType
at startup and just pass in the QueryType by name and the query String and
you're done.


This passes the initial unit test case, but sorting has not been tested in
this code yet and was somewhat rewritten in organizing the code for general
release so it is development level code.

I have also supplied a Servlet that shows how to load some indexes for use
in field level sorting in web based apps.

NOTE: To compile, you will have to make a change to the Hits class to make
the id field public (it's private). Hopefully we will make these changes
after 1.2 is released.
Also, if you are going to compile the Servlet, you will need the Servlet.jar
(from tomcat is what I use).
Finally, you will need to also have Junit in your classpath. The easiest way
to do this, is just put these three jars into the lib directory and then use
the ant build script.

Any comments, criticisms or suggestions are welcome.
I think something like this could help people get up and working with Lucene
very quickly.

Now we just have to get the Indexing part easier.

--Peter


--
To unsubscribe, e-mail:   <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>


Mime
View raw message