Browse Source

add library search buttons (#177)

pull/178/head
Jason Dove 5 years ago committed by GitHub
parent
commit
49d9b1c714
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      ErsatzTV.Infrastructure/Search/SearchIndex.cs
  2. 7
      ErsatzTV/Pages/Libraries.razor

24
ErsatzTV.Infrastructure/Search/SearchIndex.cs

@ -11,6 +11,9 @@ using ErsatzTV.Core.Interfaces.Search; @@ -11,6 +11,9 @@ using ErsatzTV.Core.Interfaces.Search;
using ErsatzTV.Core.Search;
using LanguageExt;
using LanguageExt.UnsafeValueAccess;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Core;
using Lucene.Net.Analysis.Miscellaneous;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
@ -62,7 +65,7 @@ namespace ErsatzTV.Infrastructure.Search @@ -62,7 +65,7 @@ namespace ErsatzTV.Infrastructure.Search
_cultureInfos = CultureInfo.GetCultures(CultureTypes.NeutralCultures).ToList();
}
public int Version => 7;
public int Version => 8;
public Task<bool> Initialize(ILocalFileSystem localFileSystem)
{
@ -155,9 +158,14 @@ namespace ErsatzTV.Infrastructure.Search @@ -155,9 +158,14 @@ namespace ErsatzTV.Infrastructure.Search
var searcher = new IndexSearcher(reader);
int hitsLimit = limit == 0 ? searcher.IndexReader.MaxDoc : skip + limit;
using var analyzer = new StandardAnalyzer(AppLuceneVersion);
var customAnalyzers = new Dictionary<string, Analyzer>
{
{ LibraryNameField, new KeywordAnalyzer() }
};
using var analyzerWrapper = new PerFieldAnalyzerWrapper(analyzer, customAnalyzers);
QueryParser parser = !string.IsNullOrWhiteSpace(searchField)
? new QueryParser(AppLuceneVersion, searchField, analyzer)
: new MultiFieldQueryParser(AppLuceneVersion, new[] { TitleField }, analyzer);
? new QueryParser(AppLuceneVersion, searchField, analyzerWrapper)
: new MultiFieldQueryParser(AppLuceneVersion, new[] { TitleField }, analyzerWrapper);
parser.AllowLeadingWildcard = true;
Query query = ParseQuery(searchQuery, parser);
var filter = new DuplicateFilter(TitleAndYearField);
@ -251,7 +259,7 @@ namespace ErsatzTV.Infrastructure.Search @@ -251,7 +259,7 @@ namespace ErsatzTV.Infrastructure.Search
new StringField(TypeField, MovieType, Field.Store.NO),
new TextField(TitleField, metadata.Title, Field.Store.NO),
new StringField(SortTitleField, metadata.SortTitle.ToLowerInvariant(), Field.Store.NO),
new TextField(LibraryNameField, movie.LibraryPath.Library.Name, Field.Store.NO),
new StringField(LibraryNameField, movie.LibraryPath.Library.Name, Field.Store.NO),
new StringField(TitleAndYearField, GetTitleAndYear(metadata), Field.Store.NO),
new StringField(JumpLetterField, GetJumpLetter(metadata), Field.Store.YES)
};
@ -338,7 +346,7 @@ namespace ErsatzTV.Infrastructure.Search @@ -338,7 +346,7 @@ namespace ErsatzTV.Infrastructure.Search
new StringField(TypeField, ShowType, Field.Store.NO),
new TextField(TitleField, metadata.Title, Field.Store.NO),
new StringField(SortTitleField, metadata.SortTitle.ToLowerInvariant(), Field.Store.NO),
new TextField(LibraryNameField, show.LibraryPath.Library.Name, Field.Store.NO),
new StringField(LibraryNameField, show.LibraryPath.Library.Name, Field.Store.NO),
new StringField(TitleAndYearField, GetTitleAndYear(metadata), Field.Store.NO),
new StringField(JumpLetterField, GetJumpLetter(metadata), Field.Store.YES)
};
@ -418,7 +426,7 @@ namespace ErsatzTV.Infrastructure.Search @@ -418,7 +426,7 @@ namespace ErsatzTV.Infrastructure.Search
new StringField(TypeField, ArtistType, Field.Store.NO),
new TextField(TitleField, metadata.Title, Field.Store.NO),
new StringField(SortTitleField, metadata.SortTitle.ToLowerInvariant(), Field.Store.NO),
new TextField(LibraryNameField, artist.LibraryPath.Library.Name, Field.Store.NO),
new StringField(LibraryNameField, artist.LibraryPath.Library.Name, Field.Store.NO),
new StringField(TitleAndYearField, GetTitleAndYear(metadata), Field.Store.NO),
new StringField(JumpLetterField, GetJumpLetter(metadata), Field.Store.YES)
};
@ -479,7 +487,7 @@ namespace ErsatzTV.Infrastructure.Search @@ -479,7 +487,7 @@ namespace ErsatzTV.Infrastructure.Search
new StringField(TypeField, MusicVideoType, Field.Store.NO),
new TextField(TitleField, metadata.Title, Field.Store.NO),
new StringField(SortTitleField, metadata.SortTitle.ToLowerInvariant(), Field.Store.NO),
new TextField(LibraryNameField, musicVideo.LibraryPath.Library.Name, Field.Store.NO),
new StringField(LibraryNameField, musicVideo.LibraryPath.Library.Name, Field.Store.NO),
new StringField(TitleAndYearField, GetTitleAndYear(metadata), Field.Store.NO),
new StringField(JumpLetterField, GetJumpLetter(metadata), Field.Store.YES)
};
@ -543,7 +551,7 @@ namespace ErsatzTV.Infrastructure.Search @@ -543,7 +551,7 @@ namespace ErsatzTV.Infrastructure.Search
}
private static string GetTitleAndYear(Metadata metadata) =>
$"{metadata.Title}_{metadata.Year}";
$"{metadata.Title}_{metadata.Year}".ToLowerInvariant();
private static string GetJumpLetter(Metadata metadata)
{

7
ErsatzTV/Pages/Libraries.razor

@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
<col/>
<col/>
<col/>
<col style="width: 180px;"/>
<col style="width: 240px;"/>
</ColGroup>
<HeaderContent>
<MudTh>Library Kind</MudTh>
@ -60,6 +60,11 @@ @@ -60,6 +60,11 @@
</MudIconButton>
</MudTooltip>
}
<MudTooltip Text="Search Library">
<MudIconButton Icon="@Icons.Material.Filled.Search"
Link="@($"/search?query=library_name%3a%22{Uri.EscapeDataString(context.Name)}%22")">
</MudIconButton>
</MudTooltip>
@if (context is LocalLibraryViewModel)
{
<MudTooltip Text="Edit Library">

Loading…
Cancel
Save