Package org.dlese.dpc.index
Class ResultDoc
java.lang.Object
org.dlese.dpc.index.ResultDoc
- All Implemented Interfaces:
Serializable,Comparable
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:
-
Constructor Summary
ConstructorsConstructorDescriptionResultDoc(org.apache.lucene.document.Document doc) Constructs a ResultDoc using theDocumentprovided.ResultDoc(org.apache.lucene.document.Document d, ResultDocConfig c) Constructor for the ResultDoc that is used by theSimpleLuceneIndexclass during search result hit list compilation to create a.invalid reference
ResultDocCollectionResultDoc(ResultDocConfig c, int dn, float s) Constructor for the ResultDoc that is used by theSimpleLuceneIndexclass during search result hit list compilation to create a.invalid reference
ResultDocCollection -
Method Summary
Modifier and TypeMethodDescriptionfinal intCompares two ResultDocs for sorting by score.getAttribute(String key) Gets an attribute that has been previously set usingSimpleLuceneIndex.setAttribute(String,Object).final StringgetComparatorField(String field) Deprecated.static final StringGets a datestamp of the current time formatted for display with logs and output.Gets aDocumentMapof all field/values contained in the LuceneDocument.final DocReaderGets theDocReaderused to read the specificDocumenttype that is returned in a search.final StringGets the doctype for this ResultDoc.final org.apache.lucene.document.DocumentGets the LuceneDocumentassociated with this ResultDoc.final SimpleLuceneIndexgetIndex()Gets the index that was searched over.Gets aLazyDocumentMapof all field/values contained in the LuceneDocument.final StringgetQuery()Gets the query that was used in the search.final StringGets the readerClass attribute of the ResultDoc objectfinal floatgetScore()Gets the score assigned to this ResultDoc by the Lucene engine.static voidsetDebug(boolean db) Sets the debug attribute of the SimpleLuceneIndex object
-
Constructor Details
-
ResultDoc
Constructor for the ResultDoc that is used by theSimpleLuceneIndexclass during search result hit list compilation to create a.invalid reference
ResultDocCollection- Parameters:
c- The configuration for this ResultDocdn- The Lucene document number for theDocumentassociated with this ResultDoc.s- The rank assigned to this result by the Lucene search engine.
-
ResultDoc
Constructor for the ResultDoc that is used by theSimpleLuceneIndexclass during search result hit list compilation to create a.invalid reference
ResultDocCollection- Parameters:
d- A LuceneDocumentused to populate this ResultDoc.c- The configuration for this ResultDoc
-
ResultDoc
public ResultDoc(org.apache.lucene.document.Document doc) Constructs a ResultDoc using theDocumentprovided. Use this constructor to wrap aDocumentinside a ResultDoc.- Parameters:
doc- A LuceneDocumentused to populate this ResultDoc.
-
-
Method Details
-
getDocReader
Gets theDocReaderused to read the specificDocumenttype 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:
-
getDocMap
Gets aDocumentMapof all field/values contained in the LuceneDocument. 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:
-
getLazyDocMap
Gets aLazyDocumentMapof all field/values contained in the LuceneDocument. 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:
-
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
Gets the readerClass attribute of the ResultDoc object- Returns:
- The readerClass value
-
getDocument
public final org.apache.lucene.document.Document getDocument()Gets the LuceneDocumentassociated 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
Documentassociated with this ResultDoc.
-
getComparatorField
Deprecated.Sorting should now be done by supplying aSortobject at search time. Sorting on returned ResultDocs is less efficient and may cause OutOfMemory errors on large result sets.Gets the field content used byLuceneFieldComparatorfor 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:
-
getIndex
Gets the index that was searched over.- Returns:
- The index.
-
getAttribute
Gets an attribute that has been previously set usingSimpleLuceneIndex.setAttribute(String,Object).- Parameters:
key- The key for the attribute- Returns:
- The attruibute, or null if none exists under the given key
- See Also:
-
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
Compares two ResultDocs for sorting by score.- Specified by:
compareToin interfaceComparable- Parameters:
obj- A ResultDoc to compare with this one.- Returns:
- Negative is less-than, positive if greater-than or zero if equal.
-
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
-
Sortobject at search time.