From 4ae671b633348c60451b3ef068b862df5391ba1b Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Fri, 29 Apr 2022 21:49:23 -0500 Subject: [PATCH] fix trashing episodes with no title (#773) --- CHANGELOG.md | 3 +++ ErsatzTV.Infrastructure/Search/SearchIndex.cs | 27 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65c01aa0b..4385d636e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Fixed +- Fix adding episodes with no title to the search index + - This behavior was preventing some items from being removed from the trash ## [0.5.3-beta] - 2022-04-29 ### Fixed diff --git a/ErsatzTV.Infrastructure/Search/SearchIndex.cs b/ErsatzTV.Infrastructure/Search/SearchIndex.cs index 1b5afef39..0fa0730e9 100644 --- a/ErsatzTV.Infrastructure/Search/SearchIndex.cs +++ b/ErsatzTV.Infrastructure/Search/SearchIndex.cs @@ -85,7 +85,7 @@ public sealed class SearchIndex : ISearchIndex _initialized = false; } - public int Version => 22; + public int Version => 23; public async Task Initialize( ILocalFileSystem localFileSystem, @@ -775,23 +775,10 @@ public sealed class SearchIndex : ISearchIndex { try { - if (string.IsNullOrWhiteSpace(metadata.Title)) - { - _logger.LogWarning( - "Unable to index episode without title {Show} s{Season}e{Episode}", - metadata.Episode.Season?.Show?.ShowMetadata.Head().Title, - metadata.Episode.Season?.SeasonNumber, - metadata.EpisodeNumber); - - continue; - } - var doc = new Document { new StringField(IdField, episode.Id.ToString(), Field.Store.YES), new StringField(TypeField, EpisodeType, Field.Store.YES), - new TextField(TitleField, metadata.Title, Field.Store.NO), - new StringField(SortTitleField, metadata.SortTitle.ToLowerInvariant(), Field.Store.NO), new TextField(LibraryNameField, episode.LibraryPath.Library.Name, Field.Store.NO), new StringField(LibraryIdField, episode.LibraryPath.Library.Id.ToString(), Field.Store.NO), new StringField(TitleAndYearField, GetTitleAndYear(metadata), Field.Store.NO), @@ -802,6 +789,16 @@ public sealed class SearchIndex : ISearchIndex new TextField(ShowTitleField, episode.Season?.Show?.ShowMetadata.Head().Title, Field.Store.NO) }; + if (!string.IsNullOrWhiteSpace(metadata.Title)) + { + doc.Add(new TextField(TitleField, metadata.Title, Field.Store.NO)); + } + + if (!string.IsNullOrWhiteSpace(metadata.SortTitle)) + { + doc.Add(new StringField(SortTitleField, metadata.SortTitle.ToLowerInvariant(), Field.Store.NO)); + } + await AddLanguages(searchRepository, doc, episode.MediaVersions); foreach (MediaVersion version in episode.MediaVersions.HeadOrNone()) @@ -1023,7 +1020,7 @@ public sealed class SearchIndex : ISearchIndex private static string GetJumpLetter(Metadata metadata) { - char c = metadata.SortTitle.ToLowerInvariant().Head(); + char c = (metadata.SortTitle ?? " ").ToLowerInvariant().Head(); return c switch { (>= 'a' and <= 'z') => c.ToString(),