|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.lucene.index.IndexWriter
public class IndexWriter
An IndexWriter creates and maintains an index. The third argument to the constructor determines whether a new index is created, or whether an existing index is opened for the addition of new documents. In either case, documents are added with the addDocument method. When finished adding documents, close should be called.
If an index will not have more documents added for a while and optimal search performance is desired, then the optimize method should be called before the index is closed.
Opening an IndexWriter creates a lock file for the directory in use. Trying to open another IndexWriter on the same directory will lead to an IOException. The IOException is also thrown if an IndexReader on the same directory is used to delete documents from the index.
IndexModifier supports the important methods of IndexWriter plus deletion
Field Summary | |
---|---|
static java.lang.String |
COMMIT_LOCK_NAME
|
static long |
COMMIT_LOCK_TIMEOUT
Default value is 10,000. |
static int |
DEFAULT_MAX_BUFFERED_DOCS
Default value is 10. |
static int |
DEFAULT_MAX_FIELD_LENGTH
Default value is 10,000. |
static int |
DEFAULT_MAX_MERGE_DOCS
Default value is Integer.MAX_VALUE . |
static int |
DEFAULT_MERGE_FACTOR
Default value is 10. |
static int |
DEFAULT_MIN_MERGE_DOCS
Deprecated. use DEFAULT_MAX_BUFFERED_DOCS instead |
static int |
DEFAULT_TERM_INDEX_INTERVAL
Default value is 128. |
java.io.PrintStream |
infoStream
Deprecated. use setInfoStream(java.io.PrintStream) instead |
int |
maxFieldLength
Deprecated. use setMaxFieldLength(int) instead |
int |
maxMergeDocs
Deprecated. use setMaxMergeDocs(int) instead |
int |
mergeFactor
Deprecated. use setMergeFactor(int) instead |
int |
minMergeDocs
Deprecated. use setMaxBufferedDocs(int) instead |
static java.lang.String |
WRITE_LOCK_NAME
|
static long |
WRITE_LOCK_TIMEOUT
Default value is 1,000. |
Constructor Summary | |
---|---|
IndexWriter(Directory d,
Analyzer a,
boolean create)
Constructs an IndexWriter for the index in d . |
|
IndexWriter(java.io.File path,
Analyzer a,
boolean create)
Constructs an IndexWriter for the index in path . |
|
IndexWriter(java.lang.String path,
Analyzer a,
boolean create)
Constructs an IndexWriter for the index in path . |
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 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. |
Directory |
getDirectory()
Returns the Directory used by this index. |
java.io.PrintStream |
getInfoStream()
|
int |
getMaxBufferedDocs()
|
int |
getMaxFieldLength()
|
int |
getMaxMergeDocs()
|
int |
getMergeFactor()
|
Similarity |
getSimilarity()
Expert: Return the Similarity implementation used by this IndexWriter. |
int |
getTermIndexInterval()
Expert: Return the interval between indexed terms. |
boolean |
getUseCompoundFile()
Get the current setting of whether to use the compound file format. |
void |
optimize()
Merges all segments together into a single segment, optimizing an index for search. |
void |
setInfoStream(java.io.PrintStream infoStream)
If non-null, information about merges and a message when maxFieldLength is reached will be printed to this. |
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. |
void |
setMaxFieldLength(int maxFieldLength)
The maximum number of terms that will be indexed for a single field in a document. |
void |
setMaxMergeDocs(int maxMergeDocs)
Determines the largest number of documents ever merged by addDocument(). |
void |
setMergeFactor(int mergeFactor)
Determines how often segment indices are merged by addDocument(). |
void |
setSimilarity(Similarity similarity)
Expert: Set the Similarity implementation used by this IndexWriter. |
void |
setTermIndexInterval(int interval)
Expert: Set the interval between indexed terms. |
void |
setUseCompoundFile(boolean value)
Setting to turn on usage of a compound file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long WRITE_LOCK_TIMEOUT
public static final long COMMIT_LOCK_TIMEOUT
public static final java.lang.String WRITE_LOCK_NAME
public static final java.lang.String COMMIT_LOCK_NAME
public static final int DEFAULT_MERGE_FACTOR
setMergeFactor(int)
.
public static final int DEFAULT_MAX_BUFFERED_DOCS
setMaxBufferedDocs(int)
.
public static final int DEFAULT_MIN_MERGE_DOCS
DEFAULT_MAX_BUFFERED_DOCS
insteadpublic static final int DEFAULT_MAX_MERGE_DOCS
Integer.MAX_VALUE
. Change using setMaxMergeDocs(int)
.
public static final int DEFAULT_MAX_FIELD_LENGTH
setMaxFieldLength(int)
.
public static final int DEFAULT_TERM_INDEX_INTERVAL
setTermIndexInterval(int)
.
public int maxFieldLength
setMaxFieldLength(int)
instead
public int mergeFactor
setMergeFactor(int)
insteadThis must never be less than 2. The default value is 10.
public int minMergeDocs
setMaxBufferedDocs(int)
insteadRAMDirectory
,
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 int maxMergeDocs
setMaxMergeDocs(int)
insteadThe default value is Integer.MAX_VALUE
.
public java.io.PrintStream infoStream
setInfoStream(java.io.PrintStream)
instead
Constructor Detail |
---|
public IndexWriter(java.lang.String path, Analyzer a, boolean create) throws java.io.IOException
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.
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
java.io.IOException
- if the directory cannot be read/written to, or
if it does not exist, and create
is
false
public IndexWriter(java.io.File path, Analyzer a, boolean create) throws java.io.IOException
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.
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
java.io.IOException
- if the directory cannot be read/written to, or
if it does not exist, and create
is
false
public IndexWriter(Directory d, Analyzer a, boolean create) throws java.io.IOException
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.
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
java.io.IOException
- if the directory cannot be read/written to, or
if it does not exist, and create
is
false
Method Detail |
---|
public boolean getUseCompoundFile()
setUseCompoundFile(boolean)
public void setUseCompoundFile(boolean value)
public void setSimilarity(Similarity similarity)
Similarity.setDefault(Similarity)
public Similarity getSimilarity()
This defaults to the current value of Similarity.getDefault()
.
public void setTermIndexInterval(int interval)
numUniqueTerms/interval
terms are read into
memory by an IndexReader, and, on average, interval/2
terms
must be scanned for each random term access.
DEFAULT_TERM_INDEX_INTERVAL
public int getTermIndexInterval()
setTermIndexInterval(int)
public void setMaxMergeDocs(int maxMergeDocs)
The default value is Integer.MAX_VALUE
.
public int getMaxMergeDocs()
setMaxMergeDocs(int)
public void setMaxFieldLength(int maxFieldLength)
public int getMaxFieldLength()
setMaxFieldLength(int)
public void setMaxBufferedDocs(int maxBufferedDocs)
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.
java.lang.IllegalArgumentException
- if maxBufferedDocs is smaller than 2public int getMaxBufferedDocs()
setMaxBufferedDocs(int)
public void setMergeFactor(int mergeFactor)
This must never be less than 2. The default value is 10.
public int getMergeFactor()
setMergeFactor(int)
public void setInfoStream(java.io.PrintStream infoStream)
public java.io.PrintStream getInfoStream()
setInfoStream(java.io.PrintStream)
public void close() throws java.io.IOException
java.io.IOException
protected void finalize() throws java.io.IOException
finalize
in class java.lang.Object
java.io.IOException
public Directory getDirectory()
public Analyzer getAnalyzer()
public int docCount()
public void addDocument(Document doc) throws java.io.IOException
setMaxFieldLength(int)
terms for a given field, the remainder are
discarded.
java.io.IOException
public void addDocument(Document doc, Analyzer analyzer) throws java.io.IOException
getAnalyzer()
. If the document contains more than
setMaxFieldLength(int)
terms for a given field, the remainder are
discarded.
java.io.IOException
public void optimize() throws java.io.IOException
java.io.IOException
public void addIndexes(Directory[] dirs) throws java.io.IOException
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.
java.io.IOException
public void addIndexes(IndexReader[] readers) throws java.io.IOException
After this completes, the index is optimized.
The provided IndexReaders are not closed.
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |