Browse Source

index song genres (#513)

* add song genres to search index

* reset all song genre metadata

* update changelog and docs
pull/514/head
Jason Dove 4 years ago committed by GitHub
parent
commit
7f84933c0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      CHANGELOG.md
  2. 15
      ErsatzTV.Core/Metadata/LocalMetadataProvider.cs
  3. 2
      ErsatzTV.Infrastructure/Data/Repositories/SearchRepository.cs
  4. 3843
      ErsatzTV.Infrastructure/Migrations/20211127205227_Reset_SongMetadataGenres.Designer.cs
  5. 33
      ErsatzTV.Infrastructure/Migrations/20211127205227_Reset_SongMetadataGenres.cs
  6. 5
      ErsatzTV.Infrastructure/Search/SearchIndex.cs
  7. 1
      docs/user-guide/search.md

4
CHANGELOG.md

@ -9,6 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -9,6 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Show song artist in playout detail
- Include song artist and cover art in channel guide (xmltv)
- Use subtitles to display errors, which fixes many edge cases of unescaped characters
- Properly split song genre tags
### Added
- Add song genres to search index
### Changed
- Randomly place song cover art on left or right side of screen

15
ErsatzTV.Core/Metadata/LocalMetadataProvider.cs

@ -248,8 +248,7 @@ namespace ErsatzTV.Core.Metadata @@ -248,8 +248,7 @@ namespace ErsatzTV.Core.Metadata
if (tags.TryGetValue(MetadataFormatTag.Genre, out string genre))
{
// TODO: split genres? or is this only ever one?
result.Genres.Add(new Genre { Name = genre });
result.Genres.AddRange(SplitGenres(genre).Map(n => new Genre { Name = n }));
}
if (tags.TryGetValue(MetadataFormatTag.Title, out string title))
@ -1140,5 +1139,17 @@ namespace ErsatzTV.Core.Metadata @@ -1140,5 +1139,17 @@ namespace ErsatzTV.Core.Metadata
return result;
}
private static IEnumerable<string> SplitGenres(string genre)
{
char[] delimiters = new[] { '/', '|', ';', '\\' }
.Filter(d => genre.IndexOf(d, StringComparison.OrdinalIgnoreCase) != -1)
.DefaultIfEmpty(',')
.ToArray();
return genre.Split(delimiters, StringSplitOptions.RemoveEmptyEntries)
.Where(i => !string.IsNullOrWhiteSpace(i))
.Select(i => i.Trim());
}
}
}

2
ErsatzTV.Infrastructure/Data/Repositories/SearchRepository.cs

@ -103,6 +103,8 @@ namespace ErsatzTV.Infrastructure.Data.Repositories @@ -103,6 +103,8 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
.ThenInclude(mm => mm.Streams)
.Include(mi => (mi as Song).SongMetadata)
.ThenInclude(mm => mm.Tags)
.Include(mi => (mi as Song).SongMetadata)
.ThenInclude(mm => mm.Genres)
.Include(mi => (mi as Song).MediaVersions)
.ThenInclude(mm => mm.Streams)
.Include(mi => mi.TraktListItems)

3843
ErsatzTV.Infrastructure/Migrations/20211127205227_Reset_SongMetadataGenres.Designer.cs generated

File diff suppressed because it is too large Load Diff

33
ErsatzTV.Infrastructure/Migrations/20211127205227_Reset_SongMetadataGenres.cs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ErsatzTV.Infrastructure.Migrations
{
public partial class Reset_SongMetadataGenres : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"DELETE FROM Genre WHERE SongMetadataId IS NOT NULL");
migrationBuilder.Sql(
@"UPDATE LibraryPath SET LastScan = '0001-01-01 00:00:00' WHERE Id IN
(SELECT LP.Id FROM LibraryPath LP INNER JOIN Library L on L.Id = LP.LibraryId WHERE MediaKind = 5)");
migrationBuilder.Sql(
@"UPDATE Library SET LastScan = '0001-01-01 00:00:00' WHERE MediaKind = 5");
migrationBuilder.Sql(
@"UPDATE SongMetadata SET DateUpdated = '0001-01-01 00:00:00'");
migrationBuilder.Sql(
@"UPDATE LibraryFolder SET Etag = NULL WHERE Id IN
(SELECT LF.Id FROM LibraryFolder LF INNER JOIN LibraryPath LP on LF.LibraryPathId = LP.Id INNER JOIN Library L on LP.LibraryId = L.Id WHERE MediaKind = 5)");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

5
ErsatzTV.Infrastructure/Search/SearchIndex.cs

@ -867,6 +867,11 @@ namespace ErsatzTV.Infrastructure.Search @@ -867,6 +867,11 @@ namespace ErsatzTV.Infrastructure.Search
doc.Add(new TextField(TagField, tag.Name, Field.Store.NO));
}
foreach (Genre genre in metadata.Genres)
{
doc.Add(new TextField(GenreField, genre.Name, Field.Store.NO));
}
_writer.UpdateDocument(new Term(IdField, song.Id.ToString()), doc);
}
catch (Exception ex)

1
docs/user-guide/search.md

@ -97,6 +97,7 @@ The following fields are available for searching songs: @@ -97,6 +97,7 @@ The following fields are available for searching songs:
- `title`: The song title, or the filename of the song (without extension)
- `album`: The song album
- `artist`: The song artist
- `genre`: The song genre
- `tag`: All of the song's parent folders
- `minutes`: the rounded-up whole number duration of the song in minutes
- `type`: Always `song`

Loading…
Cancel
Save