Skip to content

Commit

Permalink
Actively checks if the lucene searcher has been disposed before creat…
Browse files Browse the repository at this point in the history
…ing a search context, throws more informative error
  • Loading branch information
Shazwazza committed Jul 14, 2020
1 parent 400b8be commit 9d90c8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Examine/LuceneEngine/Providers/LuceneSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public override Searcher GetLuceneSearcher()

public override ISearchContext GetSearchContext()
{
var searcher = GetLuceneSearcher();
if (searcher == null)
throw new InvalidOperationException($"Cannot create a {typeof(ISearchContext)}, the {Name} index either doesn't exist or the {typeof(LuceneSearcher)} has been disposed");
return new SearchContext(FieldValueTypeCollection, GetLuceneSearcher());
}

Expand Down Expand Up @@ -181,6 +184,7 @@ private bool ValidateSearcher()
{
//can't proceed if there's no index
if (!IndexExistsImpl()) return false;
if (_disposed) return false;

//TODO: Would be nicer if this used LazyInitializer instead of double check locking

Expand Down
4 changes: 2 additions & 2 deletions src/Examine/LuceneEngine/Search/SearchContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class SearchContext : ISearchContext

public SearchContext(FieldValueTypeCollection fieldValueTypeCollection, Searcher searcher)
{
_fieldValueTypeCollection = fieldValueTypeCollection;
Searcher = searcher;
_fieldValueTypeCollection = fieldValueTypeCollection ?? throw new System.ArgumentNullException(nameof(fieldValueTypeCollection));
Searcher = searcher ?? throw new System.ArgumentNullException(nameof(searcher));
}

public Searcher Searcher { get; }
Expand Down

0 comments on commit 9d90c8f

Please sign in to comment.