org.apache.jackrabbit.core.query.lucene
Class JackrabbitIndexReader

java.lang.Object
  extended by org.apache.lucene.index.IndexReader
      extended by org.apache.lucene.index.FilterIndexReader
          extended by org.apache.jackrabbit.core.query.lucene.JackrabbitIndexReader
All Implemented Interfaces:
HierarchyResolver, MultiIndexReader, ReleaseableIndexReader

public final class JackrabbitIndexReader
extends org.apache.lucene.index.FilterIndexReader
implements HierarchyResolver, MultiIndexReader

JackrabbitIndexReader wraps an index reader and releases the underlying reader when a client calls IndexReader.close() on this reader. This allows reusing of the underlying index reader instance.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.lucene.index.FilterIndexReader
org.apache.lucene.index.FilterIndexReader.FilterTermDocs, org.apache.lucene.index.FilterIndexReader.FilterTermEnum, org.apache.lucene.index.FilterIndexReader.FilterTermPositions
 
Nested classes/interfaces inherited from class org.apache.lucene.index.IndexReader
org.apache.lucene.index.IndexReader.FieldOption
 
Field Summary
 
Fields inherited from class org.apache.lucene.index.FilterIndexReader
in
 
Fields inherited from class org.apache.lucene.index.IndexReader
hasChanges
 
Constructor Summary
JackrabbitIndexReader(org.apache.lucene.index.IndexReader in)
          Creates a new JackrabbitIndexReader.
 
Method Summary
 org.apache.jackrabbit.core.query.lucene.ForeignSegmentDocId createDocId(NodeId id)
          Creates a document id for the given node identifier.
protected  void doClose()
          Calls release on the underlying MultiIndexReader instead of closing it.
 int getDocumentNumber(org.apache.jackrabbit.core.query.lucene.ForeignSegmentDocId docId)
          Returns the document number for the passed docId.
 org.apache.lucene.index.IndexReader[] getIndexReaders()
          
 int[] getParents(int n, int[] docNumbers)
          Returns the document number of the parent of n or an empty array if n does not have a parent (n is the root node).
 void release()
          Releases this index reader and potentially frees resources.
 org.apache.lucene.index.TermDocs termDocs(org.apache.lucene.index.Term term)
          Overwrite termDocs(Term) and forward the call to the wrapped reader.
 
Methods inherited from class org.apache.lucene.index.FilterIndexReader
directory, docFreq, doCommit, document, doDelete, doSetNorm, doUndeleteAll, getFieldNames, getTermFreqVector, getTermFreqVector, getTermFreqVector, getTermFreqVectors, getVersion, hasDeletions, hasNorms, isCurrent, isDeleted, isOptimized, maxDoc, norms, norms, numDocs, termDocs, termPositions, terms, terms
 
Methods inherited from class org.apache.lucene.index.IndexReader
acquireWriteLock, close, commit, decRef, deleteDocument, deleteDocuments, document, ensureOpen, flush, getCurrentVersion, getCurrentVersion, getCurrentVersion, getIndexCommit, getTermInfosIndexDivisor, incRef, indexExists, indexExists, indexExists, isLocked, isLocked, lastModified, lastModified, lastModified, listCommits, main, numDeletedDocs, open, open, open, open, open, open, open, open, open, reopen, setNorm, setNorm, setTermInfosIndexDivisor, termPositions, undeleteAll, unlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JackrabbitIndexReader

public JackrabbitIndexReader(org.apache.lucene.index.IndexReader in)
Creates a new JackrabbitIndexReader. The passed index reader must also implement the interfaces HierarchyResolver and MultiIndexReader.

Parameters:
in - the underlying index reader.
Throws:
IllegalArgumentException - if in does not implement HierarchyResolver and MultiIndexReader.
Method Detail

termDocs

public org.apache.lucene.index.TermDocs termDocs(org.apache.lucene.index.Term term)
                                          throws IOException
Overwrite termDocs(Term) and forward the call to the wrapped reader.

Overrides:
termDocs in class org.apache.lucene.index.IndexReader
Throws:
IOException

doClose

protected void doClose()
                throws IOException
Calls release on the underlying MultiIndexReader instead of closing it.

Overrides:
doClose in class org.apache.lucene.index.FilterIndexReader
Throws:
IOException - if an error occurs while releaseing the underlying index reader.

getParents

public int[] getParents(int n,
                        int[] docNumbers)
                 throws IOException
Returns the document number of the parent of n or an empty array if n does not have a parent (n is the root node).

Specified by:
getParents in interface HierarchyResolver
Parameters:
n - the document number.
docNumbers - an array for reuse. An implementation should use the passed array as a container for the return value, unless the length of the returned array is different from docNumbers. In which case an implementation will create a new array with an appropriate size.
Returns:
the document number of n's parent.
Throws:
IOException - if an error occurs while reading from the index.

getIndexReaders

public org.apache.lucene.index.IndexReader[] getIndexReaders()

Specified by:
getIndexReaders in interface MultiIndexReader
Returns:
the IndexReaders that are contained in this MultiIndexReader.

createDocId

public org.apache.jackrabbit.core.query.lucene.ForeignSegmentDocId createDocId(NodeId id)
                                                                        throws IOException
Creates a document id for the given node identifier.

Specified by:
createDocId in interface MultiIndexReader
Parameters:
id - the id of the node.
Returns:
a foreign segment doc id or null if there is no node with the given id.
Throws:
IOException - if an error occurs while reading from the index.

getDocumentNumber

public int getDocumentNumber(org.apache.jackrabbit.core.query.lucene.ForeignSegmentDocId docId)
                      throws IOException
Returns the document number for the passed docId. If the id is invalid -1 is returned.

Specified by:
getDocumentNumber in interface MultiIndexReader
Parameters:
docId - the document id to resolve.
Returns:
the document number or -1 if it is invalid (e.g. does not exist).
Throws:
IOException - if an error occurs while reading from the index.

release

public void release()
             throws IOException
Releases this index reader and potentially frees resources. In contrast to IndexReader.close() this method does not necessarily close the index reader, but gives the implementation the opportunity to do reference counting.

Specified by:
release in interface ReleaseableIndexReader
Throws:
IOException - if an error occurs while releasing the index reader.


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.