Fixed trakt searching, cleaned up indexer/notification modules

This commit is contained in:
Mark McDowall 2013-05-29 20:26:47 -07:00
parent 9181b1bb91
commit f21a235c00
7 changed files with 35 additions and 25 deletions

View file

@ -15,8 +15,8 @@ namespace NzbDrone.Common
return string.Format(format, formattingArgs.Cast<object>());
}
private static readonly Regex InvalidCharRegex = new Regex(@"[^a-z0-9\s-]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex InvalidSearchCharRegex = new Regex(@"[^a-z0-9\s-\.]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex CollapseSpace = new Regex(@"\s+", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static string ToSlug(this string phrase)
@ -30,6 +30,18 @@ namespace NzbDrone.Common
return phrase;
}
public static string ToSearchTerm(this string phrase)
{
phrase = phrase.RemoveAccent().ToLower();
phrase = phrase.Replace("&", "and");
phrase = InvalidSearchCharRegex.Replace(phrase, string.Empty);
phrase = CollapseSpace.Replace(phrase, " ").Trim();
phrase = phrase.Replace(" ", "+");
return phrase;
}
public static string RemoveAccent(this string txt)
{
var bytes = System.Text.Encoding.GetEncoding("Cyrillic").GetBytes(txt);