* add chapter statistics and new filler options * refactor playout builder * more refactor prep for filler * rewrite schedulers * refactor collectionkey * add tail filler kind * migrate tail filler to filler preset * optionally show filler * fix playout detail row count * remove duration tail filler options * implement tail and fallback in flood scheduler * implement tail and fallback in one scheduler * implement tail and fallback in multiple scheduler * implement looping fallback filler * more duration tests * start to add post-roll filler to flood * rework playoutitem filler tagging * rework scheduler logging * calculate whether configured filler will fit * implement pre-roll and post-roll duration and count filler * improve duration filler calculation * add minutes to search index * update channel guide to work with new filler * add mid-roll filler * don't clone enumerators for filler calculations * support pre-roll and post-roll pad filler * implement mid-roll pad filler * allow clearing filler selections in schedule editor * fix tests * filler config validation * use consistent time zone for tests
115 lines
3.7 KiB
C#
115 lines
3.7 KiB
C#
using System;
|
|
using ErsatzTV.Core;
|
|
using Lucene.Net.Analysis;
|
|
using Lucene.Net.Index;
|
|
using Lucene.Net.QueryParsers.Classic;
|
|
using Lucene.Net.Search;
|
|
using Lucene.Net.Util;
|
|
|
|
namespace ErsatzTV.Infrastructure.Search
|
|
{
|
|
public class CustomQueryParser : QueryParser
|
|
{
|
|
public CustomQueryParser(LuceneVersion matchVersion, string f, Analyzer a) : base(matchVersion, f, a)
|
|
{
|
|
}
|
|
|
|
protected internal CustomQueryParser(ICharStream stream) : base(stream)
|
|
{
|
|
}
|
|
|
|
protected CustomQueryParser(QueryParserTokenManager tm) : base(tm)
|
|
{
|
|
}
|
|
|
|
protected override Query GetFieldQuery(string field, string queryText, bool quoted)
|
|
{
|
|
if (field == "released_onthisday")
|
|
{
|
|
var todayString = DateTime.Today.ToString("*MMdd");
|
|
return base.GetWildcardQuery("release_date", todayString);
|
|
}
|
|
|
|
if (field == "minutes" && int.TryParse(queryText, out int val))
|
|
{
|
|
var bytesRef = new BytesRef();
|
|
NumericUtils.Int32ToPrefixCoded(val, 0, bytesRef);
|
|
return NewTermQuery(new Term("minutes", bytesRef));
|
|
}
|
|
|
|
return base.GetFieldQuery(field, queryText, quoted);
|
|
}
|
|
|
|
protected override Query GetFieldQuery(string field, string queryText, int slop)
|
|
{
|
|
if (field == "released_inthelast" && ParseStart(queryText, out DateTime start))
|
|
{
|
|
var todayString = DateTime.Today.ToString("yyyyMMdd");
|
|
var dateString = start.ToString("yyyyMMdd");
|
|
|
|
return base.GetRangeQuery("release_date", dateString, todayString, true, true);
|
|
}
|
|
|
|
if (field == "released_notinthelast" && ParseStart(queryText, out DateTime finish))
|
|
{
|
|
var dateString = finish.ToString("yyyyMMdd");
|
|
|
|
return base.GetRangeQuery("release_date", "00000000", dateString, false, false);
|
|
}
|
|
|
|
return base.GetFieldQuery(field, queryText, slop);
|
|
}
|
|
|
|
protected override Query GetRangeQuery(string field, string part1, string part2, bool startInclusive, bool endInclusive)
|
|
{
|
|
if (field == "minutes" && int.TryParse(part1, out int min) && int.TryParse(part2, out int max))
|
|
{
|
|
return NumericRangeQuery.NewInt32Range(field, 1, min, max, startInclusive, endInclusive);
|
|
}
|
|
|
|
return base.GetRangeQuery(field, part1, part2, startInclusive, endInclusive);
|
|
}
|
|
|
|
internal static bool ParseStart(string text, out DateTime start)
|
|
{
|
|
start = SystemTime.MinValueUtc;
|
|
|
|
try
|
|
{
|
|
if (int.TryParse(text.Split(" ")[0], out int number))
|
|
{
|
|
if (text.Contains("day"))
|
|
{
|
|
start = DateTime.Today.AddDays(number * -1);
|
|
return true;
|
|
}
|
|
|
|
if (text.Contains("week"))
|
|
{
|
|
start = DateTime.Today.AddDays(number * -7);
|
|
return true;
|
|
}
|
|
|
|
if (text.Contains("month"))
|
|
{
|
|
start = DateTime.Today.AddMonths(number * -1);
|
|
return true;
|
|
}
|
|
|
|
if (text.Contains("year"))
|
|
{
|
|
start = DateTime.Today.AddYears(number * -1);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// do nothing
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|