From 2967e0cd5ff9573829b260d3c286a4afa38608c1 Mon Sep 17 00:00:00 2001 From: Paul Irwin Date: Wed, 13 Mar 2024 17:30:44 -0600 Subject: [PATCH] Make MergeTrigger.NONE be 0, add back previously commented-out assert for null as NONE --- .../Index/TestNoMergeScheduler.cs | 5 ++- src/Lucene.Net/Index/IndexWriter.cs | 44 +++++++++---------- src/Lucene.Net/Index/MergeTrigger.cs | 2 +- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/Lucene.Net.Tests/Index/TestNoMergeScheduler.cs b/src/Lucene.Net.Tests/Index/TestNoMergeScheduler.cs index 403ccb077a..5f22aee545 100644 --- a/src/Lucene.Net.Tests/Index/TestNoMergeScheduler.cs +++ b/src/Lucene.Net.Tests/Index/TestNoMergeScheduler.cs @@ -2,6 +2,7 @@ using NUnit.Framework; using RandomizedTesting.Generators; using System; +using System.Linq; using System.Reflection; using Assert = Lucene.Net.TestFramework.Assert; @@ -34,7 +35,7 @@ public virtual void TestNoMergeScheduler_Mem() { MergeScheduler ms = NoMergeScheduler.INSTANCE; ms.Dispose(); - ms.Merge(null, RandomPicks.RandomFrom(Random, (MergeTrigger[])Enum.GetValues(typeof(MergeTrigger))), Random.NextBoolean()); + ms.Merge(null, RandomPicks.RandomFrom(Random, ((MergeTrigger[])Enum.GetValues(typeof(MergeTrigger))).Where(i => i != MergeTrigger.NONE).ToArray()), Random.NextBoolean()); } [Test] @@ -69,4 +70,4 @@ public virtual void TestMethodsOverridden() } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Index/IndexWriter.cs b/src/Lucene.Net/Index/IndexWriter.cs index fd81b70740..48e651ea92 100644 --- a/src/Lucene.Net/Index/IndexWriter.cs +++ b/src/Lucene.Net/Index/IndexWriter.cs @@ -126,9 +126,9 @@ namespace Lucene.Net.Index /// the and the . /// The is invoked whenever there are /// changes to the segments in the index. Its role is to - /// select which merges to do, if any, and return a + /// select which merges to do, if any, and return a /// describing the merges. - /// The default is . Then, the + /// The default is . Then, the /// is invoked with the requested merges and /// it decides when and how to run the merges. The default is /// . @@ -145,7 +145,7 @@ namespace Lucene.Net.Index /// last commit. You can also just call /// directly. /// - /// NOTE: + /// NOTE: /// instances are completely thread /// safe, meaning multiple threads can call any of its /// methods, concurrently. If your application requires @@ -1074,24 +1074,24 @@ private void MessageState() /// something like this: /// /// - /// try + /// try /// { /// writer.Dispose(); - /// } - /// finally + /// } + /// finally /// { - /// if (IndexWriter.IsLocked(directory)) + /// if (IndexWriter.IsLocked(directory)) /// { /// IndexWriter.Unlock(directory); /// } /// } /// - /// + /// /// after which, you must be certain not to use the writer /// instance anymore. /// /// NOTE: if this method hits an - /// you should immediately dispose the writer, again. See + /// you should immediately dispose the writer, again. See /// for details. /// /// if there is a low-level IO error @@ -1109,7 +1109,7 @@ public void Dispose() /// threads. /// /// NOTE: If this method hits an - /// you should immediately dispose the writer, again. See + /// you should immediately dispose the writer, again. See /// for details. /// /// NOTE: It is dangerous to always call @@ -1160,7 +1160,7 @@ public void Dispose(bool waitForMerges) /// set to true. /// /// NOTE: If this method hits an - /// you should immediately dispose the writer, again. See + /// you should immediately dispose the writer, again. See /// for details. /// /// NOTE: It is dangerous to always call @@ -1594,7 +1594,7 @@ public virtual bool HasDeletions() /// U+FFFD. /// /// NOTE: if this method hits an - /// you should immediately dispose the writer. See + /// you should immediately dispose the writer. See /// for details. /// /// if the index is corrupt @@ -1658,8 +1658,8 @@ public virtual void AddDocument(IEnumerable doc, Analyzer analy /// NOTE: if this method hits an /// you should immediately dispose the writer. See /// for details. - /// - /// @lucene.experimental + /// + /// @lucene.experimental /// /// if the index is corrupt /// if there is a low-level IO error @@ -1746,7 +1746,7 @@ public virtual void UpdateDocuments(Term delTerm, IEnumerable. /// /// NOTE: if this method hits an - /// you should immediately dispose the writer. See + /// you should immediately dispose the writer. See /// for details. /// /// the term to identify the documents to be deleted @@ -1770,7 +1770,7 @@ public virtual void DeleteDocuments(Term term) /// /// Expert: attempts to delete by document ID, as long as - /// the provided is a near-real-time reader (from + /// the provided is a near-real-time reader (from /// . If the /// provided is an NRT reader obtained from this /// writer, and its segment has not been merged away, then @@ -2604,7 +2604,7 @@ private bool UpdatePendingMerges(MergeTrigger trigger, int maxNumSegments) try { if (Debugging.AssertsEnabled) Debugging.Assert(maxNumSegments == -1 || maxNumSegments > 0); - //if (Debugging.AssertsEnabled) Debugging.Assert(trigger != null); // LUCENENET NOTE: Enum cannot be null in .NET + if (Debugging.AssertsEnabled) Debugging.Assert(trigger != MergeTrigger.NONE); // LUCENENET specific: using NONE instead of null if (stopMerges) { return false; @@ -2912,7 +2912,7 @@ private void RollbackInternal() /// documents as deleted. /// /// NOTE: this method will forcefully abort all merges - /// in progress. If other threads are running + /// in progress. If other threads are running /// , or /// methods, they may receive /// s. @@ -3852,8 +3852,8 @@ protected virtual void DoBeforeFlush() /// steps necessary to commit changes since this writer /// was opened: flushes pending added and deleted docs, /// syncs the index files, writes most of next segments_N - /// file. After calling this you must call either - /// to finish the commit, or + /// file. After calling this you must call either + /// to finish the commit, or /// to revert the commit and undo all changes /// done since the writer was opened. /// @@ -6136,7 +6136,7 @@ public static void Unlock(Directory directory) /// after a merge completes. /// /// @lucene.experimental - /// + /// /// NOTE: is called before any deletes have /// been carried over to the merged segment. /// @@ -6485,4 +6485,4 @@ private static bool SlowFileExists(Directory dir, string fileName) } } } -} \ No newline at end of file +} diff --git a/src/Lucene.Net/Index/MergeTrigger.cs b/src/Lucene.Net/Index/MergeTrigger.cs index 6516fe2606..2aa3ebccf6 100644 --- a/src/Lucene.Net/Index/MergeTrigger.cs +++ b/src/Lucene.Net/Index/MergeTrigger.cs @@ -27,7 +27,7 @@ public enum MergeTrigger /// /// LUCENENET-specific value to be used instead of null. /// - NONE = -1, + NONE = 0, /// /// Merge was triggered by a segment flush.