public class ResultDoc
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable
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}.
SimpleLuceneIndex
,
DocReader
,
DocumentMap
,
Serialized FormConstructor and Description |
---|
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 . |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(java.lang.Object obj)
Compares two ResultDocs for sorting by score.
|
java.lang.Object |
getAttribute(java.lang.String key)
Gets an attribute that has been previously set using
SimpleLuceneIndex.setAttribute(String,Object) . |
java.lang.String |
getComparatorField(java.lang.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 java.lang.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. |
java.lang.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 . |
java.lang.String |
getQuery()
Gets the query that was used in the search.
|
java.lang.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
|
public ResultDoc(ResultDocConfig c, int dn, float s)
SimpleLuceneIndex
class
during search result hit list compilation to create a ResultDocCollection
.c
- The configuration for this ResultDocdn
- The Lucene document number for the Document
associated with
this ResultDoc.s
- The rank assigned to this result by the Lucene search engine.public ResultDoc(org.apache.lucene.document.Document d, ResultDocConfig c)
SimpleLuceneIndex
class
during search result hit list compilation to create a ResultDocCollection
.d
- A Lucene Document
used to populate this ResultDoc.c
- The configuration for this ResultDocpublic ResultDoc(org.apache.lucene.document.Document doc)
Document
provided. Use this
constructor to wrap a Document
inside a ResultDoc.doc
- A Lucene Document
used to populate this ResultDoc.public final DocReader getDocReader()
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.DocReader
public DocumentMap getDocMap()
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"]}
DocumentMap
public LazyDocumentMap getLazyDocMap()
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"]}
DocumentMap
public final java.lang.String getDoctype()
public final java.lang.String getReaderClass()
public final org.apache.lucene.document.Document getDocument()
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.Document
associated with this ResultDoc.public final java.lang.String getComparatorField(java.lang.String field)
Sort
object at
search time. Sorting on returned ResultDocs is less efficient and may cause OutOfMemory errors on large
result sets.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.field
- The field name used for sortingLuceneFieldComparator
public final SimpleLuceneIndex getIndex()
public java.lang.Object getAttribute(java.lang.String key)
SimpleLuceneIndex.setAttribute(String,Object)
.key
- The key for the attributeSimpleLuceneIndex.setAttribute(String,Object)
public final java.lang.String getQuery()
public final float getScore()
public final int compareTo(java.lang.Object obj)
compareTo
in interface java.lang.Comparable
obj
- A ResultDoc to compare with this one.public static final java.lang.String getDateStamp()
public static void setDebug(boolean db)
db
- The new debug value