|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.lucene.index.IndexModifier
IndexWriter
instead.
public class IndexModifier
[Note that as of 2.1, all but one of the
methods in this class are available via IndexWriter
. The one method that is not available is
deleteDocument(int)
.]
IndexReader
and IndexWriter
so that you
do not need to care about implementation details such as that adding
documents is done via IndexWriter and deletion is done via IndexReader.
Note that you cannot create more than one IndexModifier
object
on the same directory at the same time.
Example usage:
Analyzer analyzer = new StandardAnalyzer();
|
Not all methods of IndexReader and IndexWriter are offered by this
class. If you need access to additional methods, either use those classes
directly or implement your own class that extends IndexModifier
.
Although an instance of this class can be used from more than one thread, you will not get the best performance. You might want to use IndexReader and IndexWriter directly for that (but you will need to care about synchronization yourself then).
While you can freely mix calls to add() and delete() using this class, you should batch you calls for best performance. For example, if you want to update 20 documents, you should first delete all those documents, then add all the new documents.
Field Summary | |
---|---|
protected Analyzer |
analyzer
Deprecated. |
protected Directory |
directory
Deprecated. |
protected IndexReader |
indexReader
Deprecated. |
protected IndexWriter |
indexWriter
Deprecated. |
protected PrintStream |
infoStream
Deprecated. |
protected int |
maxBufferedDocs
Deprecated. |
protected int |
maxFieldLength
Deprecated. |
protected int |
mergeFactor
Deprecated. |
protected boolean |
open
Deprecated. |
protected boolean |
useCompoundFile
Deprecated. |
Constructor Summary | |
---|---|
IndexModifier(Directory directory,
Analyzer analyzer,
boolean create)
Deprecated. Open an index with write access. |
|
IndexModifier(File file,
Analyzer analyzer,
boolean create)
Deprecated. Open an index with write access. |
|
IndexModifier(String dirName,
Analyzer analyzer,
boolean create)
Deprecated. Open an index with write access. |
Method Summary | |
---|---|
void |
addDocument(Document doc)
Deprecated. Adds a document to this index. |
void |
addDocument(Document doc,
Analyzer docAnalyzer)
Deprecated. Adds a document to this index, using the provided analyzer instead of the one specific in the constructor. |
protected void |
assureOpen()
Deprecated. Throw an IllegalStateException if the index is closed. |
void |
close()
Deprecated. Close this index, writing all pending changes to disk. |
protected void |
createIndexReader()
Deprecated. Close the IndexWriter and open an IndexReader. |
protected void |
createIndexWriter()
Deprecated. Close the IndexReader and open an IndexWriter. |
void |
deleteDocument(int docNum)
Deprecated. Deletes the document numbered docNum . |
int |
deleteDocuments(Term term)
Deprecated. Deletes all documents containing term . |
int |
docCount()
Deprecated. Returns the number of documents currently in this index. |
void |
flush()
Deprecated. Make sure all changes are written to disk. |
PrintStream |
getInfoStream()
Deprecated. |
int |
getMaxBufferedDocs()
Deprecated. |
int |
getMaxFieldLength()
Deprecated. |
int |
getMergeFactor()
Deprecated. |
boolean |
getUseCompoundFile()
Deprecated. |
protected void |
init(Directory directory,
Analyzer analyzer,
boolean create)
Deprecated. Initialize an IndexWriter. |
void |
optimize()
Deprecated. Merges all segments together into a single segment, optimizing an index for search. |
void |
setInfoStream(PrintStream infoStream)
Deprecated. If non-null, information about merges and a message when getMaxFieldLength() is reached will be printed to this. |
void |
setMaxBufferedDocs(int maxBufferedDocs)
Deprecated. Determines the minimal number of documents required before the buffered in-memory documents are merging and a new Segment is created. |
void |
setMaxFieldLength(int maxFieldLength)
Deprecated. The maximum number of terms that will be indexed for a single field in a document. |
void |
setMergeFactor(int mergeFactor)
Deprecated. Determines how often segment indices are merged by addDocument(). |
void |
setUseCompoundFile(boolean useCompoundFile)
Deprecated. Setting to turn on usage of a compound file. |
String |
toString()
Deprecated. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected IndexWriter indexWriter
protected IndexReader indexReader
protected Directory directory
protected Analyzer analyzer
protected boolean open
protected PrintStream infoStream
protected boolean useCompoundFile
protected int maxBufferedDocs
protected int maxFieldLength
protected int mergeFactor
Constructor Detail |
---|
public IndexModifier(Directory directory, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException
directory
- the index directoryanalyzer
- the analyzer to use for adding new documentscreate
- true
to create the index or overwrite the existing one;
false
to append to the existing index
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorpublic IndexModifier(String dirName, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException
dirName
- the index directoryanalyzer
- the analyzer to use for adding new documentscreate
- true
to create the index or overwrite the existing one;
false
to append to the existing index
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorpublic IndexModifier(File file, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException
file
- the index directoryanalyzer
- the analyzer to use for adding new documentscreate
- true
to create the index or overwrite the existing one;
false
to append to the existing index
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorMethod Detail |
---|
protected void init(Directory directory, Analyzer analyzer, boolean create) throws CorruptIndexException, LockObtainFailedException, IOException
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorprotected void assureOpen()
IllegalStateException
protected void createIndexWriter() throws CorruptIndexException, LockObtainFailedException, IOException
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorprotected void createIndexReader() throws CorruptIndexException, IOException
CorruptIndexException
- if the index is corrupt
IOException
- if there is a low-level IO errorpublic void flush() throws CorruptIndexException, LockObtainFailedException, IOException
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorpublic void addDocument(Document doc, Analyzer docAnalyzer) throws CorruptIndexException, LockObtainFailedException, IOException
setMaxFieldLength(int)
terms for a given field, the remainder are
discarded.
IllegalStateException
- if the index is closed
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorIndexWriter.addDocument(Document, Analyzer)
public void addDocument(Document doc) throws CorruptIndexException, LockObtainFailedException, IOException
setMaxFieldLength(int)
terms for a given field, the remainder are
discarded.
IllegalStateException
- if the index is closed
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorIndexWriter.addDocument(Document)
public int deleteDocuments(Term term) throws StaleReaderException, CorruptIndexException, LockObtainFailedException, IOException
term
.
This is useful if one uses a document field to hold a unique ID string for
the document. Then to delete such a document, one merely constructs a
term with the appropriate field and the unique ID string as its text and
passes it to this method. Returns the number of documents deleted.
IllegalStateException
- if the index is closed
StaleReaderException
- if the index has changed
since this reader was opened
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorIndexReader.deleteDocuments(Term)
public void deleteDocument(int docNum) throws StaleReaderException, CorruptIndexException, LockObtainFailedException, IOException
docNum
.
StaleReaderException
- if the index has changed
since this reader was opened
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IllegalStateException
- if the index is closed
IOException
IndexReader.deleteDocument(int)
public int docCount()
IndexWriter.docCount()
, else IndexReader.numDocs()
. But, note that IndexWriter.docCount()
does not take deletions into
account, unlike IndexReader.numDocs()
.
IllegalStateException
- if the index is closedpublic void optimize() throws CorruptIndexException, LockObtainFailedException, IOException
IllegalStateException
- if the index is closed
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorIndexWriter.optimize()
public void setInfoStream(PrintStream infoStream)
getMaxFieldLength()
is reached will be printed to this.
Example: index.setInfoStream(System.err);
IllegalStateException
- if the index is closedIndexWriter.setInfoStream(PrintStream)
public PrintStream getInfoStream() throws CorruptIndexException, LockObtainFailedException, IOException
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorsetInfoStream(PrintStream)
public void setUseCompoundFile(boolean useCompoundFile)
IllegalStateException
- if the index is closedIndexWriter.setUseCompoundFile(boolean)
public boolean getUseCompoundFile() throws CorruptIndexException, LockObtainFailedException, IOException
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorsetUseCompoundFile(boolean)
public void setMaxFieldLength(int maxFieldLength)
IllegalStateException
- if the index is closedIndexWriter.setMaxFieldLength(int)
public int getMaxFieldLength() throws CorruptIndexException, LockObtainFailedException, IOException
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorsetMaxFieldLength(int)
public void setMaxBufferedDocs(int maxBufferedDocs)
RAMDirectory
,
large value gives faster indexing. At the same time, mergeFactor limits
the number of files open in a FSDirectory.
The default value is 10.
IllegalStateException
- if the index is closed
IllegalArgumentException
- if maxBufferedDocs is smaller than 2IndexWriter.setMaxBufferedDocs(int)
public int getMaxBufferedDocs() throws CorruptIndexException, LockObtainFailedException, IOException
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorsetMaxBufferedDocs(int)
public void setMergeFactor(int mergeFactor)
This must never be less than 2. The default value is 10.
IllegalStateException
- if the index is closedIndexWriter.setMergeFactor(int)
public int getMergeFactor() throws CorruptIndexException, LockObtainFailedException, IOException
CorruptIndexException
- if the index is corrupt
LockObtainFailedException
- if another writer
has this index open (write.lock
could not
be obtained)
IOException
- if there is a low-level IO errorsetMergeFactor(int)
public void close() throws CorruptIndexException, IOException
IllegalStateException
- if the index has been closed before already
CorruptIndexException
- if the index is corrupt
IOException
- if there is a low-level IO errorpublic String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |