From 383258ac87357a739d560a0a287b95d8046570e1 Mon Sep 17 00:00:00 2001 From: glax Date: Tue, 22 Jul 2025 21:53:14 +0200 Subject: [PATCH] Add Query to get similar Manga by name --- API/Controllers/QueryController.cs | 33 ++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/API/Controllers/QueryController.cs b/API/Controllers/QueryController.cs index e3062b0..b8c692d 100644 --- a/API/Controllers/QueryController.cs +++ b/API/Controllers/QueryController.cs @@ -2,7 +2,7 @@ using API.Schema.MangaContext; using Asp.Versioning; using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; +using Soenneker.Utils.String.NeedlemanWunsch; using static Microsoft.AspNetCore.Http.StatusCodes; // ReSharper disable InconsistentNaming @@ -72,18 +72,33 @@ public class QueryController(MangaContext context) : Controller [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetMangaDownloading() { - Manga[] ret = context.Mangas.Where(m => m.MangaConnectorIds.Any(id => id.UseForDownload)) - .Include(m => m.Library) - .Include(m => m.Authors) - .Include(m => m.MangaTags) - .Include(m => m.Links) - .Include(m => m.AltTitles) - .Include(m => m.Chapters) - .Include(m => m.MangaConnectorIds) + Manga[] ret = context.MangaIncludeAll() + .Where(m => m.MangaConnectorIds.Any(id => id.UseForDownload)) .ToArray(); return Ok(ret); } + /// + /// Returns with names similar to (identified by + /// + /// Key of + /// + /// with not found + [HttpGet("Manga/{MangaId}/SimilarName")] + [ProducesResponseType(Status200OK, "application/json")] + [ProducesResponseType(Status404NotFound)] + public IActionResult GetSimilarManga(string MangaId) + { + if (context.Mangas.Find(MangaId) is not { } manga) + return NotFound(); + string name = manga.Name; + Dictionary mangaNames = context.Mangas.Where(m => m.Key != MangaId).ToDictionary(m => m.Key, m => m.Name); + string[] similarIds = mangaNames + .Where(kv => NeedlemanWunschStringUtil.CalculateSimilarityPercentage(name, kv.Value) > 0.8) + .Select(kv => kv.Key).ToArray(); + return Ok(similarIds); + } + /// /// Returns the with .Key ///