mirror of https://github.com/ErsatzTV/ErsatzTV.git
Browse Source
* fix some potential null reference exceptions * searching isn't actually async * add search query breadcrumbpull/1046/head
21 changed files with 160 additions and 66 deletions
@ -1,29 +1,33 @@ |
|||||||
using ErsatzTV.Core.Interfaces.Search; |
using Bugsnag; |
||||||
|
using ErsatzTV.Core.Interfaces.Search; |
||||||
using ErsatzTV.Infrastructure.Search; |
using ErsatzTV.Infrastructure.Search; |
||||||
|
|
||||||
namespace ErsatzTV.Application.Search; |
namespace ErsatzTV.Application.Search; |
||||||
|
|
||||||
public class |
public class QuerySearchIndexAllItemsHandler : IRequestHandler<QuerySearchIndexAllItems, SearchResultAllItemsViewModel> |
||||||
QuerySearchIndexAllItemsHandler : IRequestHandler<QuerySearchIndexAllItems, SearchResultAllItemsViewModel> |
|
||||||
{ |
{ |
||||||
|
private readonly IClient _client; |
||||||
private readonly ISearchIndex _searchIndex; |
private readonly ISearchIndex _searchIndex; |
||||||
|
|
||||||
public QuerySearchIndexAllItemsHandler(ISearchIndex searchIndex) => _searchIndex = searchIndex; |
public QuerySearchIndexAllItemsHandler(IClient client, ISearchIndex searchIndex) |
||||||
|
{ |
||||||
|
_client = client; |
||||||
|
_searchIndex = searchIndex; |
||||||
|
} |
||||||
|
|
||||||
public async Task<SearchResultAllItemsViewModel> Handle( |
public Task<SearchResultAllItemsViewModel> Handle( |
||||||
QuerySearchIndexAllItems request, |
QuerySearchIndexAllItems request, |
||||||
CancellationToken cancellationToken) => |
CancellationToken cancellationToken) => |
||||||
new( |
new SearchResultAllItemsViewModel( |
||||||
await GetIds(SearchIndex.MovieType, request.Query), |
GetIds(SearchIndex.MovieType, request.Query), |
||||||
await GetIds(SearchIndex.ShowType, request.Query), |
GetIds(SearchIndex.ShowType, request.Query), |
||||||
await GetIds(SearchIndex.SeasonType, request.Query), |
GetIds(SearchIndex.SeasonType, request.Query), |
||||||
await GetIds(SearchIndex.EpisodeType, request.Query), |
GetIds(SearchIndex.EpisodeType, request.Query), |
||||||
await GetIds(SearchIndex.ArtistType, request.Query), |
GetIds(SearchIndex.ArtistType, request.Query), |
||||||
await GetIds(SearchIndex.MusicVideoType, request.Query), |
GetIds(SearchIndex.MusicVideoType, request.Query), |
||||||
await GetIds(SearchIndex.OtherVideoType, request.Query), |
GetIds(SearchIndex.OtherVideoType, request.Query), |
||||||
await GetIds(SearchIndex.SongType, request.Query)); |
GetIds(SearchIndex.SongType, request.Query)).AsTask(); |
||||||
|
|
||||||
private Task<List<int>> GetIds(string type, string query) => |
private List<int> GetIds(string type, string query) => |
||||||
_searchIndex.Search($"type:{type} AND ({query})", 0, 0) |
_searchIndex.Search(_client, $"type:{type} AND ({query})", 0, 0).Items.Map(i => i.Id).ToList(); |
||||||
.Map(result => result.Items.Map(i => i.Id).ToList()); |
|
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue