Cleaning up searches

This commit is contained in:
Zoe Roux 2021-03-10 00:46:17 +01:00
parent d3d2677a83
commit 356b8a5472
11 changed files with 45 additions and 13 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Kyoo.Models;
using Kyoo.Models.Attributes;
@ -58,10 +59,22 @@ namespace Kyoo.Controllers
{
public override void WriteJson(JsonWriter writer, PeopleRole value, JsonSerializer serializer)
{
// TODO this seems to not use the property.ShouldSerialize and cause an recursive inclusion error.
JToken t = JToken.FromObject(value, serializer);
JObject obj = t as JObject;
writer.WriteValue(obj);
ICollection<PeopleRole> oldPeople = value.Show?.People;
ICollection<PeopleRole> oldRoles = value.People?.Roles;
if (value.Show != null)
value.Show.People = null;
if (value.People != null)
value.People.Roles = null;
JObject obj = JObject.FromObject(value.ForPeople ? value.People : value.Show, serializer);
obj.Add("role", value.Role);
obj.Add("type", value.Type);
obj.WriteTo(writer);
if (value.Show != null)
value.Show.People = oldPeople;
if (value.People != null)
value.People.Roles = oldRoles;
}
public override PeopleRole ReadJson(JsonReader reader,

View File

@ -40,6 +40,7 @@ namespace Kyoo.Controllers
{
return await _database.Collections
.Where(x => EF.Functions.ILike(x.Name, $"%{query}%"))
.OrderBy(DefaultSort)
.Take(20)
.ToListAsync();
}

View File

@ -125,7 +125,8 @@ namespace Kyoo.Controllers
public override async Task<ICollection<Episode>> Search(string query)
{
List<Episode> episodes = await _database.Episodes
.Where(x => EF.Functions.ILike(x.Title, $"%{query}%"))
.Where(x => EF.Functions.ILike(x.Title, $"%{query}%") && x.EpisodeNumber != -1)
.OrderBy(DefaultSort)
.Take(20)
.ToListAsync();
foreach (Episode episode in episodes)

View File

@ -41,6 +41,7 @@ namespace Kyoo.Controllers
{
return await _database.Genres
.Where(genre => EF.Functions.ILike(genre.Name, $"%{query}%"))
.OrderBy(DefaultSort)
.Take(20)
.ToListAsync();
}

View File

@ -96,6 +96,7 @@ namespace Kyoo.Controllers
{
return await ItemsQuery
.Where(x => EF.Functions.ILike(x.Title, $"%{query}%"))
.OrderBy(DefaultSort)
.Take(20)
.ToListAsync();
}

View File

@ -46,6 +46,7 @@ namespace Kyoo.Controllers
{
return await _database.Libraries
.Where(x => EF.Functions.ILike(x.Name, $"%{query}%"))
.OrderBy(DefaultSort)
.Take(20)
.ToListAsync();
}

View File

@ -54,6 +54,7 @@ namespace Kyoo.Controllers
{
return await _database.People
.Where(people => EF.Functions.ILike(people.Name, $"%{query}%"))
.OrderBy(DefaultSort)
.Take(20)
.ToListAsync();
}
@ -97,7 +98,9 @@ namespace Kyoo.Controllers
Sort<PeopleRole> sort = default,
Pagination limit = default)
{
ICollection<PeopleRole> people = await ApplyFilters(_database.PeopleRoles.Where(x => x.ShowID == showID),
ICollection<PeopleRole> people = await ApplyFilters(_database.PeopleRoles
.Where(x => x.ShowID == showID)
.Include(x => x.People),
id => _database.PeopleRoles.FirstOrDefaultAsync(x => x.ID == id),
x => x.People.Name,
where,
@ -105,6 +108,8 @@ namespace Kyoo.Controllers
limit);
if (!people.Any() && await _shows.Value.Get(showID) == null)
throw new ItemNotFound();
foreach (PeopleRole role in people)
role.ForPeople = true;
return people;
}
@ -113,7 +118,10 @@ namespace Kyoo.Controllers
Sort<PeopleRole> sort = default,
Pagination limit = default)
{
ICollection<PeopleRole> people = await ApplyFilters(_database.PeopleRoles.Where(x => x.Show.Slug == showSlug),
ICollection<PeopleRole> people = await ApplyFilters(_database.PeopleRoles
.Where(x => x.Show.Slug == showSlug)
.Include(x => x.People)
.Include(x => x.Show),
id => _database.PeopleRoles.FirstOrDefaultAsync(x => x.ID == id),
x => x.People.Name,
where,
@ -121,6 +129,8 @@ namespace Kyoo.Controllers
limit);
if (!people.Any() && await _shows.Value.Get(showSlug) == null)
throw new ItemNotFound();
foreach (PeopleRole role in people)
role.ForPeople = true;
return people;
}
@ -129,7 +139,9 @@ namespace Kyoo.Controllers
Sort<PeopleRole> sort = default,
Pagination limit = default)
{
ICollection<PeopleRole> roles = await ApplyFilters(_database.PeopleRoles.Where(x => x.PeopleID == peopleID),
ICollection<PeopleRole> roles = await ApplyFilters(_database.PeopleRoles
.Where(x => x.PeopleID == peopleID)
.Include(x => x.Show),
id => _database.PeopleRoles.FirstOrDefaultAsync(x => x.ID == id),
x => x.Show.Title,
where,
@ -137,8 +149,6 @@ namespace Kyoo.Controllers
limit);
if (!roles.Any() && await Get(peopleID) == null)
throw new ItemNotFound();
foreach (PeopleRole role in roles)
role.ForPeople = true;
return roles;
}
@ -147,7 +157,9 @@ namespace Kyoo.Controllers
Sort<PeopleRole> sort = default,
Pagination limit = default)
{
ICollection<PeopleRole> roles = await ApplyFilters(_database.PeopleRoles.Where(x => x.People.Slug == slug),
ICollection<PeopleRole> roles = await ApplyFilters(_database.PeopleRoles
.Where(x => x.People.Slug == slug)
.Include(x => x.Show),
id => _database.PeopleRoles.FirstOrDefaultAsync(x => x.ID == id),
x => x.Show.Title,
where,
@ -155,8 +167,6 @@ namespace Kyoo.Controllers
limit);
if (!roles.Any() && await Get(slug) == null)
throw new ItemNotFound();
foreach (PeopleRole role in roles)
role.ForPeople = true;
return roles;
}
}

View File

@ -23,6 +23,7 @@ namespace Kyoo.Controllers
{
return await _database.Providers
.Where(x => EF.Functions.ILike(x.Name, $"%{query}%"))
.OrderBy(DefaultSort)
.Take(20)
.ToListAsync();
}

View File

@ -105,6 +105,7 @@ namespace Kyoo.Controllers
{
List<Season> seasons = await _database.Seasons
.Where(x => EF.Functions.ILike(x.Title, $"%{query}%"))
.OrderBy(DefaultSort)
.Take(20)
.ToListAsync();
foreach (Season season in seasons)

View File

@ -79,6 +79,7 @@ namespace Kyoo.Controllers
.Where(x => EF.Functions.ILike(x.Title, query)
|| EF.Functions.ILike(x.Slug, query)
/*|| x.Aliases.Any(y => EF.Functions.ILike(y, query))*/) // NOT TRANSLATABLE.
.OrderBy(DefaultSort)
.Take(20)
.ToListAsync();
}

View File

@ -23,6 +23,7 @@ namespace Kyoo.Controllers
{
return await _database.Studios
.Where(x => EF.Functions.ILike(x.Name, $"%{query}%"))
.OrderBy(DefaultSort)
.Take(20)
.ToListAsync();
}