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.
Prowlarr/src/NzbDrone.Core/IndexerSearch/Definitions/SearchCriteriaBase.cs

56 lines
2.1 KiB

using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.IndexerSearch.Definitions
{
public abstract class SearchCriteriaBase
{
private static readonly Regex StandardizeDashesRegex = new (@"\p{Pd}+", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex StandardizeSingleQuotesRegex = new (@"[\u0060\u00B4\u2018\u2019]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
public virtual bool InteractiveSearch { get; set; }
public List<int> IndexerIds { get; set; }
public string SearchTerm { get; set; }
public int[] Categories { get; set; }
public string SearchType { get; set; }
public int Limit { get; set; }
public int Offset { get; set; }
public int? MinAge { get; set; }
public int? MaxAge { get; set; }
public long? MinSize { get; set; }
public long? MaxSize { get; set; }
public string Source { get; set; }
public string Host { get; set; }
protected SearchCriteriaBase()
{
Limit = 100;
Offset = 0;
}
public override string ToString() => $"{SearchQuery}, Offset: {Offset}, Limit: {Limit}, Categories: [{string.Join(", ", Categories)}]";
public virtual string SearchQuery => $"Term: [{SearchTerm}]";
public virtual bool IsRssSearch => SearchTerm.IsNullOrWhiteSpace();
public virtual bool IsIdSearch => false;
public string SanitizedSearchTerm => GetSanitizedTerm(SearchTerm);
private static string GetSanitizedTerm(string term)
{
term ??= "";
term = StandardizeDashesRegex.Replace(term, "-");
term = StandardizeSingleQuotesRegex.Replace(term, "'");
var safeTitle = term.Where(c => char.IsLetterOrDigit(c) || char.IsWhiteSpace(c) || c is '-' or '.' or '_' or '(' or ')' or '@' or '/' or '\'' or '[' or ']' or '+' or '%');
return string.Concat(safeTitle);
}
}
}