mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.0 KiB
58 lines
2.0 KiB
using System; |
|
using System.Collections.Generic; |
|
using Lucene.Net.Analysis; |
|
using Lucene.Net.QueryParsers.Classic; |
|
using Lucene.Net.Search; |
|
using Lucene.Net.Util; |
|
|
|
namespace ErsatzTV.Infrastructure.Search |
|
{ |
|
public class CustomMultiFieldQueryParser : MultiFieldQueryParser |
|
{ |
|
public CustomMultiFieldQueryParser( |
|
LuceneVersion matchVersion, |
|
string[] fields, |
|
Analyzer analyzer, |
|
IDictionary<string, float> boosts) : base(matchVersion, fields, analyzer, boosts) |
|
{ |
|
} |
|
|
|
public CustomMultiFieldQueryParser(LuceneVersion matchVersion, string[] fields, Analyzer analyzer) : base( |
|
matchVersion, |
|
fields, |
|
analyzer) |
|
{ |
|
} |
|
|
|
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); |
|
} |
|
|
|
return base.GetFieldQuery(field, queryText, quoted); |
|
} |
|
|
|
protected override Query GetFieldQuery(string field, string queryText, int slop) |
|
{ |
|
if (field == "released_inthelast" && CustomQueryParser.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" && CustomQueryParser.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); |
|
} |
|
} |
|
}
|
|
|