DLESE Tools
v1.6.0

org.dlese.dpc.index
Class ResultDoc

java.lang.Object
  extended by org.dlese.dpc.index.ResultDoc
All Implemented Interfaces:
Serializable, Comparable

public class ResultDoc
extends Object
implements Comparable, Serializable

A factory container for a hit that is returned from a SimpleLuceneIndex search. This factory uses the class name provided in the DocWriter.getReaderClass() method to return the DocReader bean that is best suited to read the type of index Document that was returned by the search. Also provides access to a DocumentMap for reading the fields in the lucene Document. This container also provides acces to the Document, the score rank and the document number.

Example that uses JSTL inside a JSP page (assumes result is an instance of ResultDoc and that the DocReader has a method named getFormattedDate()):

The title is: ${result.docMap["title"]}. The date is: ${result.docReader.formattedDate}.

Author:
John Weatherley
See Also:
SimpleLuceneIndex, DocReader, DocumentMap, Serialized Form

Constructor Summary
ResultDoc(org.apache.lucene.document.Document doc)
          Constructs a ResultDoc using the Document provided.
ResultDoc(org.apache.lucene.document.Document d, ResultDocConfig c)
          Constructor for the ResultDoc that is used by the SimpleLuceneIndex class during search result hit list compilation to create a ResultDocCollection.
ResultDoc(ResultDocConfig c, int dn, float s)
          Constructor for the ResultDoc that is used by the SimpleLuceneIndex class during search result hit list compilation to create a ResultDocCollection.
 
Method Summary
 int compareTo(Object obj)
          Compares two ResultDocs for sorting by score.
 Object getAttribute(String key)
          Gets an attribute that has been previously set using SimpleLuceneIndex.setAttribute(String,Object).
 String getComparatorField(String field)
          Deprecated. Sorting should now be done by supplying a Sort object at search time. Sorting on returned ResultDocs is less efficient and may cause OutOfMemory errors on large result sets.
static String getDateStamp()
          Gets a datestamp of the current time formatted for display with logs and output.
 DocumentMap getDocMap()
          Gets a DocumentMap of all field/values contained in the Lucene Document.
 DocReader getDocReader()
          Gets the DocReader used to read the specific Document type that is returned in a search.
 String getDoctype()
          Gets the doctype for this ResultDoc.
 org.apache.lucene.document.Document getDocument()
          Gets the Lucene Document associated with this ResultDoc.
 SimpleLuceneIndex getIndex()
          Gets the index that was searched over.
 LazyDocumentMap getLazyDocMap()
          Gets a LazyDocumentMap of all field/values contained in the Lucene Document.
 String getQuery()
          Gets the query that was used in the search.
 String getReaderClass()
          Gets the readerClass attribute of the ResultDoc object
 float getScore()
          Gets the score assigned to this ResultDoc by the Lucene engine.
static void setDebug(boolean db)
          Sets the debug attribute of the SimpleLuceneIndex object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultDoc

public ResultDoc(ResultDocConfig c,
                 int dn,
                 float s)
Constructor for the ResultDoc that is used by the SimpleLuceneIndex class during search result hit list compilation to create a ResultDocCollection.

Parameters:
c - The configuration for this ResultDoc
dn - The Lucene document number for the Document associated with this ResultDoc.
s - The rank assigned to this result by the Lucene search engine.

ResultDoc

public ResultDoc(org.apache.lucene.document.Document d,
                 ResultDocConfig c)
Constructor for the ResultDoc that is used by the SimpleLuceneIndex class during search result hit list compilation to create a ResultDocCollection.

Parameters:
d - A Lucene Document used to populate this ResultDoc.
c - The configuration for this ResultDoc

ResultDoc

public ResultDoc(org.apache.lucene.document.Document doc)
Constructs a ResultDoc using the Document provided. Use this constructor to wrap a Document inside a ResultDoc.

Parameters:
doc - A Lucene Document used to populate this ResultDoc.
Method Detail

getDocReader

public final DocReader getDocReader()
Gets the DocReader used to read the specific Document type that is returned in a search. Remember that all concrete DocReader classes must have a default constructor with no arguments.

Returns:
The docReader value
See Also:
DocReader

getDocMap

public DocumentMap getDocMap()
Gets a DocumentMap of all field/values contained in the Lucene Document. The text values in each field is stored in the Map as Strings. For example getDocMap.get("title") returns the text that was indexed and stored under the field name "title" for this Document.

Example that uses JSTL inside a JSP page (assumes result is an instance of ResultDoc):

The title is: ${result.docMap["title"]}

Returns:
A Map of all field/values contained in this Document, or null
See Also:
DocumentMap

getLazyDocMap

public LazyDocumentMap getLazyDocMap()
Gets a LazyDocumentMap of all field/values contained in the Lucene Document. The text values in each field is stored in the Map as Strings. For example getDocMap.get("title") returns the text that was indexed and stored under the field name "title" for this Document.

Example that uses JSTL inside a JSP page (assumes result is an instance of ResultDoc):

The title is: ${result.docMap["title"]}

Returns:
A Map of all field/values contained in this Document, or null
See Also:
DocumentMap

getDoctype

public final String getDoctype()
Gets the doctype for this ResultDoc. Assumes there is a stored field in the Lucene document named 'doctype' that contains the docytype name such as "dlese_ims" or "adn."

Returns:
The doctype value

getReaderClass

public final String getReaderClass()
Gets the readerClass attribute of the ResultDoc object

Returns:
The readerClass value

getDocument

public final org.apache.lucene.document.Document getDocument()
Gets the Lucene Document associated with this ResultDoc. If the index has changed since the search was conducted, this method may return an empty or incorrect Document. It is therefore best to read all Documents as soon as possible after a search if the index is being concurrently modified.

Returns:
The Document associated with this ResultDoc.

getComparatorField

public final String getComparatorField(String field)
Deprecated. Sorting should now be done by supplying a Sort object at search time. Sorting on returned ResultDocs is less efficient and may cause OutOfMemory errors on large result sets.

Gets the field content used by LuceneFieldComparator for sorting. Note that it is not possible to re-sort a single set of ResultDocs. To re-sort, first do a fresh search, then a fresh sort over the new ResultDocs using the differnt field.

Parameters:
field - The field name used for sorting
Returns:
The given field content
See Also:
LuceneFieldComparator

getIndex

public final SimpleLuceneIndex getIndex()
Gets the index that was searched over.

Returns:
The index.

getAttribute

public Object getAttribute(String key)
Gets an attribute that has been previously set using SimpleLuceneIndex.setAttribute(String,Object).

Parameters:
key - The key for the attribute
Returns:
The attruibute, or null if none exists under the given key
See Also:
SimpleLuceneIndex.setAttribute(String,Object)

getQuery

public final String getQuery()
Gets the query that was used in the search.

Returns:
The query value

getScore

public final float getScore()
Gets the score assigned to this ResultDoc by the Lucene engine.

Returns:
The score.

compareTo

public final int compareTo(Object obj)
Compares two ResultDocs for sorting by score.

Specified by:
compareTo in interface Comparable
Parameters:
obj - A ResultDoc to compare with this one.
Returns:
Negative is less-than, positive if greater-than or zero if equal.

getDateStamp

public static final String getDateStamp()
Gets a datestamp of the current time formatted for display with logs and output.

Returns:
A datestamp for display purposes.

setDebug

public static void setDebug(boolean db)
Sets the debug attribute of the SimpleLuceneIndex object

Parameters:
db - The new debug value

DLESE Tools
v1.6.0