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 System.Collections.Generic; |
|
using System.Linq; |
|
using System.Threading; |
|
using System.Threading.Tasks; |
|
using ErsatzTV.Core.Interfaces.Search; |
|
using LanguageExt; |
|
using MediatR; |
|
|
|
namespace ErsatzTV.Application.Search.Queries |
|
{ |
|
public class |
|
QuerySearchIndexAllItemsHandler : IRequestHandler<QuerySearchIndexAllItems, SearchResultAllItemsViewModel> |
|
{ |
|
private readonly ISearchIndex _searchIndex; |
|
|
|
public QuerySearchIndexAllItemsHandler(ISearchIndex searchIndex) => _searchIndex = searchIndex; |
|
|
|
public async Task<SearchResultAllItemsViewModel> Handle( |
|
QuerySearchIndexAllItems request, |
|
CancellationToken cancellationToken) |
|
{ |
|
List<int> movieIds = await _searchIndex.Search($"type:movie AND ({request.Query})", 0, 0) |
|
.Map(result => result.Items.Map(i => i.Id).ToList()); |
|
List<int> showIds = await _searchIndex.Search($"type:show AND ({request.Query})", 0, 0) |
|
.Map(result => result.Items.Map(i => i.Id).ToList()); |
|
List<int> artistIds = await _searchIndex.Search($"type:artist AND ({request.Query})", 0, 0) |
|
.Map(result => result.Items.Map(i => i.Id).ToList()); |
|
List<int> musicVideoIds = await _searchIndex.Search($"type:music_video AND ({request.Query})", 0, 0) |
|
.Map(result => result.Items.Map(i => i.Id).ToList()); |
|
|
|
return new SearchResultAllItemsViewModel(movieIds, showIds, artistIds, musicVideoIds); |
|
} |
|
} |
|
}
|
|
|