Lucene++ - a full-featured, c++ search engine
API Documentation
This class implements a MergePolicy
that tries to merge segments into levels of exponentially increasing size, where each level has fewer segments than the value of the merge factor. Whenever extra segments (beyond the merge factor upper bound) are encountered, all segments within the level are merged. You can get or set the merge factor using getMergeFactor()
and setMergeFactor(int)
respectively.
More...
#include <LogMergePolicy.h>
Public Member Functions | |
LogMergePolicy (const IndexWriterPtr &writer) | |
virtual | ~LogMergePolicy () |
virtual String | getClassName () |
boost::shared_ptr< LogMergePolicy > | shared_from_this () |
double | getNoCFSRatio () |
void | setNoCFSRatio (double noCFSRatio) |
If a merged segment will be more than this percentage of the total size of the index, leave the segment as non-compound file even if compound file is enabled. Set to 1.0 to always use CFS regardless of merge size. | |
int32_t | getMergeFactor () |
Returns the number of segments that are merged at once and also controls the total number of segments allowed to accumulate in the index. | |
void | setMergeFactor (int32_t 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 (< 10) for indices that are interactively maintained. | |
virtual bool | useCompoundFile (const SegmentInfosPtr &segments, const SegmentInfoPtr &newSegment) |
Returns true if a newly flushed (not from merge) segment should use the compound file format. | |
void | setUseCompoundFile (bool useCompoundFile) |
Sets whether compound file format should be used for newly flushed and newly merged segments. | |
bool | getUseCompoundFile () |
Returns true if newly flushed and newly merge segments are written in compound file format. | |
virtual bool | useCompoundDocStore (const SegmentInfosPtr &segments) |
Returns true if the doc store files should use the compound file format. | |
void | setUseCompoundDocStore (bool useCompoundDocStore) |
Sets whether compound file format should be used for newly flushed and newly merged doc store segment files (term vectors and stored fields). | |
bool | getUseCompoundDocStore () |
Returns true if newly flushed and newly merge doc store segment files (term vectors and stored fields) are written in compound file format. | |
void | setCalibrateSizeByDeletes (bool calibrateSizeByDeletes) |
Sets whether the segment size should be calibrated by the number of deletes when choosing segments for merge. | |
bool | getCalibrateSizeByDeletes () |
Returns true if the segment size should be calibrated by the number of deletes when choosing segments for merge. | |
virtual void | close () |
Release all resources for the policy. | |
virtual MergeSpecificationPtr | findMergesForOptimize (const SegmentInfosPtr &segmentInfos, int32_t maxSegmentCount, SetSegmentInfo segmentsToOptimize) |
Returns the merges necessary to optimize the index. This merge policy defines "optimized" to mean only one segment in the index, where that segment has no deletions pending nor separate norms, and it is in compound file format if the current useCompoundFile setting is true. This method returns multiple merges (mergeFactor at a time) so the MergeScheduler in use may make use of concurrency. | |
virtual MergeSpecificationPtr | findMergesToExpungeDeletes (const SegmentInfosPtr &segmentInfos) |
Finds merges necessary to expunge all deletes from the index. We simply merge adjacent segments that have deletes, up to mergeFactor at a time. | |
virtual MergeSpecificationPtr | findMerges (const SegmentInfosPtr &segmentInfos) |
Checks if any merges are now necessary and returns a MergePolicy.MergeSpecification if so. A merge is necessary when there are more than setMergeFactor segments at a given level. When multiple levels have too many segments, this method will return multiple merges, allowing the MergeScheduler to use concurrency. | |
void | setMaxMergeDocs (int32_t maxMergeDocs) |
Determines the largest segment (measured by document count) that may be merged with other segments. Small values (eg., 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. | |
int32_t | getMaxMergeDocs () |
Returns the largest segment (measured by document count) that may be merged with other segments. | |
![]() | |
MergePolicy (const IndexWriterPtr &writer) | |
virtual | ~MergePolicy () |
boost::shared_ptr< MergePolicy > | shared_from_this () |
![]() | |
virtual | ~LuceneObject () |
virtual void | initialize () |
Called directly after instantiation to create objects that depend on this object being fully constructed. | |
virtual LuceneObjectPtr | clone (const LuceneObjectPtr &other=LuceneObjectPtr()) |
Return clone of this object. | |
virtual int32_t | hashCode () |
Return hash code for this object. | |
virtual bool | equals (const LuceneObjectPtr &other) |
Return whether two objects are equal. | |
virtual int32_t | compareTo (const LuceneObjectPtr &other) |
Compare two objects. | |
virtual String | toString () |
Returns a string representation of the object. | |
![]() | |
virtual | ~LuceneSync () |
virtual SynchronizePtr | getSync () |
Return this object synchronize lock. | |
virtual LuceneSignalPtr | getSignal () |
Return this object signal. | |
virtual void | lock (int32_t timeout=0) |
Lock this object using an optional timeout. | |
virtual void | unlock () |
Unlock this object. | |
virtual bool | holdsLock () |
Returns true if this object is currently locked by current thread. | |
virtual void | wait (int32_t timeout=0) |
Wait for signal using an optional timeout. | |
virtual void | notifyAll () |
Notify all threads waiting for signal. | |
Static Public Member Functions | |
static String | _getClassName () |
![]() | |
static String | _getClassName () |
Data Fields | |
int64_t | minMergeSize |
int64_t | maxMergeSize |
int32_t | maxMergeDocs |
Static Public Attributes | |
static const double | LEVEL_LOG_SPAN |
Defines the allowed range of log(size) for each level. A level is computed by taking the max segment log size, minus LEVEL_LOG_SPAN, and finding all segments falling within that range. | |
static const int32_t | DEFAULT_MERGE_FACTOR |
Default merge factor, which is how many segments are merged at a time. | |
static const int32_t | DEFAULT_MAX_MERGE_DOCS |
Default maximum segment size. A segment of this size or larger will never be merged. | |
static const double | DEFAULT_NO_CFS_RATIO |
Default noCFSRatio. If a merge's size is >= 10% of the index, then we disable compound file for it. | |
Protected Member Functions | |
bool | verbose () |
void | message (const String &message) |
virtual int64_t | size (const SegmentInfoPtr &info)=0 |
int64_t | sizeDocs (const SegmentInfoPtr &info) |
int64_t | sizeBytes (const SegmentInfoPtr &info) |
bool | isOptimized (const SegmentInfosPtr &infos, int32_t maxNumSegments, SetSegmentInfo segmentsToOptimize) |
bool | isOptimized (const SegmentInfoPtr &info) |
Returns true if this single info is optimized (has no pending norms or deletes, is in the same dir as the writer, and matches the current compound file setting. | |
OneMergePtr | makeOneMerge (const SegmentInfosPtr &infos, const SegmentInfosPtr &infosToMerge) |
![]() | |
LuceneObject () | |
Protected Attributes | |
int32_t | mergeFactor |
double | noCFSRatio |
bool | calibrateSizeByDeletes |
bool | _useCompoundFile |
bool | _useCompoundDocStore |
![]() | |
IndexWriterWeakPtr | _writer |
![]() | |
SynchronizePtr | objectLock |
LuceneSignalPtr | objectSignal |
This class implements a MergePolicy
that tries to merge segments into levels of exponentially increasing size, where each level has fewer segments than the value of the merge factor. Whenever extra segments (beyond the merge factor upper bound) are encountered, all segments within the level are merged. You can get or set the merge factor using getMergeFactor()
and setMergeFactor(int)
respectively.
This class is abstract and requires a subclass to define the size
method which specifies how a segment's size is determined. LogDocMergePolicy
is one subclass that measures size by document count in the segment. LogByteSizeMergePolicy
is another subclass that measures size as the total byte size of the file(s) for the segment.
Lucene::LogMergePolicy::LogMergePolicy | ( | const IndexWriterPtr & | writer | ) |
|
virtual |
|
inlinestatic |
|
virtual |
Release all resources for the policy.
Implements Lucene::MergePolicy.
|
virtual |
Checks if any merges are now necessary and returns a MergePolicy.MergeSpecification
if so. A merge is necessary when there are more than setMergeFactor
segments at a given level. When multiple levels have too many segments, this method will return multiple merges, allowing the MergeScheduler
to use concurrency.
Implements Lucene::MergePolicy.
|
virtual |
Returns the merges necessary to optimize the index. This merge policy defines "optimized" to mean only one segment in the index, where that segment has no deletions pending nor separate norms, and it is in compound file format if the current useCompoundFile setting is true. This method returns multiple merges (mergeFactor at a time) so the MergeScheduler
in use may make use of concurrency.
Implements Lucene::MergePolicy.
|
virtual |
Finds merges necessary to expunge all deletes from the index. We simply merge adjacent segments that have deletes, up to mergeFactor at a time.
Implements Lucene::MergePolicy.
bool Lucene::LogMergePolicy::getCalibrateSizeByDeletes | ( | ) |
Returns true if the segment size should be calibrated by the number of deletes when choosing segments for merge.
|
inlinevirtual |
Reimplemented from Lucene::MergePolicy.
Reimplemented in Lucene::LogByteSizeMergePolicy, and Lucene::LogDocMergePolicy.
int32_t Lucene::LogMergePolicy::getMaxMergeDocs | ( | ) |
Returns the largest segment (measured by document count) that may be merged with other segments.
int32_t Lucene::LogMergePolicy::getMergeFactor | ( | ) |
Returns the number of segments that are merged at once and also controls the total number of segments allowed to accumulate in the index.
double Lucene::LogMergePolicy::getNoCFSRatio | ( | ) |
bool Lucene::LogMergePolicy::getUseCompoundDocStore | ( | ) |
Returns true if newly flushed and newly merge doc store segment files (term vectors and stored fields) are written in compound file format.
bool Lucene::LogMergePolicy::getUseCompoundFile | ( | ) |
Returns true if newly flushed and newly merge segments are written in compound file format.
|
protected |
Returns true if this single info is optimized (has no pending norms or deletes, is in the same dir as the writer, and matches the current compound file setting.
|
protected |
|
protected |
|
protected |
void Lucene::LogMergePolicy::setCalibrateSizeByDeletes | ( | bool | calibrateSizeByDeletes | ) |
Sets whether the segment size should be calibrated by the number of deletes when choosing segments for merge.
void Lucene::LogMergePolicy::setMaxMergeDocs | ( | int32_t | maxMergeDocs | ) |
Determines the largest segment (measured by document count) that may be merged with other segments. Small values (eg., 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 is INT_MAX.
The default merge policy (LogByteSizeMergePolicy
) also allows you to set this limit by net size (in MB) of the segment, using LogByteSizeMergePolicy#setMaxMergeMB
.
void Lucene::LogMergePolicy::setMergeFactor | ( | int32_t | 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 (< 10) for indices that are interactively maintained.
void Lucene::LogMergePolicy::setNoCFSRatio | ( | double | noCFSRatio | ) |
If a merged segment will be more than this percentage of the total size of the index, leave the segment as non-compound file even if compound file is enabled. Set to 1.0 to always use CFS regardless of merge size.
void Lucene::LogMergePolicy::setUseCompoundDocStore | ( | bool | useCompoundDocStore | ) |
Sets whether compound file format should be used for newly flushed and newly merged doc store segment files (term vectors and stored fields).
void Lucene::LogMergePolicy::setUseCompoundFile | ( | bool | useCompoundFile | ) |
Sets whether compound file format should be used for newly flushed and newly merged segments.
|
inline |
|
protectedpure virtual |
Implemented in Lucene::LogByteSizeMergePolicy, and Lucene::LogDocMergePolicy.
|
protected |
|
protected |
|
virtual |
Returns true if the doc store files should use the compound file format.
Implements Lucene::MergePolicy.
|
virtual |
Returns true if a newly flushed (not from merge) segment should use the compound file format.
Implements Lucene::MergePolicy.
|
protected |
|
protected |
|
protected |
|
protected |
|
static |
Default maximum segment size. A segment of this size or larger will never be merged.
|
static |
Default merge factor, which is how many segments are merged at a time.
|
static |
Default noCFSRatio. If a merge's size is >= 10% of the index, then we disable compound file for it.
|
static |
Defines the allowed range of log(size) for each level. A level is computed by taking the max segment log size, minus LEVEL_LOG_SPAN, and finding all segments falling within that range.
int32_t Lucene::LogMergePolicy::maxMergeDocs |
int64_t Lucene::LogMergePolicy::maxMergeSize |
|
protected |
int64_t Lucene::LogMergePolicy::minMergeSize |
|
protected |