Norbits: duplicate search without diacritics

This commit is contained in:
kaso17
2017-03-09 11:17:10 +01:00
parent 34cdedae12
commit a34a3fb4b6
2 changed files with 160 additions and 134 deletions

View File

@@ -226,14 +226,14 @@ namespace Jackett.Indexers
{
var releases = new List<ReleaseInfo>();
var torrentRowList = new List<CQ>();
var searchTerm = query.GetQueryString();
var exactSearchTerm = query.GetQueryString();
var searchUrl = SearchUrl;
// Check login before performing a query
await CheckLogin();
// Check cache first so we don't query the server (if search term used or not in dev mode)
if (!DevMode && !string.IsNullOrEmpty(searchTerm))
if (!DevMode && !string.IsNullOrEmpty(exactSearchTerm))
{
lock (cache)
{
@@ -241,12 +241,21 @@ namespace Jackett.Indexers
CleanCache();
// Search in cache
var cachedResult = cache.FirstOrDefault(i => i.Query == searchTerm);
var cachedResult = cache.FirstOrDefault(i => i.Query == exactSearchTerm);
if (cachedResult != null)
return cachedResult.Results.Select(s => (ReleaseInfo)s.Clone()).ToArray();
}
}
var SearchTerms = new List<string> { exactSearchTerm };
// duplicate search without diacritics
var baseSearchTerm = StringUtil.RemoveDiacritics(exactSearchTerm);
if (baseSearchTerm != exactSearchTerm)
SearchTerms.Add(baseSearchTerm);
foreach (var searchTerm in SearchTerms)
{
// Build our query
var request = BuildQuery(searchTerm, query, searchUrl);
@@ -282,7 +291,7 @@ namespace Jackett.Indexers
Output("\nNo result found for your query, please try another search term ...\n", "info");
// No result found for this query
return releases;
break;
}
}
@@ -420,7 +429,7 @@ namespace Jackett.Indexers
{
OnParseError("Error, unable to parse result \n" + ex.StackTrace, ex);
}
}
// Return found releases
return releases;
}

View File

@@ -3,6 +3,7 @@ using AngleSharp.Html;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Http;
@@ -28,6 +29,22 @@ namespace Jackett.Utils
return str;
}
// replaces culture specific characters with the corresponding base characters (e.g. è becomes e).
public static String RemoveDiacritics(String s)
{
String normalizedString = s.Normalize(NormalizationForm.FormD);
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < normalizedString.Length; i++)
{
Char c = normalizedString[i];
if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
stringBuilder.Append(c);
}
return stringBuilder.ToString();
}
public static string FromBase64(string str)
{
return Encoding.UTF8.GetString(Convert.FromBase64String(str));