diff --git a/Kyoo.Common/Controllers/ILibraryManager.cs b/Kyoo.Common/Controllers/ILibraryManager.cs index adbb055f..c8c00a82 100644 --- a/Kyoo.Common/Controllers/ILibraryManager.cs +++ b/Kyoo.Common/Controllers/ILibraryManager.cs @@ -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 GetShows(); - IEnumerable GetShows(string searchQuery); + IEnumerable SearchShows(string searchQuery); + IEnumerable SearchCollections(string searchQuery); Library GetLibrary(string librarySlug); IEnumerable GetLibraries(); Show GetShowBySlug(string slug); diff --git a/Kyoo.Common/Models/Episode.cs b/Kyoo.Common/Models/Episode.cs index 96cbd0c6..9106b0f9 100644 --- a/Kyoo.Common/Models/Episode.cs +++ b/Kyoo.Common/Models/Episode.cs @@ -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) diff --git a/Kyoo.Common/Models/SearchResult.cs b/Kyoo.Common/Models/SearchResult.cs index a9fd9a38..42a25bcf 100644 --- a/Kyoo.Common/Models/SearchResult.cs +++ b/Kyoo.Common/Models/SearchResult.cs @@ -5,6 +5,7 @@ namespace Kyoo.Models public class SearchResult { public string Query; + public IEnumerable Collections; public IEnumerable Shows; public IEnumerable Episodes; public IEnumerable People; diff --git a/Kyoo/Controllers/Crawler.cs b/Kyoo/Controllers/Crawler.cs index afcc5684..46358435 100644 --- a/Kyoo/Controllers/Crawler.cs +++ b/Kyoo/Controllers/Crawler.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using Kyoo.Models; using Microsoft.Extensions.Configuration; using System.Collections.Generic; diff --git a/Kyoo/Controllers/LibraryManager.cs b/Kyoo/Controllers/LibraryManager.cs index 7fbb1f1c..5a36ee83 100644 --- a/Kyoo/Controllers/LibraryManager.cs +++ b/Kyoo/Controllers/LibraryManager.cs @@ -1,5 +1,4 @@ -using System; -using Kyoo.Models; +using Kyoo.Models; using Kyoo.Models.Watch; using System.Collections.Generic; using System.Linq; @@ -58,7 +57,7 @@ namespace Kyoo.Controllers { return (from track in _database.Tracks where track.ID == id select track).FirstOrDefault(); } - + public Library GetLibrary(string librarySlug) { return (from library in _database.Libraries where library.Slug == librarySlug select library).FirstOrDefault(); @@ -70,14 +69,10 @@ namespace Kyoo.Controllers .OrderBy(x => x.Title); } - public IEnumerable GetShows(string searchQuery) + public IEnumerable 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 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 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 SearchPeople(string searchQuery) { return (from people in _database.Peoples where EF.Functions.Like(people.Name, $"%{searchQuery}%") select people) diff --git a/Kyoo/Controllers/StartupCode.cs b/Kyoo/Controllers/StartupCode.cs index 18a95ca3..f0b28f4c 100644 --- a/Kyoo/Controllers/StartupCode.cs +++ b/Kyoo/Controllers/StartupCode.cs @@ -24,7 +24,7 @@ namespace Kyoo.Controllers { using (IServiceScope serviceScope = _serviceProvider.CreateScope()) { - serviceScope.ServiceProvider.GetService().Database.Migrate();; + serviceScope.ServiceProvider.GetService().Database.Migrate(); ConfigurationDbContext identityContext = serviceScope.ServiceProvider.GetService(); identityContext.Database.Migrate(); diff --git a/Kyoo/Views/API/SearchAPI.cs b/Kyoo/Views/API/SearchAPI.cs index 273dd6cd..ab0ab3dd 100644 --- a/Kyoo/Views/API/SearchAPI.cs +++ b/Kyoo/Views/API/SearchAPI.cs @@ -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), diff --git a/Kyoo/Views/WebClient b/Kyoo/Views/WebClient index 576e35fc..1a4d6404 160000 --- a/Kyoo/Views/WebClient +++ b/Kyoo/Views/WebClient @@ -1 +1 @@ -Subproject commit 576e35fcaba5ed1fc5dafd7e5f2f569c38649c0f +Subproject commit 1a4d6404b11a39380c006bf730ee654d9234989e