Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.lucene.index.IndexWriter
public class IndexWriter
extends Object
Field Summary | |
static String | |
static long |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static int |
|
static String | |
static long |
|
PrintStream |
|
int |
|
int |
|
int |
|
int |
|
Constructor Summary | |
| |
| |
|
Method Summary | |
void |
|
void |
|
void |
|
void |
|
void |
|
int |
|
protected void |
|
Analyzer |
|
Directory |
|
PrintStream | |
int | |
int | |
int | |
int | |
Similarity |
|
int |
|
boolean |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
public static final String COMMIT_LOCK_NAME
public static final long COMMIT_LOCK_TIMEOUT
Default value is 10,000.
- Field Value:
- 10000L
public static final int DEFAULT_MAX_BUFFERED_DOCS
Default value is 10. Change usingsetMaxBufferedDocs(int)
.
- Field Value:
- 10
public static final int DEFAULT_MAX_FIELD_LENGTH
Default value is 10,000. Change usingsetMaxFieldLength(int)
.
- Field Value:
- 10000
public static final int DEFAULT_MAX_MERGE_DOCS
Default value isInteger.MAX_VALUE
. Change usingsetMaxMergeDocs(int)
.
public static final int DEFAULT_MERGE_FACTOR
Default value is 10. Change usingsetMergeFactor(int)
.
- Field Value:
- 10
public static final int DEFAULT_MIN_MERGE_DOCS
Deprecated. use
DEFAULT_MAX_BUFFERED_DOCS
instead
- Field Value:
- 10
public static final int DEFAULT_TERM_INDEX_INTERVAL
Default value is 128. Change usingsetTermIndexInterval(int)
.
- Field Value:
- 128
public static final String WRITE_LOCK_NAME
public static final long WRITE_LOCK_TIMEOUT
Default value is 1,000.
- Field Value:
- 1000L
public PrintStream infoStream
Deprecated. use
setInfoStream(PrintStream)
insteadIf non-null, information about merges will be printed to this.
public int maxFieldLength
Deprecated. use
setMaxFieldLength(int)
insteadThe 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.
public int maxMergeDocs
Deprecated. use
setMaxMergeDocs(int)
insteadDetermines the largest number of documents ever merged by addDocument(). Small values (e.g., less than 10,000) are best for interactive indexing, as this limits the length of pauses while indexing to a few seconds. Larger values are best for batched indexing and speedier searches. The default value isInteger.MAX_VALUE
.
public int mergeFactor
Deprecated. use
setMergeFactor(int)
insteadDetermines 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 (<3210) for indices that are interactively maintained. This must never be less than 2. The default value is 10.
public int minMergeDocs
Deprecated. use
setMaxBufferedDocs(int)
insteadDetermines 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 aRAMDirectory
, large value gives faster indexing. At the same time, mergeFactor limits the number of files open in a FSDirectory. The default value is 10.
public IndexWriter(File path, Analyzer a, boolean create) throws IOException
Constructs an IndexWriter for the index inpath
. Text will be analyzed witha
. Ifcreate
is true, then a new, empty index will be created inpath
, replacing the index already there, if any.
- Parameters:
path
- the path to the index directorya
- the analyzer to usecreate
-true
to create the index or overwrite the existing one;false
to append to the existing index
public IndexWriter(String path, Analyzer a, boolean create) throws IOException
Constructs an IndexWriter for the index inpath
. Text will be analyzed witha
. Ifcreate
is true, then a new, empty index will be created inpath
, replacing the index already there, if any.
- Parameters:
path
- the path to the index directorya
- the analyzer to usecreate
-true
to create the index or overwrite the existing one;false
to append to the existing index
public IndexWriter(Directory d, Analyzer a, boolean create) throws IOException
Constructs an IndexWriter for the index ind
. Text will be analyzed witha
. Ifcreate
is true, then a new, empty index will be created ind
, replacing the index already there, if any.
- Parameters:
d
- the index directorya
- the analyzer to usecreate
-true
to create the index or overwrite the existing one;false
to append to the existing index
public void addDocument(Document doc) throws IOException
Adds a document to this index. If the document contains more thansetMaxFieldLength(int)
terms for a given field, the remainder are discarded.
public void addDocument(Document doc, Analyzer analyzer) throws IOException
Adds a document to this index, using the provided analyzer instead of the value ofgetAnalyzer()
. If the document contains more thansetMaxFieldLength(int)
terms for a given field, the remainder are discarded.
public void addIndexes(IndexReader[] readers) throws IOException
Merges the provided indexes into this index. After this completes, the index is optimized. The provided IndexReaders are not closed.
public void addIndexes(Directory[] dirs) throws IOException
Merges all segments from an array of indexes into this index. This may be used to parallelize batch indexing. A large document collection can be broken into sub-collections. Each sub-collection can be indexed in parallel, on a different thread, process or machine. The complete index can then be created by merging sub-collection indexes with this method. After this completes, the index is optimized.
public void close() throws IOException
Flushes all changes to an index and closes all associated files.
public int docCount()
Returns the number of documents currently in this index.
protected void finalize() throws IOException
Release the write lock, if needed.
public Similarity getSimilarity()
Expert: Return the Similarity implementation used by this IndexWriter. This defaults to the current value ofSimilarity.getDefault()
.
public int getTermIndexInterval()
Expert: Return the interval between indexed terms.
- See Also:
setTermIndexInterval(int)
public boolean getUseCompoundFile()
Get the current setting of whether to use the compound file format. Note that this just returns the value you set with setUseCompoundFile(boolean) or the default. You cannot use this to query the status of an existing index.
- See Also:
setUseCompoundFile(boolean)
public void optimize() throws IOException
Merges all segments together into a single segment, optimizing an index for search.
public void setInfoStream(PrintStream infoStream)
If non-null, information about merges and a message when maxFieldLength is reached will be printed to this.
public 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. Since Documents are merged in aRAMDirectory
, large value gives faster indexing. At the same time, mergeFactor limits the number of files open in a FSDirectory. The default value is 10.
public void setMaxFieldLength(int maxFieldLength)
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.
public void setMaxMergeDocs(int maxMergeDocs)
Determines the largest number of documents ever merged by addDocument(). Small values (e.g., less than 10,000) are best for interactive indexing, as this limits the length of pauses while indexing to a few seconds. Larger values are best for batched indexing and speedier searches. The default value isInteger.MAX_VALUE
.
public void setMergeFactor(int mergeFactor)
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 (<3210) for indices that are interactively maintained. This must never be less than 2. The default value is 10.
public void setSimilarity(Similarity similarity)
Expert: Set the Similarity implementation used by this IndexWriter.
- See Also:
Similarity.setDefault(Similarity)
public void setTermIndexInterval(int interval)
Expert: Set the interval between indexed terms. Large values cause less memory to be used by IndexReader, but slow random-access to terms. Small values cause more memory to be used by an IndexReader, and speed random-access to terms. This parameter determines the amount of computation required per query term, regardless of the number of documents that contain that term. In particular, it is the maximum number of other terms that must be scanned before a term is located and its frequency and position information may be processed. In a large index with user-entered query terms, query processing time is likely to be dominated not by term lookup but rather by the processing of frequency and positional data. In a small index or when many uncommon query terms are generated (e.g., by wildcard queries) term lookup may become a dominant cost. In particular,numUniqueTerms/interval
terms are read into memory by an IndexReader, and, on average,interval/2
terms must be scanned for each random term access.
- See Also:
DEFAULT_TERM_INDEX_INTERVAL
public void setUseCompoundFile(boolean value)
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.