Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: Lucene.Net.Index.SegmentInfos: Changed Info() method to an indexer (.NET Convention) #577

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Lucene.Net.Misc/Index/IndexSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public virtual void ListSegments()
{
for (int x = 0; x < Infos.Count; x++)
{
SegmentCommitInfo info = Infos.Info(x);
SegmentCommitInfo info = Infos[x];
string sizeStr = string.Format(CultureInfo.InvariantCulture, "{0:###,###.###}", info.GetSizeInBytes());
Console.WriteLine(info.Info.Name + " " + sizeStr);
}
Expand All @@ -114,7 +114,7 @@ private int GetIdx(string name)
{
for (int x = 0; x < Infos.Count; x++)
{
if (name.Equals(Infos.Info(x).Info.Name, StringComparison.Ordinal))
if (name.Equals(Infos[x].Info.Name, StringComparison.Ordinal))
{
return x;
}
Expand All @@ -126,9 +126,9 @@ private SegmentCommitInfo GetInfo(string name)
{
for (int x = 0; x < Infos.Count; x++)
{
if (name.Equals(Infos.Info(x).Info.Name, StringComparison.Ordinal))
if (name.Equals(Infos[x].Info.Name, StringComparison.Ordinal))
{
return Infos.Info(x);
return Infos[x];
}
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Tests.Misc/Index/TestIndexSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void Test()
iw.Dispose();
// we should have 2 segments now
IndexSplitter @is = new IndexSplitter(dir);
string splitSegName = @is.Infos.Info(1).Info.Name;
string splitSegName = @is.Infos[1].Info.Name;
@is.Split(destDir, new string[] { splitSegName });
Store.Directory fsDirDest = NewFSDirectory(destDir);
DirectoryReader r = DirectoryReader.Open(fsDirDest);
Expand Down
24 changes: 12 additions & 12 deletions src/Lucene.Net.Tests/Index/TestConsistentFieldNumbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public virtual void TestSameFieldNumbersAcrossSegments()
sis.Read(dir);
Assert.AreEqual(2, sis.Count);

FieldInfos fis1 = SegmentReader.ReadFieldInfos(sis.Info(0));
FieldInfos fis2 = SegmentReader.ReadFieldInfos(sis.Info(1));
FieldInfos fis1 = SegmentReader.ReadFieldInfos(sis[0]);
FieldInfos fis2 = SegmentReader.ReadFieldInfos(sis[1]);

Assert.AreEqual("f1", fis1.FieldInfo(0).Name);
Assert.AreEqual("f2", fis1.FieldInfo(1).Name);
Expand All @@ -97,7 +97,7 @@ public virtual void TestSameFieldNumbersAcrossSegments()
sis.Read(dir);
Assert.AreEqual(1, sis.Count);

FieldInfos fis3 = SegmentReader.ReadFieldInfos(sis.Info(0));
FieldInfos fis3 = SegmentReader.ReadFieldInfos(sis[0]);

Assert.AreEqual("f1", fis3.FieldInfo(0).Name);
Assert.AreEqual("f2", fis3.FieldInfo(1).Name);
Expand Down Expand Up @@ -142,8 +142,8 @@ public virtual void TestAddIndexes()
sis.Read(dir1);
Assert.AreEqual(2, sis.Count);

FieldInfos fis1 = SegmentReader.ReadFieldInfos(sis.Info(0));
FieldInfos fis2 = SegmentReader.ReadFieldInfos(sis.Info(1));
FieldInfos fis1 = SegmentReader.ReadFieldInfos(sis[0]);
FieldInfos fis2 = SegmentReader.ReadFieldInfos(sis[1]);

Assert.AreEqual("f1", fis1.FieldInfo(0).Name);
Assert.AreEqual("f2", fis1.FieldInfo(1).Name);
Expand Down Expand Up @@ -174,7 +174,7 @@ public virtual void TestFieldNumberGaps()
SegmentInfos sis = new SegmentInfos();
sis.Read(dir);
Assert.AreEqual(1, sis.Count);
FieldInfos fis1 = SegmentReader.ReadFieldInfos(sis.Info(0));
FieldInfos fis1 = SegmentReader.ReadFieldInfos(sis[0]);
Assert.AreEqual("f1", fis1.FieldInfo(0).Name);
Assert.AreEqual("f2", fis1.FieldInfo(1).Name);
}
Expand All @@ -189,8 +189,8 @@ public virtual void TestFieldNumberGaps()
SegmentInfos sis = new SegmentInfos();
sis.Read(dir);
Assert.AreEqual(2, sis.Count);
FieldInfos fis1 = SegmentReader.ReadFieldInfos(sis.Info(0));
FieldInfos fis2 = SegmentReader.ReadFieldInfos(sis.Info(1));
FieldInfos fis1 = SegmentReader.ReadFieldInfos(sis[0]);
FieldInfos fis2 = SegmentReader.ReadFieldInfos(sis[1]);
Assert.AreEqual("f1", fis1.FieldInfo(0).Name);
Assert.AreEqual("f2", fis1.FieldInfo(1).Name);
Assert.AreEqual("f1", fis2.FieldInfo(0).Name);
Expand All @@ -209,9 +209,9 @@ public virtual void TestFieldNumberGaps()
SegmentInfos sis = new SegmentInfos();
sis.Read(dir);
Assert.AreEqual(3, sis.Count);
FieldInfos fis1 = SegmentReader.ReadFieldInfos(sis.Info(0));
FieldInfos fis2 = SegmentReader.ReadFieldInfos(sis.Info(1));
FieldInfos fis3 = SegmentReader.ReadFieldInfos(sis.Info(2));
FieldInfos fis1 = SegmentReader.ReadFieldInfos(sis[0]);
FieldInfos fis2 = SegmentReader.ReadFieldInfos(sis[1]);
FieldInfos fis3 = SegmentReader.ReadFieldInfos(sis[2]);
Assert.AreEqual("f1", fis1.FieldInfo(0).Name);
Assert.AreEqual("f2", fis1.FieldInfo(1).Name);
Assert.AreEqual("f1", fis2.FieldInfo(0).Name);
Expand All @@ -238,7 +238,7 @@ public virtual void TestFieldNumberGaps()
SegmentInfos sis_ = new SegmentInfos();
sis_.Read(dir);
Assert.AreEqual(1, sis_.Count);
FieldInfos fis1_ = SegmentReader.ReadFieldInfos(sis_.Info(0));
FieldInfos fis1_ = SegmentReader.ReadFieldInfos(sis_[0]);
Assert.AreEqual("f1", fis1_.FieldInfo(0).Name);
Assert.AreEqual("f2", fis1_.FieldInfo(1).Name);
Assert.AreEqual("f3", fis1_.FieldInfo(2).Name);
Expand Down
6 changes: 3 additions & 3 deletions src/Lucene.Net.Tests/Index/TestPerSegmentDeletes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public virtual void TestDeletes1()
/// fsmp.length = 2;
/// System.out.println("maybeMerge "+writer.SegmentInfos);
///
/// SegmentInfo info0 = writer.SegmentInfos.Info(0);
/// SegmentInfo info1 = writer.SegmentInfos.Info(1);
/// SegmentInfo info0 = writer.SegmentInfos[0];
/// SegmentInfo info1 = writer.SegmentInfos[1];
///
/// writer.MaybeMerge();
/// System.out.println("maybeMerge after "+writer.SegmentInfos);
Expand Down Expand Up @@ -214,7 +214,7 @@ internal virtual void Part2(IndexWriter writer, RangeMergePolicy fsmp)
// deletes for info1, the newly created segment from the
// merge should have no deletes because they were applied in
// the merge
//SegmentInfo info1 = writer.SegmentInfos.Info(1);
//SegmentInfo info1 = writer.SegmentInfos[1];
//Assert.IsFalse(exists(info1, writer.docWriter.segmentDeletes));

//System.out.println("infos4:"+writer.SegmentInfos);
Expand Down
8 changes: 4 additions & 4 deletions src/Lucene.Net.Tests/Index/TestSizeBoundedForceMerge.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Lucene.Net.Documents;
using Lucene.Net.Documents;
using Lucene.Net.Index.Extensions;
using NUnit.Framework;
using Assert = Lucene.Net.TestFramework.Assert;
Expand Down Expand Up @@ -80,7 +80,7 @@ public virtual void TestByteSizeLimit()

SegmentInfos sis = new SegmentInfos();
sis.Read(dir);
double min = sis.Info(0).GetSizeInBytes();
double min = sis[0].GetSizeInBytes();

conf = NewWriterConfig();
LogByteSizeMergePolicy lmp = new LogByteSizeMergePolicy();
Expand Down Expand Up @@ -340,7 +340,7 @@ public virtual void TestSingleMergeableSegment()
SegmentInfos sis = new SegmentInfos();
sis.Read(dir);
Assert.AreEqual(3, sis.Count);
Assert.IsFalse(sis.Info(2).HasDeletions);
Assert.IsFalse(sis[2].HasDeletions);
}

[Test]
Expand Down Expand Up @@ -398,7 +398,7 @@ public virtual void TestSingleMergeableTooLargeSegment()
SegmentInfos sis = new SegmentInfos();
sis.Read(dir);
Assert.AreEqual(1, sis.Count);
Assert.IsTrue(sis.Info(0).HasDeletions);
Assert.IsTrue(sis[0].HasDeletions);
}
}
}
2 changes: 1 addition & 1 deletion src/Lucene.Net/Index/CheckIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ public virtual Status DoCheckIndex(IList<string> onlySegments)

for (int i = 0; i < numSegments; i++)
{
SegmentCommitInfo info = sis.Info(i);
SegmentCommitInfo info = sis[i];
int segmentName = 0;
try
{
Expand Down
6 changes: 3 additions & 3 deletions src/Lucene.Net/Index/IndexWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public virtual bool InfoIsLive(SegmentCommitInfo info)
{
int idx = outerInstance.segmentInfos.IndexOf(info);
Debugging.Assert(idx != -1, "info={0} isn't live", info);
Debugging.Assert(outerInstance.segmentInfos.Info(idx) == info, "info={0} doesn't match live info in segmentInfos", info);
Debugging.Assert(outerInstance.segmentInfos[idx] == info, "info={0} doesn't match live info in segmentInfos", info);
return true;
}
finally
Expand Down Expand Up @@ -2098,7 +2098,7 @@ internal int GetDocCount(int i)
{
if (i >= 0 && i < segmentInfos.Count)
{
return segmentInfos.Info(i).Info.DocCount;
return segmentInfos[i].Info.DocCount;
}
else
{
Expand Down Expand Up @@ -5719,7 +5719,7 @@ internal virtual SegmentCommitInfo NewestSegment()
UninterruptableMonitor.Enter(this);
try
{
return segmentInfos.Count > 0 ? segmentInfos.Info(segmentInfos.Count - 1) : null;
return segmentInfos.Count > 0 ? segmentInfos[segmentInfos.Count - 1] : null;
}
finally
{
Expand Down
24 changes: 12 additions & 12 deletions src/Lucene.Net/Index/LogMergePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected virtual bool IsMerged(SegmentInfos infos, int maxNumSegments, IDiction
bool segmentIsOriginal = false;
for (int i = 0; i < numSegments && numToMerge <= maxNumSegments; i++)
{
SegmentCommitInfo info = infos.Info(i);
SegmentCommitInfo info = infos[i];
if (segmentsToMerge.TryGetValue(info, out bool isOriginal))
{
segmentIsOriginal = isOriginal;
Expand Down Expand Up @@ -260,7 +260,7 @@ private MergeSpecification FindForcedMergesSizeLimit(SegmentInfos infos, /* int
int start = last - 1;
while (start >= 0)
{
SegmentCommitInfo info = infos.Info(start);
SegmentCommitInfo info = infos[start];
if (Size(info) > m_maxMergeSizeForForcedMerge || SizeDocs(info) > m_maxMergeDocs)
{
if (IsVerbose)
Expand All @@ -269,7 +269,7 @@ private MergeSpecification FindForcedMergesSizeLimit(SegmentInfos infos, /* int
}
// need to skip that segment + add a merge for the 'right' segments,
// unless there is only 1 which is merged.
if (last - start - 1 > 1 || (start != last - 1 && !IsMerged(infos, infos.Info(start + 1))))
if (last - start - 1 > 1 || (start != last - 1 && !IsMerged(infos, infos[start + 1])))
{
// there is more than 1 segment to the right of
// this one, or a mergeable single segment.
Expand All @@ -288,7 +288,7 @@ private MergeSpecification FindForcedMergesSizeLimit(SegmentInfos infos, /* int

// Add any left-over segments, unless there is just 1
// already fully merged
if (last > 0 && (++start + 1 < last || !IsMerged(infos, infos.Info(start))))
if (last > 0 && (++start + 1 < last || !IsMerged(infos, infos[start])))
{
spec.Add(new OneMerge(segments.GetView(start, last - start))); // LUCENENET: Converted end index to length
}
Expand Down Expand Up @@ -322,7 +322,7 @@ private MergeSpecification FindForcedMergesMaxNumSegments(SegmentInfos infos, in
{
// Since we must merge down to 1 segment, the
// choice is simple:
if (last > 1 || !IsMerged(infos, infos.Info(0)))
if (last > 1 || !IsMerged(infos, infos[0]))
{
spec.Add(new OneMerge(segments.GetView(0, last))); // LUCENENET: Converted end index to length
}
Expand All @@ -349,9 +349,9 @@ private MergeSpecification FindForcedMergesMaxNumSegments(SegmentInfos infos, in
long sumSize = 0;
for (int j = 0; j < finalMergeSize; j++)
{
sumSize += Size(infos.Info(j + i));
sumSize += Size(infos[j + i]);
}
if (i == 0 || (sumSize < 2 * Size(infos.Info(i - 1)) && sumSize < bestSize))
if (i == 0 || (sumSize < 2 * Size(infos[i - 1]) && sumSize < bestSize))
{
bestStart = i;
bestSize = sumSize;
Expand Down Expand Up @@ -402,7 +402,7 @@ public override MergeSpecification FindForcedMerges(SegmentInfos infos, int maxN
int last = infos.Count;
while (last > 0)
{
SegmentCommitInfo info = infos.Info(--last);
SegmentCommitInfo info = infos[--last];
if (segmentsToMerge.ContainsKey(info))
{
last++;
Expand All @@ -420,7 +420,7 @@ public override MergeSpecification FindForcedMerges(SegmentInfos infos, int maxN
}

// There is only one segment already, and it is merged
if (maxNumSegments == 1 && last == 1 && IsMerged(infos, infos.Info(0)))
if (maxNumSegments == 1 && last == 1 && IsMerged(infos, infos[0]))
{
if (IsVerbose)
{
Expand All @@ -433,7 +433,7 @@ public override MergeSpecification FindForcedMerges(SegmentInfos infos, int maxN
bool anyTooLarge = false;
for (int i = 0; i < last; i++)
{
SegmentCommitInfo info = infos.Info(i);
SegmentCommitInfo info = infos[i];
if (Size(info) > m_maxMergeSizeForForcedMerge || SizeDocs(info) > m_maxMergeDocs)
{
anyTooLarge = true;
Expand Down Expand Up @@ -472,7 +472,7 @@ public override MergeSpecification FindForcedDeletesMerges(SegmentInfos segmentI
if (Debugging.AssertsEnabled) Debugging.Assert(w != null);
for (int i = 0; i < numSegments; i++)
{
SegmentCommitInfo info = segmentInfos.Info(i);
SegmentCommitInfo info = segmentInfos[i];
int delCount = w.NumDeletedDocs(info);
if (delCount > 0)
{
Expand Down Expand Up @@ -568,7 +568,7 @@ public override MergeSpecification FindMerges(MergeTrigger mergeTrigger, Segment

for (int i = 0; i < numSegments; i++)
{
SegmentCommitInfo info = infos.Info(i);
SegmentCommitInfo info = infos[i];
long size = Size(info);

// Floor tiny segments
Expand Down
18 changes: 11 additions & 7 deletions src/Lucene.Net/Index/SegmentInfos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ public static bool UseLegacySegmentNames
/// <para/>
/// This also implements the switch for <see cref="UseLegacySegmentNames"/> so it doesn't have to be dealt with externally.
/// </summary>
/// <
internal static string SegmentNumberToString(long segment, bool allowLegacyNames = true)
{
switch (segment)
Expand Down Expand Up @@ -322,14 +321,19 @@ public SegmentInfos()
{
}

[Obsolete("Use indexer instead. This method will be removed in 4.8.0 release candidate."), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public SegmentCommitInfo Info(int i)
{
return segments[i];
}

/// <summary>
/// Returns <see cref="SegmentCommitInfo"/> at the provided
/// index.
/// <para/>
/// This was info(int) in Lucene.
/// </summary>
public SegmentCommitInfo Info(int i) // LUCENENET TODO: API - add indexer for this class
{
return segments[i];
}
public SegmentCommitInfo this[int index] => segments[index];

/// <summary>
/// Get the generation of the most recent commit to the
Expand Down Expand Up @@ -1296,7 +1300,7 @@ public ICollection<string> GetFiles(Directory dir, bool includeSegmentsFile)
var size = Count;
for (int i = 0; i < size; i++)
{
var info = Info(i);
var info = this[i];
if (Debugging.AssertsEnabled) Debugging.Assert(info.Info.Dir == dir);
if (info.Info.Dir == dir)
{
Expand Down Expand Up @@ -1413,7 +1417,7 @@ public string ToString(Directory directory)
{
buffer.Append(' ');
}
SegmentCommitInfo info = Info(i);
SegmentCommitInfo info = this[i];
buffer.Append(info.ToString(directory, 0));
}
return buffer.ToString();
Expand Down
Loading