Class DocReader

java.lang.Object
org.dlese.dpc.index.reader.DocReader
Direct Known Subclasses:
FileIndexingServiceDocReader, HarvestLogReader, SimpleDocReader, WebLogReader

public abstract class DocReader extends Object
An abstract bean for accessing the data stored in the Lucene Documents that are returned from a search. All concrete DocReader classes must implement a default no-argument constructor so that they may be created automatically by the factory ResultDoc.getDocReader(). In addition, the index writer corresponding to the concrete reader must implement the DocWriter.getReaderClass() method.
Author:
John Weatherley
See Also:
  • Field Details

    • doc

      protected org.apache.lucene.document.Document doc
      The Lucene Document that is being read.
    • score

      protected float score
      The Lucene score assigned to the Document, or -1 if none available.
    • conf

      protected ResultDocConfig conf
      The index that was searched over.
    • resultDoc

      protected ResultDoc resultDoc
  • Constructor Details

    • DocReader

      protected DocReader(org.apache.lucene.document.Document myDoc)
      Constructor that may be used programatically to wrap a reader around a Lucene Document that was created by a DocWriter.
      Parameters:
      myDoc - Gets the Lucene Document that is being read by this DocReader.
      See Also:
    • DocReader

      protected DocReader()
      Constructor that initializes an empty DocReader.
  • Method Details

    • getReaderType

      public abstract String getReaderType()
      Gets a String describing the reader type. This may be used in (Struts) beans to determine which type of reader is available for a given search result and thus what data is available for display in the UI. The reader type implies which getter methods are available.
      Returns:
      The readerType value.
    • init

      public abstract void init()
      An init method that may be used by concrete classes to initialize variables and resources as needed.
    • doInit

      public final void doInit(org.apache.lucene.document.Document myDoc, ResultDoc resultDoc, float myScore, ResultDocConfig myConf)
      Called by ResultDoc at search time to initialize a new instance of a DocReader.
      Parameters:
      myDoc - The Lucene Document
      myScore - The Lucene score asigned to this hit
      myConf - The config available to the doc reader
    • 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:
    • 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:
    • setDoc

      protected void setDoc(org.apache.lucene.document.Document myDoc)
      Sets the Lucene Document that is being read by this DocReader.
      Parameters:
      myDoc - The new doc value
    • getScore

      public String getScore()
      Gets the Lucene score for the Document, or -1 if none available.
      Returns:
      The score or -1 if not available.
    • getDocument

      public org.apache.lucene.document.Document getDocument()
      Gets the Lucene Document associated with this DocReader.
      Returns:
      A Lucene Document.
    • getIndex

      public SimpleLuceneIndex getIndex()
      Gets the index that was searched over to produce the resulting hit.
      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:
    • getRepositoryManager

      public RepositoryManager getRepositoryManager()
      Gets the RepositoryManager associated with this DocReader or null if not available. Assumes the RepositoryManager has been set as attribute 'repositoryManager' in the SimpleLuceneIndex that was searched.
      Returns:
      The repositoryManager value
    • getQuery

      public String getQuery()
      Gets the query that was used in the search.
      Returns:
      The query value