Skip to content

Commit b27135f

Browse files
committed
PR feedback and fix linter error of writer field name
1 parent 157b46b commit b27135f

2 files changed

Lines changed: 27 additions & 30 deletions

File tree

src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingInfixSuggester.cs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public class AnalyzingInfixSuggester : Lookup, IDisposable
102102
/// <summary>
103103
/// Used for ongoing NRT additions/updates. </summary>
104104
// LUCENENET specific - changed from private to protected internal for LUCENE-7564 test support.
105-
protected internal IndexWriter writer;
105+
protected internal IndexWriter m_writer;
106106

107107
/// <summary>
108108
/// <see cref="IndexSearcher"/> used for lookups. </summary>
@@ -307,19 +307,18 @@ public override void Build(IInputEnumerator enumerator)
307307
m_searcherMgr = null;
308308
}
309309

310-
if (writer != null)
310+
if (m_writer != null)
311311
{
312-
writer.Dispose();
313-
writer = null;
312+
m_writer.Dispose();
313+
m_writer = null;
314314
}
315315

316-
AtomicReader r = null;
317316
bool success = false;
318317
try
319318
{
320319
// First pass: build a temporary normal Lucene index,
321320
// just indexing the suggestions as they iterate:
322-
writer = new IndexWriter(dir, indexWriterConfigFactory.Get(matchVersion, GetGramAnalyzer(), OpenMode.CREATE));
321+
m_writer = new IndexWriter(dir, indexWriterConfigFactory.Get(matchVersion, GetGramAnalyzer(), OpenMode.CREATE));
323322
//long t0 = System.nanoTime();
324323

325324
// TODO: use threads?
@@ -345,7 +344,7 @@ public override void Build(IInputEnumerator enumerator)
345344
{
346345
Commit();
347346
}
348-
m_searcherMgr = new SearcherManager(writer, true, null);
347+
m_searcherMgr = new SearcherManager(m_writer, true, null);
349348
success = true;
350349
}
351350
finally
@@ -354,19 +353,17 @@ public override void Build(IInputEnumerator enumerator)
354353
{
355354
if (closeIndexWriterOnBuild) // LUCENENET specific - Support for LUCENE-7564.
356355
{
357-
writer.Dispose();
358-
writer = null;
356+
m_writer.Dispose();
357+
m_writer = null;
359358
}
360-
IOUtils.Dispose(r);
361359
}
362360
else
363361
{
364-
if (writer != null)
362+
if (m_writer != null)
365363
{
366-
writer.Rollback();
367-
writer = null;
364+
m_writer.Rollback();
365+
m_writer = null;
368366
}
369-
IOUtils.DisposeWhileHandlingException(r);
370367
}
371368
}
372369
}
@@ -379,17 +376,17 @@ public override void Build(IInputEnumerator enumerator)
379376
// LUCENENET specific - Support for LUCENE-5889, LUCENE-7564.
380377
public void Commit()
381378
{
382-
if (writer is null)
379+
if (m_writer is null)
383380
{
384381
if (m_searcherMgr is null || closeIndexWriterOnBuild == false)
385382
{
386-
throw IllegalStateException.Create("Cannot commit on an closed writer. Add documents first");
383+
throw IllegalStateException.Create("Cannot commit on a closed writer. Add documents first");
387384
}
388385
// else no-op: writer was committed and closed after the index was built, so commit is unnecessary
389386
}
390387
else
391388
{
392-
writer.Commit();
389+
m_writer.Commit();
393390
}
394391
}
395392

@@ -432,28 +429,28 @@ protected override TokenStreamComponents WrapComponents(string fieldName, TokenS
432429
// LUCENENET specific - Support for LUCENE-5889, LUCENE-7564.
433430
private void EnsureOpen()
434431
{
435-
if (writer != null)
432+
if (m_writer != null)
436433
return;
437434

438435
UninterruptableMonitor.Enter(syncLock);
439436
try
440437
{
441-
if (writer is null)
438+
if (m_writer is null)
442439
{
443440
if (DirectoryReader.IndexExists(dir))
444441
{
445442
// Already built; open it:
446-
writer = new IndexWriter(dir, indexWriterConfigFactory.Get(matchVersion, GetGramAnalyzer(), OpenMode.APPEND));
443+
m_writer = new IndexWriter(dir, indexWriterConfigFactory.Get(matchVersion, GetGramAnalyzer(), OpenMode.APPEND));
447444
}
448445
else
449446
{
450-
writer = new IndexWriter(dir, indexWriterConfigFactory.Get(matchVersion, GetGramAnalyzer(), OpenMode.CREATE));
447+
m_writer = new IndexWriter(dir, indexWriterConfigFactory.Get(matchVersion, GetGramAnalyzer(), OpenMode.CREATE));
451448
}
452449
UninterruptableMonitor.Enter(searcherMgrLock);
453450
try
454451
{
455452
SearcherManager oldSearcherMgr = m_searcherMgr;
456-
m_searcherMgr = new SearcherManager(writer, true, null);
453+
m_searcherMgr = new SearcherManager(m_writer, true, null);
457454
if (oldSearcherMgr != null)
458455
{
459456
oldSearcherMgr.Dispose();
@@ -481,7 +478,7 @@ private void EnsureOpen()
481478
public virtual void Add(BytesRef text, IEnumerable<BytesRef> contexts, long weight, BytesRef payload)
482479
{
483480
EnsureOpen(); // LUCENENET specific - Support for LUCENE-5889.
484-
writer.AddDocument(BuildDocument(text, contexts, weight, payload));
481+
m_writer.AddDocument(BuildDocument(text, contexts, weight, payload));
485482
}
486483

487484
/// <summary>
@@ -496,7 +493,7 @@ public virtual void Add(BytesRef text, IEnumerable<BytesRef> contexts, long weig
496493
public virtual void Update(BytesRef text, IEnumerable<BytesRef> contexts, long weight, BytesRef payload)
497494
{
498495
EnsureOpen(); // LUCENENET specific - Support for LUCENE-5889.
499-
writer.UpdateDocument(new Term(EXACT_TEXT_FIELD_NAME, text.Utf8ToString()), BuildDocument(text, contexts, weight, payload));
496+
m_writer.UpdateDocument(new Term(EXACT_TEXT_FIELD_NAME, text.Utf8ToString()), BuildDocument(text, contexts, weight, payload));
500497
}
501498

502499
private Document BuildDocument(BytesRef text, IEnumerable<BytesRef> contexts, long weight, BytesRef payload)
@@ -539,7 +536,7 @@ public virtual void Refresh()
539536
{
540537
throw IllegalStateException.Create("suggester was not built");
541538
}
542-
if (writer != null) // LUCENENET specific - Support for LUCENE-7564.
539+
if (m_writer != null) // LUCENENET specific - Support for LUCENE-7564.
543540
{
544541
m_searcherMgr.MaybeRefreshBlocking();
545542
}
@@ -975,10 +972,10 @@ protected virtual void Dispose(bool disposing) // LUCENENET specific - implement
975972
m_searcherMgr.Dispose();
976973
m_searcherMgr = null;
977974
}
978-
if (writer != null)
975+
if (m_writer != null)
979976
{
980-
writer.Dispose();
981-
writer = null;
977+
m_writer.Dispose();
978+
m_writer = null;
982979
}
983980
if (dir != null) // LUCENENET specific - Support for LUCENE-7564. Close dir even when writer is null.
984981
{

src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ public MyAnalyzingInfixSuggester(Store.Directory dir, Analyzer indexAnalyzer, An
10471047

10481048
public IndexWriter GetIndexWriter()
10491049
{
1050-
return writer;
1050+
return m_writer;
10511051
}
10521052

10531053
public SearcherManager GetSearcherManager()
@@ -1070,7 +1070,7 @@ public void TestCloseIndexWriterOnBuild()
10701070
// * The IndexWriter should be null
10711071
// * The SearcherManager should be non-null
10721072
// * SearcherManager's IndexWriter reference should be closed
1073-
// (as evidenced by MaybeRefreshBlocking() throwing AlreadyClosedException)
1073+
// (as evidenced by MaybeRefreshBlocking() throwing AlreadyClosedException/ObjectDisposedException)
10741074
Analyzer a = new MockAnalyzer(Random, MockTokenizer.WHITESPACE, false);
10751075
DirectoryInfo tempDir = CreateTempDir("analyzingInfixContext");
10761076
MyAnalyzingInfixSuggester suggester = new MyAnalyzingInfixSuggester(NewFSDirectory(tempDir), a, a, 3, false, true);

0 commit comments

Comments
 (0)