Class UpgradeIndexMergePolicy
This MergePolicy is used for upgrading all existing segments of an index when calling ForceMerge(int). All other methods delegate to the base MergePolicy given to the constructor. This allows for an as-cheap-as possible upgrade of an older index by only upgrading segments that are created by previous Lucene versions. ForceMerge does no longer really merge; it is just used to "ForceMerge" older segment versions away.
In general one would use IndexUpgrader, but for a fully customizeable upgrade, you can use this like any other MergePolicy and call ForceMerge(int):IndexWriterConfig iwc = new IndexWriterConfig(LuceneVersion.LUCENE_XX, new KeywordAnalyzer());
iwc.MergePolicy = new UpgradeIndexMergePolicy(iwc.MergePolicy);
using (IndexWriter w = new IndexWriter(dir, iwc))
{
w.ForceMerge(1);
}
Warning: this merge policy may reorder documents if the index was partially
upgraded before calling ForceMerge(int) (e.g., documents were added). If your application relies
on "monotonicity" of doc IDs (which means that the order in which the documents
were added to the index is preserved), do a ForceMerge(1)
instead. Please note, the
delegate MergePolicy may also reorder documents.
Note
This API is experimental and might change in incompatible ways in the next release.
Implements
Inherited Members
Namespace: Lucene.Net.Index
Assembly: Lucene.Net.dll
Syntax
public class UpgradeIndexMergePolicy : MergePolicy, IDisposable
Constructors
UpgradeIndexMergePolicy(MergePolicy)
Wrap the given MergePolicy and intercept ForceMerge(int) requests to only upgrade segments written with previous Lucene versions.
Declaration
public UpgradeIndexMergePolicy(MergePolicy @base)
Parameters
Type | Name | Description |
---|---|---|
MergePolicy | base |
See Also
Fields
m_base
Wrapped MergePolicy.
Declaration
protected readonly MergePolicy m_base
Field Value
Type | Description |
---|---|
MergePolicy |
See Also
Methods
Dispose(bool)
Release all resources for the policy.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
Overrides
See Also
FindForcedDeletesMerges(SegmentInfos)
Determine what set of merge operations is necessary in order to expunge all deletes from the index.
Declaration
public override MergePolicy.MergeSpecification FindForcedDeletesMerges(SegmentInfos segmentInfos)
Parameters
Type | Name | Description |
---|---|---|
SegmentInfos | segmentInfos | the total set of segments in the index |
Returns
Type | Description |
---|---|
MergePolicy.MergeSpecification |
Overrides
See Also
FindForcedMerges(SegmentInfos, int, IDictionary<SegmentCommitInfo, bool>)
Determine what set of merge operations is necessary in order to merge to <= the specified segment count. IndexWriter calls this when its ForceMerge(int, bool) method is called. This call is always synchronized on the IndexWriter instance so only one thread at a time will call this method.
Declaration
public override MergePolicy.MergeSpecification FindForcedMerges(SegmentInfos segmentInfos, int maxSegmentCount, IDictionary<SegmentCommitInfo, bool> segmentsToMerge)
Parameters
Type | Name | Description |
---|---|---|
SegmentInfos | segmentInfos | The total set of segments in the index |
int | maxSegmentCount | Requested maximum number of segments in the index (currently this is always 1) |
IDictionary<SegmentCommitInfo, bool> | segmentsToMerge | Contains the specific SegmentInfo instances that must be merged
away. This may be a subset of all
SegmentInfos. If the value is |
Returns
Type | Description |
---|---|
MergePolicy.MergeSpecification |
Overrides
See Also
FindMerges(MergeTrigger, SegmentInfos)
Determine what set of merge operations are now necessary on the index. IndexWriter calls this whenever there is a change to the segments. This call is always synchronized on the IndexWriter instance so only one thread at a time will call this method.
Declaration
public override MergePolicy.MergeSpecification FindMerges(MergeTrigger mergeTrigger, SegmentInfos segmentInfos)
Parameters
Type | Name | Description |
---|---|---|
MergeTrigger | mergeTrigger | the event that triggered the merge |
SegmentInfos | segmentInfos | the total set of segments in the index |
Returns
Type | Description |
---|---|
MergePolicy.MergeSpecification |
Overrides
See Also
SetIndexWriter(IndexWriter)
Sets the IndexWriter to use by this merge policy. This method is allowed to be called only once, and is usually set by IndexWriter. If it is called more than once, AlreadySetException is thrown.
Declaration
public override void SetIndexWriter(IndexWriter writer)
Parameters
Type | Name | Description |
---|---|---|
IndexWriter | writer |
Overrides
See Also
ShouldUpgradeSegment(SegmentCommitInfo)
Returns true
if the given segment should be upgraded. The default implementation
will return !Constants.LUCENE_MAIN_VERSION.Equals(si.Info.Version, StringComparison.Ordinal)
,
so all segments created with a different version number than this Lucene version will
get upgraded.
Declaration
protected virtual bool ShouldUpgradeSegment(SegmentCommitInfo si)
Parameters
Type | Name | Description |
---|---|---|
SegmentCommitInfo | si |
Returns
Type | Description |
---|---|
bool |
See Also
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string that represents the current object. |
Overrides
See Also
UseCompoundFile(SegmentInfos, SegmentCommitInfo)
Returns true
if a new segment (regardless of its origin) should use the
compound file format. The default implementation returns true
iff the size of the given mergedInfo is less or equal to
MaxCFSSegmentSizeMB and the size is less or equal to the
TotalIndexSize * NoCFSRatio otherwise
false
.
Declaration
public override bool UseCompoundFile(SegmentInfos segments, SegmentCommitInfo newSegment)
Parameters
Type | Name | Description |
---|---|---|
SegmentInfos | segments | |
SegmentCommitInfo | newSegment |
Returns
Type | Description |
---|---|
bool |