mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.5 KiB
34 lines
1.5 KiB
using Bugsnag; |
|
using ErsatzTV.Core.Interfaces.Search; |
|
using ErsatzTV.Infrastructure.Search; |
|
|
|
namespace ErsatzTV.Application.Search; |
|
|
|
public class QuerySearchIndexAllItemsHandler : IRequestHandler<QuerySearchIndexAllItems, SearchResultAllItemsViewModel> |
|
{ |
|
private readonly IClient _client; |
|
private readonly ISearchIndex _searchIndex; |
|
|
|
public QuerySearchIndexAllItemsHandler(IClient client, ISearchIndex searchIndex) |
|
{ |
|
_client = client; |
|
_searchIndex = searchIndex; |
|
} |
|
|
|
public async Task<SearchResultAllItemsViewModel> Handle( |
|
QuerySearchIndexAllItems request, |
|
CancellationToken cancellationToken) => |
|
new( |
|
await GetIds(LuceneSearchIndex.MovieType, request.Query), |
|
await GetIds(LuceneSearchIndex.ShowType, request.Query), |
|
await GetIds(LuceneSearchIndex.SeasonType, request.Query), |
|
await GetIds(LuceneSearchIndex.EpisodeType, request.Query), |
|
await GetIds(LuceneSearchIndex.ArtistType, request.Query), |
|
await GetIds(LuceneSearchIndex.MusicVideoType, request.Query), |
|
await GetIds(LuceneSearchIndex.OtherVideoType, request.Query), |
|
await GetIds(LuceneSearchIndex.SongType, request.Query), |
|
await GetIds(LuceneSearchIndex.ImageType, request.Query)); |
|
|
|
private async Task<List<int>> GetIds(string type, string query) => |
|
(await _searchIndex.Search(_client, $"type:{type} AND ({query})", string.Empty, 0, 0)).Items.Map(i => i.Id).ToList(); |
|
}
|
|
|