| java.lang.Object org.apache.lucene.index.IndexModifier
IndexModifier | public class IndexModifier (Code) | | [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
IndexModifier.deleteDocument(int) .]
A class to modify an index, i.e. to delete and add documents. This
class hides
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();
// create an index in /tmp/index, overwriting an existing one:
IndexModifier indexModifier = new IndexModifier("/tmp/index", analyzer, true);
Document doc = new Document();
doc.add(new Field("id", "1", Field.Store.YES, Field.Index.UN_TOKENIZED));
doc.add(new Field("body", "a simple test", Field.Store.YES, Field.Index.TOKENIZED));
indexModifier.addDocument(doc);
int deleted = indexModifier.delete(new Term("id", "1"));
System.out.println("Deleted " + deleted + " document");
indexModifier.flush();
System.out.println(indexModifier.docCount() + " docs in index");
indexModifier.close();
|
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.
author: Daniel NaberIndexWriter |
maxBufferedDocs | protected int maxBufferedDocs(Code) | | |
maxFieldLength | protected int maxFieldLength(Code) | | |
mergeFactor | protected int mergeFactor(Code) | | |
open | protected boolean open(Code) | | |
useCompoundFile | protected boolean useCompoundFile(Code) | | |
setMaxFieldLength | public void setMaxFieldLength(int maxFieldLength)(Code) | | The maximum number of terms that will be indexed for a single field in a
document. This limits the amount of memory required for indexing, so that
collections with very large files will not crash the indexing process by
running out of memory.
Note that this effectively truncates large documents, excluding from the
index terms that occur further in the document. If you know your source
documents are large, be sure to set this value high enough to accomodate
the expected size. If you set it to Integer.MAX_VALUE, then the only limit
is your memory, but you should anticipate an OutOfMemoryError.
By default, no more than 10,000 terms will be indexed for a field.
See Also: IndexWriter.setMaxFieldLength(int) throws: IllegalStateException - if the index is closed |
setMergeFactor | public void setMergeFactor(int mergeFactor)(Code) | | Determines how often segment indices are merged by addDocument(). With
smaller values, less RAM is used while indexing, and searches on
unoptimized indices are faster, but indexing speed is slower. With larger
values, more RAM is used during indexing, and while searches on unoptimized
indices are slower, indexing is faster. Thus larger values (> 10) are best
for batch index creation, and smaller values (< 10) for indices that are
interactively maintained.
This must never be less than 2. The default value is 10.
See Also: IndexWriter.setMergeFactor(int) throws: IllegalStateException - if the index is closed |
setUseCompoundFile | public void setUseCompoundFile(boolean useCompoundFile)(Code) | | Setting to turn on usage of a compound file. When on, multiple files
for each segment are merged into a single file once the segment creation
is finished. This is done regardless of what directory is in use.
See Also: IndexWriter.setUseCompoundFile(boolean) throws: IllegalStateException - if the index is closed |
|
|