People Aliases and Merging (#3795)
Co-authored-by: Joseph Milazzo <josephmajora@gmail.com>
This commit is contained in:
parent
cd2a6af6f2
commit
7ce36bfc44
67 changed files with 5288 additions and 284 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using API.Data.Misc;
|
||||
using API.Data.Repositories;
|
||||
|
|
@ -49,23 +50,26 @@ public static class SearchQueryableExtensions
|
|||
// Get people from SeriesMetadata
|
||||
var peopleFromSeriesMetadata = queryable
|
||||
.Where(sm => seriesIds.Contains(sm.SeriesId))
|
||||
.SelectMany(sm => sm.People)
|
||||
.Where(p => p.Person.Name != null && EF.Functions.Like(p.Person.Name, $"%{searchQuery}%"))
|
||||
.Select(p => p.Person);
|
||||
.SelectMany(sm => sm.People.Select(sp => sp.Person))
|
||||
.Where(p =>
|
||||
EF.Functions.Like(p.Name, $"%{searchQuery}%") ||
|
||||
p.Aliases.Any(pa => EF.Functions.Like(pa.Alias, $"%{searchQuery}%"))
|
||||
);
|
||||
|
||||
// Get people from ChapterPeople by navigating through Volume -> Series
|
||||
var peopleFromChapterPeople = queryable
|
||||
.Where(sm => seriesIds.Contains(sm.SeriesId))
|
||||
.SelectMany(sm => sm.Series.Volumes)
|
||||
.SelectMany(v => v.Chapters)
|
||||
.SelectMany(ch => ch.People)
|
||||
.Where(cp => cp.Person.Name != null && EF.Functions.Like(cp.Person.Name, $"%{searchQuery}%"))
|
||||
.Select(cp => cp.Person);
|
||||
.SelectMany(ch => ch.People.Select(cp => cp.Person))
|
||||
.Where(p =>
|
||||
EF.Functions.Like(p.Name, $"%{searchQuery}%") ||
|
||||
p.Aliases.Any(pa => EF.Functions.Like(pa.Alias, $"%{searchQuery}%"))
|
||||
);
|
||||
|
||||
// Combine both queries and ensure distinct results
|
||||
return peopleFromSeriesMetadata
|
||||
.Union(peopleFromChapterPeople)
|
||||
.Distinct()
|
||||
.Select(p => p)
|
||||
.OrderBy(p => p.NormalizedName);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using System.Linq;
|
||||
using API.Data.Repositories;
|
||||
using API.Entities;
|
||||
using API.Entities.Metadata;
|
||||
using API.Entities.Person;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Extensions.QueryExtensions;
|
||||
|
|
@ -321,4 +321,25 @@ public static class IncludesExtensions
|
|||
|
||||
return query.AsSplitQuery();
|
||||
}
|
||||
|
||||
public static IQueryable<Person> Includes(this IQueryable<Person> queryable, PersonIncludes includeFlags)
|
||||
{
|
||||
|
||||
if (includeFlags.HasFlag(PersonIncludes.Aliases))
|
||||
{
|
||||
queryable = queryable.Include(p => p.Aliases);
|
||||
}
|
||||
|
||||
if (includeFlags.HasFlag(PersonIncludes.ChapterPeople))
|
||||
{
|
||||
queryable = queryable.Include(p => p.ChapterPeople);
|
||||
}
|
||||
|
||||
if (includeFlags.HasFlag(PersonIncludes.SeriesPeople))
|
||||
{
|
||||
queryable = queryable.Include(p => p.SeriesMetadataPeople);
|
||||
}
|
||||
|
||||
return queryable;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue