Allow searching for aliases

This commit is contained in:
Amelia 2025-05-07 23:45:38 +02:00
parent 4b13802301
commit bbea28fd05
No known key found for this signature in database
GPG key ID: D6D0ECE365407EAA

View file

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using API.Data.Misc; using API.Data.Misc;
using API.Data.Repositories; using API.Data.Repositories;
@ -50,7 +51,9 @@ public static class SearchQueryableExtensions
var peopleFromSeriesMetadata = queryable var peopleFromSeriesMetadata = queryable
.Where(sm => seriesIds.Contains(sm.SeriesId)) .Where(sm => seriesIds.Contains(sm.SeriesId))
.SelectMany(sm => sm.People) .SelectMany(sm => sm.People)
.Where(p => p.Person.Name != null && EF.Functions.Like(p.Person.Name, $"%{searchQuery}%")) .Include(sp => sp.Person.Aliases)
.Where(p => (p.Person.Name != null && EF.Functions.Like(p.Person.Name, $"%{searchQuery}%"))
|| p.Person.Aliases.Any(pa => EF.Functions.Like(pa.Alias, $"%{searchQuery}%")))
.Select(p => p.Person); .Select(p => p.Person);
// Get people from ChapterPeople by navigating through Volume -> Series // Get people from ChapterPeople by navigating through Volume -> Series
@ -59,7 +62,9 @@ public static class SearchQueryableExtensions
.SelectMany(sm => sm.Series.Volumes) .SelectMany(sm => sm.Series.Volumes)
.SelectMany(v => v.Chapters) .SelectMany(v => v.Chapters)
.SelectMany(ch => ch.People) .SelectMany(ch => ch.People)
.Where(cp => cp.Person.Name != null && EF.Functions.Like(cp.Person.Name, $"%{searchQuery}%")) .Include(cp => cp.Person.Aliases)
.Where(p => (p.Person.Name != null && EF.Functions.Like(p.Person.Name, $"%{searchQuery}%"))
|| p.Person.Aliases.Any(pa => EF.Functions.Like(pa.Alias, $"%{searchQuery}%")))
.Select(cp => cp.Person); .Select(cp => cp.Person);
// Combine both queries and ensure distinct results // Combine both queries and ensure distinct results