Browse Source

search movies and music videos by language (#148)

pull/149/head
Jason Dove 5 years ago committed by GitHub
parent
commit
0aac702853
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      ErsatzTV.Infrastructure/Data/Repositories/SearchRepository.cs
  2. 21
      ErsatzTV.Infrastructure/Search/SearchIndex.cs

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

@ -39,6 +39,8 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
.ThenInclude(mm => mm.Tags) .ThenInclude(mm => mm.Tags)
.Include(mi => (mi as Movie).MovieMetadata) .Include(mi => (mi as Movie).MovieMetadata)
.ThenInclude(mm => mm.Studios) .ThenInclude(mm => mm.Studios)
.Include(mi => (mi as Movie).MediaVersions)
.ThenInclude(mm => mm.Streams)
.Include(mi => (mi as Show).ShowMetadata) .Include(mi => (mi as Show).ShowMetadata)
.ThenInclude(mm => mm.Genres) .ThenInclude(mm => mm.Genres)
.Include(mi => (mi as Show).ShowMetadata) .Include(mi => (mi as Show).ShowMetadata)
@ -51,6 +53,8 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
.ThenInclude(mm => mm.Tags) .ThenInclude(mm => mm.Tags)
.Include(mi => (mi as MusicVideo).MusicVideoMetadata) .Include(mi => (mi as MusicVideo).MusicVideoMetadata)
.ThenInclude(mm => mm.Studios) .ThenInclude(mm => mm.Studios)
.Include(mi => (mi as MusicVideo).MediaVersions)
.ThenInclude(mm => mm.Streams)
.OrderBy(mi => mi.Id) .OrderBy(mi => mi.Id)
.SingleOrDefaultAsync(mi => mi.Id == id) .SingleOrDefaultAsync(mi => mi.Id == id)
.Map(Optional); .Map(Optional);

21
ErsatzTV.Infrastructure/Search/SearchIndex.cs

@ -40,6 +40,7 @@ namespace ErsatzTV.Infrastructure.Search
private const string JumpLetterField = "jump_letter"; private const string JumpLetterField = "jump_letter";
private const string ReleaseDateField = "release_date"; private const string ReleaseDateField = "release_date";
private const string StudioField = "studio"; private const string StudioField = "studio";
private const string LanguageField = "language";
private const string MovieType = "movie"; private const string MovieType = "movie";
private const string ShowType = "show"; private const string ShowType = "show";
@ -52,7 +53,7 @@ namespace ErsatzTV.Infrastructure.Search
public SearchIndex(ILogger<SearchIndex> logger) => _logger = logger; public SearchIndex(ILogger<SearchIndex> logger) => _logger = logger;
public int Version => 2; public int Version => 3;
public Task<bool> Initialize(ILocalFileSystem localFileSystem) public Task<bool> Initialize(ILocalFileSystem localFileSystem)
{ {
@ -231,6 +232,8 @@ namespace ErsatzTV.Infrastructure.Search
new StringField(JumpLetterField, GetJumpLetter(metadata), Field.Store.YES) new StringField(JumpLetterField, GetJumpLetter(metadata), Field.Store.YES)
}; };
AddLanguages(doc, movie.MediaVersions);
if (metadata.ReleaseDate.HasValue) if (metadata.ReleaseDate.HasValue)
{ {
doc.Add( doc.Add(
@ -270,6 +273,20 @@ namespace ErsatzTV.Infrastructure.Search
} }
} }
private void AddLanguages(Document doc, List<MediaVersion> mediaVersions)
{
Option<MediaVersion> maybeVersion = mediaVersions.HeadOrNone();
if (maybeVersion.IsSome)
{
MediaVersion version = maybeVersion.ValueUnsafe();
foreach (string lang in version.Streams.Map(ms => ms.Language).Distinct()
.Filter(s => !string.IsNullOrWhiteSpace(s)))
{
doc.Add(new StringField(LanguageField, lang, Field.Store.NO));
}
}
}
private void UpdateShow(Show show) private void UpdateShow(Show show)
{ {
Option<ShowMetadata> maybeMetadata = show.ShowMetadata.HeadOrNone(); Option<ShowMetadata> maybeMetadata = show.ShowMetadata.HeadOrNone();
@ -350,6 +367,8 @@ namespace ErsatzTV.Infrastructure.Search
new StringField(JumpLetterField, GetJumpLetter(metadata), Field.Store.YES) new StringField(JumpLetterField, GetJumpLetter(metadata), Field.Store.YES)
}; };
AddLanguages(doc, musicVideo.MediaVersions);
if (metadata.ReleaseDate.HasValue) if (metadata.ReleaseDate.HasValue)
{ {
doc.Add( doc.Add(

Loading…
Cancel
Save