Reworking the search API

This commit is contained in:
Zoe Roux 2020-04-04 15:30:53 +02:00
parent 2fe5d376d9
commit 8df8cd4b20
8 changed files with 28 additions and 18 deletions

View File

@ -1,5 +1,4 @@
using Kyoo.Models;
using Kyoo.Models.Watch;
using System.Collections.Generic;
namespace Kyoo.Controllers
@ -25,7 +24,8 @@ namespace Kyoo.Controllers
//Public read
IEnumerable<Show> GetShows();
IEnumerable<Show> GetShows(string searchQuery);
IEnumerable<Show> SearchShows(string searchQuery);
IEnumerable<Collection> SearchCollections(string searchQuery);
Library GetLibrary(string librarySlug);
IEnumerable<Library> GetLibraries();
Show GetShowBySlug(string slug);

View File

@ -81,6 +81,13 @@ namespace Kyoo.Models
return this;
}
public Episode LoadShowDetails()
{
SetLink(Show.Slug);
ShowTitle = Show.Title;
return this;
}
public Episode Merge(Episode other)
{
if (other == null)

View File

@ -5,6 +5,7 @@ namespace Kyoo.Models
public class SearchResult
{
public string Query;
public IEnumerable<Collection> Collections;
public IEnumerable<Show> Shows;
public IEnumerable<Episode> Episodes;
public IEnumerable<People> People;

View File

@ -1,5 +1,4 @@
using System;
using System.Collections;
using Kyoo.Models;
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;

View File

@ -1,5 +1,4 @@
using System;
using Kyoo.Models;
using Kyoo.Models;
using Kyoo.Models.Watch;
using System.Collections.Generic;
using System.Linq;
@ -70,14 +69,10 @@ namespace Kyoo.Controllers
.OrderBy(x => x.Title);
}
public IEnumerable<Show> GetShows(string searchQuery)
public IEnumerable<Show> SearchShows(string searchQuery)
{
return (from show in _database.Shows from l in _database.CollectionLinks.DefaultIfEmpty()
where l.CollectionID == null select show).AsEnumerable().Union(
from collection in _database.Collections select collection.AsShow())
.Where(x => EF.Functions.Like(x.Title, $"%{searchQuery}%")
|| EF.Functions.Like(x.GetAliases(), $"%{searchQuery}%"))
.Take(20).OrderBy(x => x.Title);
return _database.Shows.FromSqlInterpolated($"SELECT * FROM Shows WHERE Shows.Title LIKE {"%" + searchQuery + "%"} OR Shows.Aliases LIKE {"%" + searchQuery + "%"}")
.OrderBy(x => x.Title).Take(20);
}
public Show GetShowBySlug(string slug)
@ -223,7 +218,7 @@ namespace Kyoo.Controllers
public Collection GetCollection(string slug)
{
Collection collection = _database.Collections.Where(collection => collection.Slug == slug).FirstOrDefault();
Collection collection = _database.Collections.FirstOrDefault(col => col.Slug == slug);
if (collection != null)
collection.Shows = GetShowsInCollection(collection.ID);
return collection;
@ -254,10 +249,17 @@ namespace Kyoo.Controllers
public IEnumerable<Episode> SearchEpisodes(string searchQuery)
{
return (from episode in _database.Episodes where EF.Functions.Like(episode.Title, $"%{searchQuery}%") select episode)
return (from episode in _database.Episodes where EF.Functions.Like(episode.Title, $"%{searchQuery}%")
select episode.LoadShowDetails())
.Take(20);
}
public IEnumerable<Collection> SearchCollections(string searchQuery)
{
return (from collection in _database.Collections where EF.Functions.Like(collection.Name, $"%{searchQuery}%") select collection)
.OrderBy(x => x.Name).Take(20);
}
public IEnumerable<People> SearchPeople(string searchQuery)
{
return (from people in _database.Peoples where EF.Functions.Like(people.Name, $"%{searchQuery}%") select people)

View File

@ -24,7 +24,7 @@ namespace Kyoo.Controllers
{
using (IServiceScope serviceScope = _serviceProvider.CreateScope())
{
serviceScope.ServiceProvider.GetService<DatabaseContext>().Database.Migrate();;
serviceScope.ServiceProvider.GetService<DatabaseContext>().Database.Migrate();
ConfigurationDbContext identityContext = serviceScope.ServiceProvider.GetService<ConfigurationDbContext>();
identityContext.Database.Migrate();

View File

@ -23,7 +23,8 @@ namespace Kyoo.Api
SearchResult result = new SearchResult
{
Query = query,
Shows = _libraryManager.GetShows(query),
Collections = _libraryManager.SearchCollections(query),
Shows = _libraryManager.SearchShows(query),
Episodes = _libraryManager.SearchEpisodes(query),
People = _libraryManager.SearchPeople(query),
Genres = _libraryManager.SearchGenres(query),

@ -1 +1 @@
Subproject commit 576e35fcaba5ed1fc5dafd7e5f2f569c38649c0f
Subproject commit 1a4d6404b11a39380c006bf730ee654d9234989e