|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectgate.creole.annic.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.
| Field Summary | |
|---|---|
private Analyzer |
analyzer
|
private boolean |
closeDir
|
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 Integer.MAX_VALUE. |
static int |
DEFAULT_MERGE_FACTOR
Default value is 10. |
static int |
DEFAULT_MIN_MERGE_DOCS
Default value is 10. |
private Directory |
directory
|
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. |
private Directory |
ramDirectory
|
private SegmentInfos |
segmentInfos
|
private Similarity |
similarity
|
private boolean |
useCompoundFile
Use compound file setting. |
static String |
WRITE_LOCK_NAME
|
static long |
WRITE_LOCK_TIMEOUT
Default value is 1000. |
private Lock |
writeLock
|
| Constructor Summary | |
|---|---|
|
IndexWriter(Directory d,
Analyzer a,
boolean create)
Constructs an IndexWriter for the index in d. |
private |
IndexWriter(Directory d,
Analyzer a,
boolean create,
boolean closeDir)
|
|
IndexWriter(File path,
Analyzer a,
boolean create)
Constructs an IndexWriter for the index in path. |
|
IndexWriter(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. |
private void |
deleteFiles(Vector files,
Directory directory)
|
private void |
deleteFiles(Vector files,
Vector deletable)
|
private void |
deleteSegments(Vector segments)
|
int |
docCount()
Returns the number of documents currently in this index. |
protected void |
finalize()
Release the write lock, if needed. |
private void |
flushRamSegments()
Merges all RAM-resident segments. |
Analyzer |
getAnalyzer()
Returns the analyzer used by this index. |
(package private) int |
getSegmentsCounter()
|
Similarity |
getSimilarity()
Expert: Return the Similarity implementation used by this IndexWriter. |
boolean |
getUseCompoundFile()
Setting to turn on usage of a compound file. |
private void |
maybeMergeSegments()
Incremental segment merger. |
private void |
mergeSegments(int minSegment)
Pops segments off of segmentInfos stack down to minSegment, merges them, and pushes the merged index onto the top of the segmentInfos stack. |
private String |
newSegmentName()
|
void |
optimize()
Merges all segments together into a single segment, optimizing an index for search. |
private Vector |
readDeleteableFiles()
|
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. |
private void |
writeDeleteableFiles(Vector files)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static long WRITE_LOCK_TIMEOUT
gate.creole.annic.apache.lucene.writeLockTimeout
system property to override.
public static long COMMIT_LOCK_TIMEOUT
gate.creole.annic.apache.lucene.commitLockTimeout
system property to override.
public static final String WRITE_LOCK_NAME
public static final String COMMIT_LOCK_NAME
public static final int DEFAULT_MERGE_FACTOR
gate.creole.annic.apache.lucene.mergeFactor
system property to override.
public static final int DEFAULT_MIN_MERGE_DOCS
gate.creole.annic.apache.lucene.minMergeDocs
system property to override.
public static final int DEFAULT_MAX_MERGE_DOCS
Integer.MAX_VALUE.
Use gate.creole.annic.apache.lucene.maxMergeDocs system property to override.
public static final int DEFAULT_MAX_FIELD_LENGTH
gate.creole.annic.apache.lucene.maxFieldLength
system property to override.
private Directory directory
private Analyzer analyzer
private Similarity similarity
private SegmentInfos segmentInfos
private final Directory ramDirectory
private Lock writeLock
private boolean useCompoundFile
private boolean closeDir
public int maxFieldLength
public int mergeFactor
This must never be less than 2. The default value is 10.
public int minMergeDocs
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.
public int maxMergeDocs
The default value is Integer.MAX_VALUE.
public PrintStream infoStream
| Constructor Detail |
|---|
public IndexWriter(String path,
Analyzer a,
boolean create)
throws 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
IOException - if the directory cannot be read/written to, or
if it does not exist, and create is
false
public IndexWriter(File path,
Analyzer a,
boolean create)
throws 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
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 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
IOException - if the directory cannot be read/written to, or
if it does not exist, and create is
false
private IndexWriter(Directory d,
Analyzer a,
boolean create,
boolean closeDir)
throws IOException
IOException| Method Detail |
|---|
public boolean getUseCompoundFile()
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 close()
throws IOException
IOException
protected void finalize()
throws IOException
finalize in class ObjectIOExceptionpublic Analyzer getAnalyzer()
public int docCount()
public void addDocument(Document doc)
throws IOException
maxFieldLength terms for a given field, the remainder are
discarded.
IOException
public void addDocument(Document doc,
Analyzer analyzer)
throws IOException
getAnalyzer(). If the document contains more than
maxFieldLength terms for a given field, the remainder are
discarded.
IOExceptionfinal int getSegmentsCounter()
private final String newSegmentName()
public void optimize()
throws IOException
IOException
public void addIndexes(Directory[] dirs)
throws 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.
IOException
public void addIndexes(IndexReader[] readers)
throws IOException
After this completes, the index is optimized.
The provided IndexReaders are not closed.
IOException
private final void flushRamSegments()
throws IOException
IOException
private final void maybeMergeSegments()
throws IOException
IOException
private final void mergeSegments(int minSegment)
throws IOException
IOException
private final void deleteSegments(Vector segments)
throws IOException
IOException
private final void deleteFiles(Vector files,
Directory directory)
throws IOException
IOException
private final void deleteFiles(Vector files,
Vector deletable)
throws IOException
IOException
private final Vector readDeleteableFiles()
throws IOException
IOException
private final void writeDeleteableFiles(Vector files)
throws IOException
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||