lux
Class CachingDocReader

java.lang.Object
  extended by lux.CachingDocReader

public class CachingDocReader
extends Object

Reads, parses and caches XML documents from a Lucene index. Assigns Lucene docIDs as Saxon document numbers. This reader is intended to survive for a single query only, and is *not thread-safe*. TODO: a nice optimization would be to maintain a global cache, shared across threads, with some tunable resource-based eviction policy. Not threadsafe.


Constructor Summary
CachingDocReader(net.sf.saxon.s9api.DocumentBuilder builder, net.sf.saxon.Configuration config, IndexConfiguration indexConfig)
          Create a CachingDocReader that will use the provided objects to read and parse XML documents.
 
Method Summary
 void clear()
          Clears all cached documents.
 net.sf.saxon.s9api.XdmNode get(int docID, org.apache.lucene.index.IndexReader reader)
          Reads the document with the given id.
 long getBuildTime()
           
 int getCacheHits()
           
 int getCacheMisses()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingDocReader

public CachingDocReader(net.sf.saxon.s9api.DocumentBuilder builder,
                        net.sf.saxon.Configuration config,
                        IndexConfiguration indexConfig)
Create a CachingDocReader that will use the provided objects to read and parse XML documents.

Parameters:
builder - will be used to construct XML documents as XdmNodes
config - assigns the proper document ID to each constructed document
indexConfig - supplies the names of the xml storage and uri fields
Method Detail

get

public net.sf.saxon.s9api.XdmNode get(int docID,
                                      org.apache.lucene.index.IndexReader reader)
                               throws IOException
Reads the document with the given id. If cached, the cached copy is returned. Otherwise the document is read from the index. If the document does not exist in the index, or has been deleted, results are not well-defined: see IndexReader.

Parameters:
docID - the id of the document to read
reader - the Lucene index reader
Returns:
the document, as a Saxon XdmNode
Throws:
IOException - if there is some sort of low-level problem with the index
LuxException - if there is an error building the document that has been retrieved

getCacheHits

public int getCacheHits()
Returns:
the number of items retrieved from the cache

getCacheMisses

public int getCacheMisses()
Returns:
the number of items retrieved and added to the cache

getBuildTime

public long getBuildTime()
Returns:
the total time spent building documents (in nanoseconds). This includes time spent parsing and constructing a Saxon NodeInfo/XdmNode.

clear

public void clear()
Clears all cached documents.



Copyright © 2013. All Rights Reserved.