org.apache.lucene.index
public class IndexModifier extends Object
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(String dirName, Analyzer analyzer, boolean create)
Open an index with write access.
| |
IndexModifier(File file, Analyzer analyzer, boolean create)
Open an index with write access.
|
Method Summary | |
---|---|
void | addDocument(Document doc, Analyzer docAnalyzer)
Adds a document to this index, using the provided analyzer instead of the
one specific in the constructor. |
void | addDocument(Document doc)
Adds a document to this index. |
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. |
int | delete(Term term)
Deletes all documents containing term .
|
void | delete(int docNum)
Deletes the document numbered docNum . |
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
{@link #getMaxFieldLength()} is reached will be printed to this.
|
void | setMaxBufferedDocs(int maxBufferedDocs)
The maximum number of terms that will be indexed for a single field in a
document. |
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() |
Parameters: directory the index directory analyzer the analyzer to use for adding new documents create true
to create the index or overwrite the existing one;
false
to append to the existing index
Parameters: dirName the index directory analyzer the analyzer to use for adding new documents create true
to create the index or overwrite the existing one;
false
to append to the existing index
Parameters: file the index directory analyzer the analyzer to use for adding new documents create true
to create the index or overwrite the existing one;
false
to append to the existing index
Throws: IllegalStateException if the index is closed
See Also: IndexWriter
Throws: IllegalStateException if the index is closed
See Also: addDocument
Throws: IllegalStateException
Throws: IllegalStateException if the index has been closed before already
Throws: IOException
Throws: IOException
Deprecated: Use {@link #deleteDocuments(Term)} instead.
Deletes all documents containingterm
.
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.Returns: the number of documents deleted
Throws: IllegalStateException if the index is closed
See Also: deleteDocuments
Deprecated: Use {@link #deleteDocument(int)} instead.
Deletes the document numbereddocNum
.Throws: IllegalStateException if the index is closed
See Also: IndexReader
docNum
.Throws: IllegalStateException if the index is closed
See Also: IndexReader
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.Returns: the number of documents deleted
Throws: IllegalStateException if the index is closed
See Also: deleteDocuments
Throws: IllegalStateException if the index is closed
Throws: IOException
Throws: IOException
See Also: setInfoStream
Throws: IOException
See Also: IndexModifier
Throws: IOException
See Also: IndexModifier
Throws: IOException
See Also: IndexModifier
Throws: IOException
See Also: IndexModifier
Throws: IOException
Throws: IllegalStateException if the index is closed
See Also: optimize
Example: index.setInfoStream(System.err);
Throws: IllegalStateException if the index is closed
See Also: setInfoStream
Throws: IllegalStateException if the index is closed
See Also: IndexWriter
Throws: IllegalStateException if the index is closed
See Also: IndexWriter
This must never be less than 2. The default value is 10.
Throws: IllegalStateException if the index is closed
See Also: IndexWriter
Throws: IllegalStateException if the index is closed
See Also: IndexWriter