Lucene++ - a full-featured, c++ search engine
API Documentation

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Data Fields | Static Public Attributes | Protected Member Functions | Protected Attributes
Lucene::LogMergePolicy Class Referenceabstract

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>`

Inheritance diagram for Lucene::LogMergePolicy:

## 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.
Public Member Functions inherited from Lucene::MergePolicy
| MergePolicy (const IndexWriterPtr &writer)
virtual | ~MergePolicy ()
boost::shared_ptr< MergePolicy > | shared_from_this ()
Public Member Functions inherited from Lucene::LuceneObject
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.
Public Member Functions inherited from Lucene::LuceneSync
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 Public Member Functions inherited from Lucene::MergePolicy
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)
Protected Member Functions inherited from Lucene::LuceneObject
| LuceneObject ()

## Protected Attributes

int32_t | mergeFactor
double | noCFSRatio
bool | calibrateSizeByDeletes
bool | _useCompoundFile
bool | _useCompoundDocStore
Protected Attributes inherited from Lucene::MergePolicy
IndexWriterWeakPtr | _writer
Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr | objectLock
LuceneSignalPtr | objectSignal

## Detailed Description

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.

## Constructor & Destructor Documentation

## ◆ LogMergePolicy()

Lucene::LogMergePolicy::LogMergePolicy | ( | const IndexWriterPtr & | writer | ) |

Referenced by _getClassName().

## ◆ ~LogMergePolicy()

virtual Lucene::LogMergePolicy::~LogMergePolicy | ( |  | ) |

virtual

## Member Function Documentation

## ◆ _getClassName()

String Lucene::LogMergePolicy::_getClassName | ( |  | ) |

inline static

References LogMergePolicy().

## ◆ close()

virtual void Lucene::LogMergePolicy::close | ( |  | ) |

virtual

Release all resources for the policy.

Implements Lucene::MergePolicy.

## ◆ findMerges()

virtual MergeSpecificationPtr Lucene::LogMergePolicy::findMerges | ( | const SegmentInfosPtr & | segmentInfos | ) |

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.

## ◆ findMergesForOptimize()

virtual MergeSpecificationPtr Lucene::LogMergePolicy::findMergesForOptimize | ( | const SegmentInfosPtr & | segmentInfos,
|  | int32_t | maxSegmentCount,
|  | SetSegmentInfo | segmentsToOptimize )

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.

## ◆ findMergesToExpungeDeletes()

virtual MergeSpecificationPtr Lucene::LogMergePolicy::findMergesToExpungeDeletes | ( | const SegmentInfosPtr & | segmentInfos | ) |

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.

## ◆ getCalibrateSizeByDeletes()

bool Lucene::LogMergePolicy::getCalibrateSizeByDeletes | ( |  | ) |

Returns true if the segment size should be calibrated by the number of deletes when choosing segments for merge.

## ◆ getClassName()

virtual String Lucene::LogMergePolicy::getClassName | ( |  | ) |

inline virtual

Reimplemented from Lucene::MergePolicy.

Reimplemented in Lucene::LogByteSizeMergePolicy, and Lucene::LogDocMergePolicy.

## ◆ getMaxMergeDocs()

int32_t Lucene::LogMergePolicy::getMaxMergeDocs | ( |  | ) |

Returns the largest segment (measured by document count) that may be merged with other segments.

See also
  setMaxMergeDocs

## ◆ getMergeFactor()

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.

## ◆ getNoCFSRatio()

double Lucene::LogMergePolicy::getNoCFSRatio | ( |  | ) |

See also
  setNoCFSRatio

## ◆ getUseCompoundDocStore()

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.

See also
  setUseCompoundDocStore

## ◆ getUseCompoundFile()

bool Lucene::LogMergePolicy::getUseCompoundFile | ( |  | ) |

Returns true if newly flushed and newly merge segments are written in compound file format.

See also
  setUseCompoundFile

## ◆ isOptimized() [1/2]

bool Lucene::LogMergePolicy::isOptimized | ( | const SegmentInfoPtr & | info | ) |

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.

## ◆ isOptimized() [2/2]

bool Lucene::LogMergePolicy::isOptimized | ( | const SegmentInfosPtr & | infos,
|  | int32_t | maxNumSegments,
|  | SetSegmentInfo | segmentsToOptimize )

protected

## ◆ makeOneMerge()

OneMergePtr Lucene::LogMergePolicy::makeOneMerge | ( | const SegmentInfosPtr & | infos,
|  | const SegmentInfosPtr & | infosToMerge )

protected

## ◆ message()

void Lucene::LogMergePolicy::message | ( | const String & | message | ) |

protected

References message().

Referenced by message().

## ◆ setCalibrateSizeByDeletes()

void Lucene::LogMergePolicy::setCalibrateSizeByDeletes | ( | bool | calibrateSizeByDeletes | ) |

Sets whether the segment size should be calibrated by the number of deletes when choosing segments for merge.

References calibrateSizeByDeletes.

## ◆ setMaxMergeDocs()

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`.

References maxMergeDocs.

## ◆ setMergeFactor()

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.

References mergeFactor.

## ◆ setNoCFSRatio()

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.

References noCFSRatio.

## ◆ setUseCompoundDocStore()

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).

References useCompoundDocStore().

## ◆ setUseCompoundFile()

void Lucene::LogMergePolicy::setUseCompoundFile | ( | bool | useCompoundFile | ) |

Sets whether compound file format should be used for newly flushed and newly merged segments.

References useCompoundFile().

## ◆ shared_from_this()

boost::shared_ptr< LogMergePolicy > Lucene::LogMergePolicy::shared_from_this | ( |  | ) |

inline

## ◆ size()

virtual int64_t Lucene::LogMergePolicy::size | ( | const SegmentInfoPtr & | info | ) |

protected pure virtual

Implemented in Lucene::LogByteSizeMergePolicy, and Lucene::LogDocMergePolicy.

## ◆ sizeBytes()

int64_t Lucene::LogMergePolicy::sizeBytes | ( | const SegmentInfoPtr & | info | ) |

protected

## ◆ sizeDocs()

int64_t Lucene::LogMergePolicy::sizeDocs | ( | const SegmentInfoPtr & | info | ) |

protected

## ◆ useCompoundDocStore()

virtual bool Lucene::LogMergePolicy::useCompoundDocStore | ( | const SegmentInfosPtr & | segments | ) |

virtual

Returns true if the doc store files should use the compound file format.

Implements Lucene::MergePolicy.

Referenced by setUseCompoundDocStore().

## ◆ useCompoundFile()

virtual bool Lucene::LogMergePolicy::useCompoundFile | ( | const SegmentInfosPtr & | segments,
|  | const SegmentInfoPtr & | newSegment )

virtual

Returns true if a newly flushed (not from merge) segment should use the compound file format.

Implements Lucene::MergePolicy.

Referenced by setUseCompoundFile().

## ◆ verbose()

bool Lucene::LogMergePolicy::verbose | ( |  | ) |

protected

## Field Documentation

## ◆ _useCompoundDocStore

bool Lucene::LogMergePolicy::_useCompoundDocStore

protected

## ◆ _useCompoundFile

bool Lucene::LogMergePolicy::_useCompoundFile

protected

## ◆ calibrateSizeByDeletes

bool Lucene::LogMergePolicy::calibrateSizeByDeletes

protected

Referenced by setCalibrateSizeByDeletes().

## ◆ DEFAULT_MAX_MERGE_DOCS

const int32_t Lucene::LogMergePolicy::DEFAULT_MAX_MERGE_DOCS

static

Default maximum segment size. A segment of this size or larger will never be merged.

See also
  setMaxMergeDocs

## ◆ DEFAULT_MERGE_FACTOR

const int32_t Lucene::LogMergePolicy::DEFAULT_MERGE_FACTOR

static

Default merge factor, which is how many segments are merged at a time.

## ◆ DEFAULT_NO_CFS_RATIO

const double Lucene::LogMergePolicy::DEFAULT_NO_CFS_RATIO

static

Default noCFSRatio. If a merge's size is >= 10% of the index, then we disable compound file for it.

See also
  setNoCFSRatio

## ◆ LEVEL_LOG_SPAN

const double Lucene::LogMergePolicy::LEVEL_LOG_SPAN

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.

## ◆ maxMergeDocs

int32_t Lucene::LogMergePolicy::maxMergeDocs

Referenced by setMaxMergeDocs().

## ◆ maxMergeSize

int64_t Lucene::LogMergePolicy::maxMergeSize

## ◆ mergeFactor

int32_t Lucene::LogMergePolicy::mergeFactor

protected

Referenced by setMergeFactor().

## ◆ minMergeSize

int64_t Lucene::LogMergePolicy::minMergeSize

## ◆ noCFSRatio

double Lucene::LogMergePolicy::noCFSRatio

protected

Referenced by setNoCFSRatio().

The documentation for this class was generated from the following file:

- LogMergePolicy.h

clucene.sourceforge.net