org.apache.lucene.limit
Class LimIndexReader

Object
  extended by IndexReader
      extended by LimIndexReader
Direct Known Subclasses:
XtfLimIndexReader

public class LimIndexReader
extends IndexReader

Wraps a normal IndexReader to limit the amount of work performed by a query. "Work" is defined as the number of docs and positions read. Limiting work in this way helps protect against malicious queries.

Author:
Martin Haye

Nested Class Summary
 
Nested classes/interfaces inherited from class IndexReader
IndexReader.FieldOption
 
Field Summary
private  int workCount
           
private  int workLimit
           
private  IndexReader wrapped
           
 
Fields inherited from class IndexReader
deleter
 
Constructor Summary
LimIndexReader(IndexReader toWrap, int workLimit)
          Wrap an index reader and enforce the specified limit.
 
Method Summary
 Directory directory()
           
 int docFreq(Term t)
           
protected  void doClose()
           
protected  void doCommit()
           
 Document document(int n)
           
 Document document(int n, FieldSelector fieldSelector)
           
protected  void doDelete(int docNum)
           
protected  void doSetNorm(int doc, String field, byte value)
           
protected  void doUndeleteAll()
           
 boolean equals(Object obj)
           
static long getCurrentVersion(Directory directory)
           
static long getCurrentVersion(File directory)
           
static long getCurrentVersion(String directory)
           
 Collection getFieldNames(IndexReader.FieldOption opt)
           
 TermFreqVector getTermFreqVector(int docNumber, String field)
           
 TermFreqVector[] getTermFreqVectors(int docNumber)
           
 long getVersion()
           
 boolean hasDeletions()
           
 int hashCode()
           
 boolean hasNorms(String field)
           
static boolean indexExists(Directory directory)
           
static boolean indexExists(File directory)
           
static boolean indexExists(String directory)
           
 boolean isCurrent()
           
 boolean isDeleted(int n)
           
static boolean isLocked(Directory directory)
           
static boolean isLocked(String directory)
           
 boolean isOptimized()
           
 int maxDoc()
           
 byte[] norms(String field)
           
 void norms(String field, byte[] bytes, int offset)
           
 int numDocs()
           
static IndexReader open(Directory directory)
           
static IndexReader open(File path)
           
static IndexReader open(String path)
           
 void setNorm(int doc, String field, float value)
           
 TermDocs termDocs()
           
 TermDocs termDocs(Term term)
           
 TermPositions termPositions()
           
 TermPositions termPositions(Term term)
           
 TermEnum terms()
           
 TermEnum terms(Term t)
           
 String toString()
           
static void unlock(Directory directory)
           
protected  void work(int amount)
          Called by LimTermDocs and LimTermPositions to notify us that a certain amount of work has been done.
 
Methods inherited from class IndexReader
close, commit, deleteDocument, deleteDocuments, finalize, getDeleter, lastModified, lastModified, lastModified, main, setDeleter, setNorm, undeleteAll
 
Methods inherited from class Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

wrapped

private IndexReader wrapped

workLimit

private int workLimit

workCount

private int workCount
Constructor Detail

LimIndexReader

public LimIndexReader(IndexReader toWrap,
                      int workLimit)
Wrap an index reader and enforce the specified limit.

Parameters:
toWrap - The reader to wrap
workLimit - Limit on the amount of wokr
Method Detail

work

protected void work(int amount)
             throws IOException
Called by LimTermDocs and LimTermPositions to notify us that a certain amount of work has been done. We check the limit, and if exceeded, throw an exception.

Parameters:
amount - How much work has been done. The unit is typically one term or term-position.
Throws:
IOException

document

public Document document(int n,
                         FieldSelector fieldSelector)
                  throws IOException
Specified by:
document in class IndexReader
Throws:
IOException

getCurrentVersion

public static long getCurrentVersion(File directory)
                              throws IOException
Throws:
IOException

getCurrentVersion

public static long getCurrentVersion(String directory)
                              throws IOException
Throws:
IOException

getCurrentVersion

public static long getCurrentVersion(Directory directory)
                              throws IOException
Throws:
IOException

indexExists

public static boolean indexExists(File directory)

indexExists

public static boolean indexExists(String directory)

indexExists

public static boolean indexExists(Directory directory)
                           throws IOException
Throws:
IOException

isLocked

public static boolean isLocked(String directory)
                        throws IOException
Throws:
IOException

isLocked

public static boolean isLocked(Directory directory)
                        throws IOException
Throws:
IOException

open

public static IndexReader open(File path)
                        throws IOException
Throws:
IOException

open

public static IndexReader open(String path)
                        throws IOException
Throws:
IOException

open

public static IndexReader open(Directory directory)
                        throws IOException
Throws:
IOException

unlock

public static void unlock(Directory directory)
                   throws IOException
Throws:
IOException

directory

public Directory directory()
Overrides:
directory in class IndexReader

docFreq

public int docFreq(Term t)
            throws IOException
Specified by:
docFreq in class IndexReader
Throws:
IOException

document

public Document document(int n)
                  throws IOException
Overrides:
document in class IndexReader
Throws:
IOException

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

getTermFreqVector

public TermFreqVector getTermFreqVector(int docNumber,
                                        String field)
                                 throws IOException
Specified by:
getTermFreqVector in class IndexReader
Throws:
IOException

getTermFreqVectors

public TermFreqVector[] getTermFreqVectors(int docNumber)
                                    throws IOException
Specified by:
getTermFreqVectors in class IndexReader
Throws:
IOException

hasDeletions

public boolean hasDeletions()
Specified by:
hasDeletions in class IndexReader

hashCode

public int hashCode()
Overrides:
hashCode in class Object

isDeleted

public boolean isDeleted(int n)
Specified by:
isDeleted in class IndexReader

maxDoc

public int maxDoc()
Specified by:
maxDoc in class IndexReader

norms

public byte[] norms(String field)
             throws IOException
Specified by:
norms in class IndexReader
Throws:
IOException

norms

public void norms(String field,
                  byte[] bytes,
                  int offset)
           throws IOException
Specified by:
norms in class IndexReader
Throws:
IOException

numDocs

public int numDocs()
Specified by:
numDocs in class IndexReader

setNorm

public void setNorm(int doc,
                    String field,
                    float value)
             throws IOException
Overrides:
setNorm in class IndexReader
Throws:
IOException

termDocs

public TermDocs termDocs()
                  throws IOException
Specified by:
termDocs in class IndexReader
Throws:
IOException

termDocs

public TermDocs termDocs(Term term)
                  throws IOException
Overrides:
termDocs in class IndexReader
Throws:
IOException

termPositions

public TermPositions termPositions()
                            throws IOException
Specified by:
termPositions in class IndexReader
Throws:
IOException

termPositions

public TermPositions termPositions(Term term)
                            throws IOException
Overrides:
termPositions in class IndexReader
Throws:
IOException

terms

public TermEnum terms()
               throws IOException
Specified by:
terms in class IndexReader
Throws:
IOException

terms

public TermEnum terms(Term t)
               throws IOException
Specified by:
terms in class IndexReader
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

doClose

protected void doClose()
                throws IOException
Specified by:
doClose in class IndexReader
Throws:
IOException

doCommit

protected void doCommit()
                 throws IOException
Specified by:
doCommit in class IndexReader
Throws:
IOException

doDelete

protected void doDelete(int docNum)
                 throws IOException
Specified by:
doDelete in class IndexReader
Throws:
IOException

doSetNorm

protected void doSetNorm(int doc,
                         String field,
                         byte value)
                  throws IOException
Specified by:
doSetNorm in class IndexReader
Throws:
IOException

doUndeleteAll

protected void doUndeleteAll()
                      throws IOException
Specified by:
doUndeleteAll in class IndexReader
Throws:
IOException

getFieldNames

public Collection getFieldNames(IndexReader.FieldOption opt)
Specified by:
getFieldNames in class IndexReader

getVersion

public long getVersion()
Overrides:
getVersion in class IndexReader

hasNorms

public boolean hasNorms(String field)
                 throws IOException
Overrides:
hasNorms in class IndexReader
Throws:
IOException

isCurrent

public boolean isCurrent()
                  throws IOException
Overrides:
isCurrent in class IndexReader
Throws:
IOException

isOptimized

public boolean isOptimized()
Overrides:
isOptimized in class IndexReader