Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.lucene.index
Class IndexModifier

    java.lang.Object
      org.apache.lucene.index.IndexModifier

Deprecated. Please use `IndexWriter` instead.

    public class IndexModifier

extends Object

[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)`.]

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 Naber

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

### indexWriter

    protected IndexWriter indexWriter

  Deprecated.

### indexReader

    protected IndexReader indexReader

  Deprecated.

### directory

    protected Directory directory

  Deprecated.

### analyzer

    protected Analyzer analyzer

  Deprecated.

### open

    protected boolean open

  Deprecated.

### infoStream

    protected PrintStream infoStream

  Deprecated.

### useCompoundFile

    protected boolean useCompoundFile

  Deprecated.

### maxBufferedDocs

    protected int maxBufferedDocs

  Deprecated.

### maxFieldLength

    protected int maxFieldLength

  Deprecated.

### mergeFactor

    protected int mergeFactor

  Deprecated.

Constructor Detail

### IndexModifier

    public IndexModifier(Directory directory,
                         Analyzer analyzer,
                         boolean create)
                  throws CorruptIndexException,
                         LockObtainFailedException,
                         IOException

  Deprecated.
  Open an index with write access.

  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
  Throws:
    `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 error

### IndexModifier

    public IndexModifier(String dirName,
                         Analyzer analyzer,
                         boolean create)
                  throws CorruptIndexException,
                         LockObtainFailedException,
                         IOException

  Deprecated.
  Open an index with write access.

  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
  Throws:
    `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 error

### IndexModifier

    public IndexModifier(File file,
                         Analyzer analyzer,
                         boolean create)
                  throws CorruptIndexException,
                         LockObtainFailedException,
                         IOException

  Deprecated.
  Open an index with write access.

  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:
    `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 error

Method Detail

### init

    protected void init(Directory directory,
                        Analyzer analyzer,
                        boolean create)
                 throws CorruptIndexException,
                        LockObtainFailedException,
                        IOException

  Deprecated.
  Initialize an IndexWriter.

  Throws:
    `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 error

### assureOpen

    protected void assureOpen()

  Deprecated.
  Throw an IllegalStateException if the index is closed.

  Throws:
    `IllegalStateException`

### createIndexWriter

    protected void createIndexWriter()
                              throws CorruptIndexException,
                                     LockObtainFailedException,
                                     IOException

  Deprecated.
  Close the IndexReader and open an IndexWriter.

  Throws:
    `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 error

### createIndexReader

    protected void createIndexReader()
                              throws CorruptIndexException,
                                     IOException

  Deprecated.
  Close the IndexWriter and open an IndexReader.

  Throws:
    `CorruptIndexException` - if the index is corrupt
    `IOException` - if there is a low-level IO error

### flush

    public void flush()
               throws CorruptIndexException,
                      LockObtainFailedException,
                      IOException

  Deprecated.
  Make sure all changes are written to disk.

  Throws:
    `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 error

### addDocument

    public void addDocument(Document doc,
                            Analyzer docAnalyzer)
                     throws CorruptIndexException,
                            LockObtainFailedException,
                            IOException

  Deprecated.
  Adds a document to this index, using the provided analyzer instead of the one specific in the constructor. If the document contains more than `setMaxFieldLength(int)` terms for a given field, the remainder are discarded.

  Throws:
    `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 error
  See Also:
    `IndexWriter.addDocument(Document, Analyzer)`

### addDocument

    public void addDocument(Document doc)
                     throws CorruptIndexException,
                            LockObtainFailedException,
                            IOException

  Deprecated.
  Adds a document to this index. If the document contains more than `setMaxFieldLength(int)` terms for a given field, the remainder are discarded.

  Throws:
    `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 error
  See Also:
    `IndexWriter.addDocument(Document)`

### deleteDocuments

    public int deleteDocuments(Term term)
                        throws StaleReaderException,
                               CorruptIndexException,
                               LockObtainFailedException,
                               IOException

  Deprecated.
  Deletes all documents containing `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
    `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 error
  See Also:
    `IndexReader.deleteDocuments(Term)`

### deleteDocument

    public void deleteDocument(int docNum)
                        throws StaleReaderException,
                               CorruptIndexException,
                               LockObtainFailedException,
                               IOException

  Deprecated.
  Deletes the document numbered `docNum`.

  Throws:
    `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`
  See Also:
    `IndexReader.deleteDocument(int)`

### docCount

    public int docCount()

  Deprecated.
  Returns the number of documents currently in this index. If the writer is currently open, this returns `IndexWriter.docCount()`, else `IndexReader.numDocs()`. But, note that `IndexWriter.docCount()` does not take deletions into account, unlike `IndexReader.numDocs()`.

  Throws:
    `IllegalStateException` - if the index is closed

### optimize

    public void optimize()
                  throws CorruptIndexException,
                         LockObtainFailedException,
                         IOException

  Deprecated.
  Merges all segments together into a single segment, optimizing an index for search.

  Throws:
    `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 error
  See Also:
    `IndexWriter.optimize()`

### setInfoStream

    public void setInfoStream(PrintStream infoStream)

  Deprecated.
  If non-null, information about merges and a message when `getMaxFieldLength()` is reached will be printed to this.

  Example: `index.setInfoStream(System.err);`

  Throws:
    `IllegalStateException` - if the index is closed
  See Also:
    `IndexWriter.setInfoStream(PrintStream)`

### getInfoStream

    public PrintStream getInfoStream()
                              throws CorruptIndexException,
                                     LockObtainFailedException,
                                     IOException

  Deprecated.
  Throws:
    `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 error
  See Also:
    `setInfoStream(PrintStream)`

### setUseCompoundFile

    public void setUseCompoundFile(boolean useCompoundFile)

  Deprecated.
  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.

  Throws:
    `IllegalStateException` - if the index is closed
  See Also:
    `IndexWriter.setUseCompoundFile(boolean)`

### getUseCompoundFile

    public boolean getUseCompoundFile()
                               throws CorruptIndexException,
                                      LockObtainFailedException,
                                      IOException

  Deprecated.
  Throws:
    `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 error
  See Also:
    `setUseCompoundFile(boolean)`

### setMaxFieldLength

    public void setMaxFieldLength(int maxFieldLength)

  Deprecated.
  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.

  Throws:
    `IllegalStateException` - if the index is closed
  See Also:
    `IndexWriter.setMaxFieldLength(int)`

### getMaxFieldLength

    public int getMaxFieldLength()
                          throws CorruptIndexException,
                                 LockObtainFailedException,
                                 IOException

  Deprecated.
  Throws:
    `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 error
  See Also:
    `setMaxFieldLength(int)`

### setMaxBufferedDocs

    public 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. Since Documents are merged in a `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.

  Throws:
    `IllegalStateException` - if the index is closed
    `IllegalArgumentException` - if maxBufferedDocs is smaller than 2
  See Also:
    `IndexWriter.setMaxBufferedDocs(int)`

### getMaxBufferedDocs

    public int getMaxBufferedDocs()
                           throws CorruptIndexException,
                                  LockObtainFailedException,
                                  IOException

  Deprecated.
  Throws:
    `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 error
  See Also:
    `setMaxBufferedDocs(int)`

### setMergeFactor

    public void setMergeFactor(int mergeFactor)

  Deprecated.
  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.

  Throws:
    `IllegalStateException` - if the index is closed
  See Also:
    `IndexWriter.setMergeFactor(int)`

### getMergeFactor

    public int getMergeFactor()
                       throws CorruptIndexException,
                              LockObtainFailedException,
                              IOException

  Deprecated.
  Throws:
    `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 error
  See Also:
    `setMergeFactor(int)`

### close

    public void close()
               throws CorruptIndexException,
                      IOException

  Deprecated.
  Close this index, writing all pending changes to disk.

  Throws:
    `IllegalStateException` - if the index has been closed before already
    `CorruptIndexException` - if the index is corrupt
    `IOException` - if there is a low-level IO error

### toString

    public String toString()

  Deprecated.
  Overrides:
    `toString` in class `Object`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.