add show_content_rating to search index (#1647)
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- Add `show_studio` to search index for seasons and episodes
|
||||
- Add `show_studio` and `show_content_rating` to search index for seasons and episodes
|
||||
- Add two new global subtitle settings:
|
||||
- `Use embedded subtitles`
|
||||
- Default value: `true`
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ElasticSearchIndex : ISearchIndex
|
||||
return exists.IsValidResponse;
|
||||
}
|
||||
|
||||
public int Version => 41;
|
||||
public int Version => 42;
|
||||
|
||||
public async Task<bool> Initialize(
|
||||
ILocalFileSystem localFileSystem,
|
||||
@@ -162,7 +162,7 @@ public class ElasticSearchIndex : ISearchIndex
|
||||
var items = new List<MinimalElasticSearchItem>();
|
||||
var totalCount = 0;
|
||||
|
||||
Query parsedQuery = LuceneSearchIndex.ParseQuery(query);
|
||||
Query parsedQuery = LuceneSearchIndex.ParseQuery(query, false);
|
||||
|
||||
SearchResponse<MinimalElasticSearchItem> response = await _client.SearchAsync<MinimalElasticSearchItem>(
|
||||
s => s.Index(IndexName)
|
||||
@@ -238,6 +238,7 @@ public class ElasticSearchIndex : ISearchIndex
|
||||
.Text(t => t.ShowGenre, t => t.Store(false))
|
||||
.Text(t => t.ShowTag, t => t.Store(false))
|
||||
.Text(t => t.ShowStudio, t => t.Store(false))
|
||||
.Keyword(t => t.ShowContentRating, t => t.Store(false))
|
||||
.Text(t => t.Style, t => t.Store(false))
|
||||
.Text(t => t.Mood, t => t.Store(false))
|
||||
.Text(t => t.Album, t => t.Store(false))
|
||||
@@ -413,6 +414,7 @@ public class ElasticSearchIndex : ISearchIndex
|
||||
ShowGenre = showMetadata.Genres.Map(g => g.Name).ToList(),
|
||||
ShowTag = showMetadata.Tags.Map(t => t.Name).ToList(),
|
||||
ShowStudio = showMetadata.Studios.Map(s => s.Name).ToList(),
|
||||
ShowContentRating = GetContentRatings(showMetadata.ContentRating),
|
||||
Language = await GetLanguages(
|
||||
searchRepository,
|
||||
await searchRepository.GetLanguagesForSeason(season)),
|
||||
@@ -614,6 +616,7 @@ public class ElasticSearchIndex : ISearchIndex
|
||||
doc.ShowGenre = showMetadata.Genres.Map(g => g.Name).ToList();
|
||||
doc.ShowTag = showMetadata.Tags.Map(t => t.Name).ToList();
|
||||
doc.ShowStudio = showMetadata.Studios.Map(s => s.Name).ToList();
|
||||
doc.ShowContentRating = GetContentRatings(showMetadata.ContentRating);
|
||||
}
|
||||
|
||||
AddStatistics(doc, episode.MediaVersions);
|
||||
|
||||
@@ -64,6 +64,7 @@ public sealed class LuceneSearchIndex : ISearchIndex
|
||||
internal const string ShowGenreField = "show_genre";
|
||||
internal const string ShowTagField = "show_tag";
|
||||
internal const string ShowStudioField = "show_studio";
|
||||
internal const string ShowContentRatingField = "show_content_rating";
|
||||
internal const string MetadataKindField = "metadata_kind";
|
||||
internal const string VideoCodecField = "video_codec";
|
||||
internal const string VideoDynamicRange = "video_dynamic_range";
|
||||
@@ -113,7 +114,7 @@ public sealed class LuceneSearchIndex : ISearchIndex
|
||||
return Task.FromResult(directoryExists && fileExists);
|
||||
}
|
||||
|
||||
public int Version => 41;
|
||||
public int Version => 42;
|
||||
|
||||
public async Task<bool> Initialize(
|
||||
ILocalFileSystem localFileSystem,
|
||||
@@ -735,6 +736,15 @@ public sealed class LuceneSearchIndex : ISearchIndex
|
||||
{
|
||||
doc.Add(new TextField(ShowStudioField, studio.Name, Field.Store.NO));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(showMetadata.ContentRating))
|
||||
{
|
||||
foreach (string contentRating in (showMetadata.ContentRating ?? string.Empty).Split("/")
|
||||
.Map(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x)))
|
||||
{
|
||||
doc.Add(new StringField(ShowContentRatingField, contentRating, Field.Store.NO));
|
||||
}
|
||||
}
|
||||
|
||||
List<string> languages = await searchRepository.GetLanguagesForSeason(season);
|
||||
await AddLanguages(searchRepository, doc, languages);
|
||||
@@ -1017,8 +1027,17 @@ public sealed class LuceneSearchIndex : ISearchIndex
|
||||
{
|
||||
doc.Add(new TextField(ShowStudioField, studio.Name, Field.Store.NO));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(showMetadata.ContentRating))
|
||||
{
|
||||
foreach (string contentRating in (showMetadata.ContentRating ?? string.Empty).Split("/")
|
||||
.Map(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x)))
|
||||
{
|
||||
doc.Add(new StringField(ShowContentRatingField, contentRating, Field.Store.NO));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(metadata.Title))
|
||||
{
|
||||
doc.Add(new TextField(TitleField, metadata.Title, Field.Store.NO));
|
||||
@@ -1353,16 +1372,20 @@ public sealed class LuceneSearchIndex : ISearchIndex
|
||||
doc.Get(TypeField, CultureInfo.InvariantCulture),
|
||||
Convert.ToInt32(doc.Get(IdField, CultureInfo.InvariantCulture), CultureInfo.InvariantCulture));
|
||||
|
||||
internal static Query ParseQuery(string query)
|
||||
internal static Query ParseQuery(string query, bool useCustomAnalyzers = true)
|
||||
{
|
||||
using var analyzer = new StandardAnalyzer(AppLuceneVersion);
|
||||
var customAnalyzers = new Dictionary<string, Analyzer>
|
||||
var customAnalyzers = new Dictionary<string, Analyzer>();
|
||||
|
||||
if (useCustomAnalyzers)
|
||||
{
|
||||
{ ContentRatingField, new KeywordAnalyzer() },
|
||||
{ StateField, new KeywordAnalyzer() }
|
||||
};
|
||||
customAnalyzers.Add(ShowContentRatingField, new KeywordAnalyzer());
|
||||
customAnalyzers.Add(ContentRatingField, new KeywordAnalyzer());
|
||||
customAnalyzers.Add(StateField, new KeywordAnalyzer());
|
||||
}
|
||||
|
||||
using var analyzerWrapper = new PerFieldAnalyzerWrapper(analyzer, customAnalyzers);
|
||||
QueryParser parser = new CustomMultiFieldQueryParser(AppLuceneVersion, new[] { TitleField }, analyzerWrapper);
|
||||
QueryParser parser = new CustomMultiFieldQueryParser(AppLuceneVersion, [TitleField], analyzerWrapper);
|
||||
parser.AllowLeadingWildcard = true;
|
||||
return ParseQuery(query, parser);
|
||||
}
|
||||
|
||||
@@ -117,6 +117,9 @@ public class ElasticSearchItem : MinimalElasticSearchItem
|
||||
|
||||
[JsonPropertyName(LuceneSearchIndex.ShowStudioField)]
|
||||
public List<string> ShowStudio { get; set; }
|
||||
|
||||
[JsonPropertyName(LuceneSearchIndex.ShowContentRatingField)]
|
||||
public List<string> ShowContentRating { get; set; }
|
||||
|
||||
[JsonPropertyName(LuceneSearchIndex.StyleField)]
|
||||
public List<string> Style { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user