org.apache.lucene.index
public class IndexWriter extends Object
Field Summary | |
---|---|
static String | COMMIT_LOCK_NAME |
static long | COMMIT_LOCK_TIMEOUT
Default value is 10000. |
static int | DEFAULT_MAX_FIELD_LENGTH
Default value is 10000. |
static int | DEFAULT_MAX_MERGE_DOCS
Default value is {@link Integer#MAX_VALUE}.
|
static int | DEFAULT_MERGE_FACTOR
Default value is 10. |
static int | DEFAULT_MIN_MERGE_DOCS
Default value is 10. |
PrintStream | infoStream If non-null, information about merges will be printed to this. |
int | maxFieldLength
The maximum number of terms that will be indexed for a single field in a
document. |
int | maxMergeDocs Determines the largest number of documents ever merged by addDocument().
|
int | mergeFactor Determines how often segment indices are merged by addDocument(). |
int | minMergeDocs Determines the minimal number of documents required before the buffered
in-memory documents are merging and a new Segment is created.
|
static String | WRITE_LOCK_NAME |
static long | WRITE_LOCK_TIMEOUT
Default value is 1000. |
Constructor Summary | |
---|---|
IndexWriter(String path, Analyzer a, boolean create)
Constructs an IndexWriter for the index in path .
| |
IndexWriter(File path, Analyzer a, boolean create)
Constructs an IndexWriter for the index in path .
| |
IndexWriter(Directory d, Analyzer a, boolean create)
Constructs an IndexWriter for the index in d .
|
Method Summary | |
---|---|
void | addDocument(Document doc)
Adds a document to this index. |
void | addDocument(Document doc, Analyzer analyzer)
Adds a document to this index, using the provided analyzer instead of the
value of {@link #getAnalyzer()}. |
void | addIndexes(Directory[] dirs) Merges all segments from an array of indexes into this index.
|
void | addIndexes(IndexReader[] readers) Merges the provided indexes into this index.
|
void | close() Flushes all changes to an index and closes all associated files. |
int | docCount() Returns the number of documents currently in this index. |
protected void | finalize() Release the write lock, if needed. |
Analyzer | getAnalyzer() Returns the analyzer used by this index. |
Similarity | getSimilarity() Expert: Return the Similarity implementation used by this IndexWriter.
|
boolean | getUseCompoundFile() Setting to turn on usage of a compound file. |
void | optimize() Merges all segments together into a single segment, optimizing an index
for search. |
void | setSimilarity(Similarity similarity) Expert: Set the Similarity implementation used by this IndexWriter.
|
void | setUseCompoundFile(boolean value) Setting to turn on usage of a compound file. |
org.apache.lucene.commitLockTimeout
system property to override.org.apache.lucene.maxFieldLength
system property to override.org.apache.lucene.maxMergeDocs
system property to override.org.apache.lucene.mergeFactor
system property to override.org.apache.lucene.minMergeDocs
system property to override.The default value is {@link Integer#MAX_VALUE}.
This must never be less than 2. The default value is 10.
The default value is 10.
org.apache.lucene.writeLockTimeout
system property to override.path
.
Text will be analyzed with a
. If create
is true, then a new, empty index will be created in
path
, replacing the index already there, if any.
Parameters: path the path to the index directory a the analyzer to use create true
to create the index or overwrite
the existing one; false
to append to the existing
index
Throws: IOException if the directory cannot be read/written to, or
if it does not exist, and create
is
false
path
.
Text will be analyzed with a
. If create
is true, then a new, empty index will be created in
path
, replacing the index already there, if any.
Parameters: path the path to the index directory a the analyzer to use create true
to create the index or overwrite
the existing one; false
to append to the existing
index
Throws: IOException if the directory cannot be read/written to, or
if it does not exist, and create
is
false
d
.
Text will be analyzed with a
. If create
is true, then a new, empty index will be created in
d
, replacing the index already there, if any.
Parameters: d the index directory a the analyzer to use create true
to create the index or overwrite
the existing one; false
to append to the existing
index
Throws: IOException if the directory cannot be read/written to, or
if it does not exist, and create
is
false
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.
After this completes, the index is optimized.
The provided IndexReaders are not closed.
This defaults to the current value of {@link Similarity#getDefault()}.
See Also: setDefault