From 58a62f827239fb17fd26435a2339de3db8f5a05b Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 2 Jul 2023 23:54:02 +0200 Subject: [PATCH] Mangasee search all title-fields. --- Tranga/Connectors/Mangasee.cs | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Tranga/Connectors/Mangasee.cs b/Tranga/Connectors/Mangasee.cs index 432f419..45cf35a 100644 --- a/Tranga/Connectors/Mangasee.cs +++ b/Tranga/Connectors/Mangasee.cs @@ -91,10 +91,9 @@ public class Mangasee : Connector Dictionary queryFiltered = new(); foreach (SearchResultItem resultItem in result) { - foreach (string term in publicationTitle.Split(' ')) - if (resultItem.i.Contains(term, StringComparison.CurrentCultureIgnoreCase)) - if (!queryFiltered.TryAdd(resultItem, 0)) - queryFiltered[resultItem]++; + int matches = resultItem.GetMatches(publicationTitle); + if (matches > 0) + queryFiltered.TryAdd(resultItem, matches); } queryFiltered = queryFiltered.Where(item => item.Value >= publicationTitle.Split(' ').Length - 1) @@ -180,6 +179,30 @@ public class Mangasee : Connector public string s { get; set; } public string[] a { get; set; } #pragma warning restore CS8618 + + public int GetMatches(string title) + { + int ret = 0; + Regex cleanRex = new("[A-z0-9]*"); + string[] badWords = { "a", "so", "as", "and" }; + + string[] titleTerms = title.Split(new[] { ' ', '-' }).Where(str => !badWords.Contains(str)).ToArray(); + + foreach (Match matchTerm in cleanRex.Matches(this.i)) + ret += titleTerms.Count(titleTerm => + titleTerm.Equals(matchTerm.Value, StringComparison.OrdinalIgnoreCase)); + + foreach (Match matchTerm in cleanRex.Matches(this.s)) + ret += titleTerms.Count(titleTerm => + titleTerm.Equals(matchTerm.Value, StringComparison.OrdinalIgnoreCase)); + + foreach(string alt in this.a) + foreach (Match matchTerm in cleanRex.Matches(alt)) + ret += titleTerms.Count(titleTerm => + titleTerm.Equals(matchTerm.Value, StringComparison.OrdinalIgnoreCase)); + + return ret; + } } public override Chapter[] GetChapters(Publication publication, string language = "")