mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 12:14:46 -04:00
Reworking the search API
This commit is contained in:
parent
2fe5d376d9
commit
8df8cd4b20
@ -1,5 +1,4 @@
|
|||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Kyoo.Models.Watch;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Kyoo.Controllers
|
namespace Kyoo.Controllers
|
||||||
@ -25,7 +24,8 @@ namespace Kyoo.Controllers
|
|||||||
|
|
||||||
//Public read
|
//Public read
|
||||||
IEnumerable<Show> GetShows();
|
IEnumerable<Show> GetShows();
|
||||||
IEnumerable<Show> GetShows(string searchQuery);
|
IEnumerable<Show> SearchShows(string searchQuery);
|
||||||
|
IEnumerable<Collection> SearchCollections(string searchQuery);
|
||||||
Library GetLibrary(string librarySlug);
|
Library GetLibrary(string librarySlug);
|
||||||
IEnumerable<Library> GetLibraries();
|
IEnumerable<Library> GetLibraries();
|
||||||
Show GetShowBySlug(string slug);
|
Show GetShowBySlug(string slug);
|
||||||
|
@ -81,6 +81,13 @@ namespace Kyoo.Models
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Episode LoadShowDetails()
|
||||||
|
{
|
||||||
|
SetLink(Show.Slug);
|
||||||
|
ShowTitle = Show.Title;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Episode Merge(Episode other)
|
public Episode Merge(Episode other)
|
||||||
{
|
{
|
||||||
if (other == null)
|
if (other == null)
|
||||||
|
@ -5,6 +5,7 @@ namespace Kyoo.Models
|
|||||||
public class SearchResult
|
public class SearchResult
|
||||||
{
|
{
|
||||||
public string Query;
|
public string Query;
|
||||||
|
public IEnumerable<Collection> Collections;
|
||||||
public IEnumerable<Show> Shows;
|
public IEnumerable<Show> Shows;
|
||||||
public IEnumerable<Episode> Episodes;
|
public IEnumerable<Episode> Episodes;
|
||||||
public IEnumerable<People> People;
|
public IEnumerable<People> People;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using Kyoo.Models;
|
||||||
using Kyoo.Models;
|
|
||||||
using Kyoo.Models.Watch;
|
using Kyoo.Models.Watch;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -70,14 +69,10 @@ namespace Kyoo.Controllers
|
|||||||
.OrderBy(x => x.Title);
|
.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()
|
return _database.Shows.FromSqlInterpolated($"SELECT * FROM Shows WHERE Shows.Title LIKE {"%" + searchQuery + "%"} OR Shows.Aliases LIKE {"%" + searchQuery + "%"}")
|
||||||
where l.CollectionID == null select show).AsEnumerable().Union(
|
.OrderBy(x => x.Title).Take(20);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Show GetShowBySlug(string slug)
|
public Show GetShowBySlug(string slug)
|
||||||
@ -223,7 +218,7 @@ namespace Kyoo.Controllers
|
|||||||
|
|
||||||
public Collection GetCollection(string slug)
|
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)
|
if (collection != null)
|
||||||
collection.Shows = GetShowsInCollection(collection.ID);
|
collection.Shows = GetShowsInCollection(collection.ID);
|
||||||
return collection;
|
return collection;
|
||||||
@ -254,10 +249,17 @@ namespace Kyoo.Controllers
|
|||||||
|
|
||||||
public IEnumerable<Episode> SearchEpisodes(string searchQuery)
|
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);
|
.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)
|
public IEnumerable<People> SearchPeople(string searchQuery)
|
||||||
{
|
{
|
||||||
return (from people in _database.Peoples where EF.Functions.Like(people.Name, $"%{searchQuery}%") select people)
|
return (from people in _database.Peoples where EF.Functions.Like(people.Name, $"%{searchQuery}%") select people)
|
||||||
|
@ -24,7 +24,7 @@ namespace Kyoo.Controllers
|
|||||||
{
|
{
|
||||||
using (IServiceScope serviceScope = _serviceProvider.CreateScope())
|
using (IServiceScope serviceScope = _serviceProvider.CreateScope())
|
||||||
{
|
{
|
||||||
serviceScope.ServiceProvider.GetService<DatabaseContext>().Database.Migrate();;
|
serviceScope.ServiceProvider.GetService<DatabaseContext>().Database.Migrate();
|
||||||
|
|
||||||
ConfigurationDbContext identityContext = serviceScope.ServiceProvider.GetService<ConfigurationDbContext>();
|
ConfigurationDbContext identityContext = serviceScope.ServiceProvider.GetService<ConfigurationDbContext>();
|
||||||
identityContext.Database.Migrate();
|
identityContext.Database.Migrate();
|
||||||
|
@ -23,7 +23,8 @@ namespace Kyoo.Api
|
|||||||
SearchResult result = new SearchResult
|
SearchResult result = new SearchResult
|
||||||
{
|
{
|
||||||
Query = query,
|
Query = query,
|
||||||
Shows = _libraryManager.GetShows(query),
|
Collections = _libraryManager.SearchCollections(query),
|
||||||
|
Shows = _libraryManager.SearchShows(query),
|
||||||
Episodes = _libraryManager.SearchEpisodes(query),
|
Episodes = _libraryManager.SearchEpisodes(query),
|
||||||
People = _libraryManager.SearchPeople(query),
|
People = _libraryManager.SearchPeople(query),
|
||||||
Genres = _libraryManager.SearchGenres(query),
|
Genres = _libraryManager.SearchGenres(query),
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 576e35fcaba5ed1fc5dafd7e5f2f569c38649c0f
|
Subproject commit 1a4d6404b11a39380c006bf730ee654d9234989e
|
Loading…
x
Reference in New Issue
Block a user