diff --git a/ErsatzTV.Infrastructure/Search/SearchIndex.cs b/ErsatzTV.Infrastructure/Search/SearchIndex.cs index af0ed5978..4894ea05f 100644 --- a/ErsatzTV.Infrastructure/Search/SearchIndex.cs +++ b/ErsatzTV.Infrastructure/Search/SearchIndex.cs @@ -40,6 +40,8 @@ namespace ErsatzTV.Infrastructure.Search private const string MovieType = "movie"; private const string ShowType = "show"; + private static bool _isRebuilding; + private readonly ILocalFileSystem _localFileSystem; private readonly string[] _searchFields = { TitleField, GenreField, TagField }; @@ -61,6 +63,8 @@ namespace ErsatzTV.Infrastructure.Search public async Task Rebuild(List itemIds) { + _isRebuilding = true; + await Initialize(); using var dir = FSDirectory.Open(FileSystemLayout.SearchIndexFolder); @@ -86,6 +90,8 @@ namespace ErsatzTV.Infrastructure.Search } } + _isRebuilding = false; + return Unit.Default; } @@ -131,7 +137,8 @@ namespace ErsatzTV.Infrastructure.Search public Task Search(string searchQuery, int skip, int limit, string searchField = "") { - if (string.IsNullOrWhiteSpace(searchQuery.Replace("*", string.Empty).Replace("?", string.Empty))) + if (_isRebuilding || + string.IsNullOrWhiteSpace(searchQuery.Replace("*", string.Empty).Replace("?", string.Empty))) { return new SearchResult(new List(), 0).AsTask(); }