|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.lucene.index.IndexModifier
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
|
protected Directory |
directory
|
protected IndexReader |
indexReader
|
protected IndexWriter |
indexWriter
|
protected PrintStream |
infoStream
|
protected int |
maxBufferedDocs
|
protected int |
maxFieldLength
|
protected int |
mergeFactor
|
protected boolean |
open
|
protected boolean |
useCompoundFile
|
| Constructor Summary | |
|---|---|
IndexModifier(Directory directory,
Analyzer analyzer,
boolean create)
Open an index with write access. |
|
IndexModifier(File file,
Analyzer analyzer,
boolean create)
Open an index with write access. |
|
IndexModifier(String dirName,
Analyzer analyzer,
boolean create)
Open an index with write access. |
|
| Method Summary | |
|---|---|
void |
addDocument(Document doc)
Adds a document to this index. |
void |
addDocument(Document doc,
Analyzer docAnalyzer)
Adds a document to this index, using the provided analyzer instead of the one specific in the constructor. |
protected void |
assureOpen()
Throw an IllegalStateException if the index is closed. |
void |
close()
Close this index, writing all pending changes to disk. |
protected void |
createIndexReader()
Close the IndexWriter and open an IndexReader. |
protected void |
createIndexWriter()
Close the IndexReader and open an IndexWriter. |
void |
deleteDocument(int docNum)
Deletes the document numbered docNum. |
int |
deleteDocuments(Term term)
Deletes all documents containing term. |
int |
docCount()
Returns the number of documents currently in this index. |
void |
flush()
Make sure all changes are written to disk. |
PrintStream |
getInfoStream()
|
int |
getMaxBufferedDocs()
|
int |
getMaxFieldLength()
|
int |
getMergeFactor()
|
boolean |
getUseCompoundFile()
|
protected void |
init(Directory directory,
Analyzer analyzer,
boolean create)
Initialize an IndexWriter. |
void |
optimize()
Merges all segments together into a single segment, optimizing an index for search. |
void |
setInfoStream(PrintStream infoStream)
If non-null, information about merges and a message when getMaxFieldLength() is reached will be printed to this. |
void |
setMaxBufferedDocs(int maxBufferedDocs)
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)
The maximum number of terms that will be indexed for a single field in a document. |
void |
setMergeFactor(int mergeFactor)
Determines how often segment indices are merged by addDocument(). |
void |
setUseCompoundFile(boolean useCompoundFile)
Setting to turn on usage of a compound file. |
String |
toString()
|
| 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 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
IOException
public IndexModifier(String dirName,
Analyzer analyzer,
boolean create)
throws 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
IOException
public IndexModifier(File file,
Analyzer analyzer,
boolean create)
throws 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
IOException| Method Detail |
|---|
protected void init(Directory directory,
Analyzer analyzer,
boolean create)
throws IOException
IOExceptionprotected void assureOpen()
IllegalStateException
protected void createIndexWriter()
throws IOException
IOException
protected void createIndexReader()
throws IOException
IOException
public void flush()
throws IOException
IOException
public void addDocument(Document doc,
Analyzer docAnalyzer)
throws IOException
setMaxFieldLength(int) terms for a given field, the remainder are
discarded.
IllegalStateException - if the index is closed
IOExceptionIndexWriter.addDocument(Document, Analyzer)
public void addDocument(Document doc)
throws IOException
setMaxFieldLength(int) terms for a given field, the remainder are
discarded.
IllegalStateException - if the index is closed
IOExceptionIndexWriter.addDocument(Document)
public int deleteDocuments(Term term)
throws 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
IOExceptionIndexReader.deleteDocuments(Term)
public void deleteDocument(int docNum)
throws IOException
docNum.
IllegalStateException - if the index is closed
IOExceptionIndexReader.deleteDocument(int)public int docCount()
IllegalStateException - if the index is closedIndexWriter.docCount(),
IndexReader.numDocs()
public void optimize()
throws IOException
IllegalStateException - if the index is closed
IOExceptionIndexWriter.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 IOException
IOExceptionsetInfoStream(PrintStream)public void setUseCompoundFile(boolean useCompoundFile)
IllegalStateException - if the index is closedIndexWriter.setUseCompoundFile(boolean)
public boolean getUseCompoundFile()
throws IOException
IOExceptionsetUseCompoundFile(boolean)public void setMaxFieldLength(int maxFieldLength)
IllegalStateException - if the index is closedIndexWriter.setMaxFieldLength(int)
public int getMaxFieldLength()
throws IOException
IOExceptionsetMaxFieldLength(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 IOException
IOExceptionsetMaxBufferedDocs(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 IOException
IOExceptionsetMergeFactor(int)
public void close()
throws IOException
IllegalStateException - if the index has been closed before already
IOExceptionpublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||