mirror of https://github.com/ErsatzTV/ErsatzTV.git
9 changed files with 93 additions and 44 deletions
@ -1,7 +0,0 @@ |
|||||||
using ErsatzTV.Core.Search; |
|
||||||
using MediatR; |
|
||||||
|
|
||||||
namespace ErsatzTV.Application.Search.Queries |
|
||||||
{ |
|
||||||
public record QuerySearchIndex(string Query) : IRequest<SearchResult>; |
|
||||||
} |
|
||||||
@ -0,0 +1,6 @@ |
|||||||
|
using MediatR; |
||||||
|
|
||||||
|
namespace ErsatzTV.Application.Search.Queries |
||||||
|
{ |
||||||
|
public record QuerySearchIndexAllItems(string Query) : IRequest<SearchResultAllItemsViewModel>; |
||||||
|
} |
||||||
@ -0,0 +1,32 @@ |
|||||||
|
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> 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, musicVideoIds); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -1,18 +0,0 @@ |
|||||||
using System.Threading; |
|
||||||
using System.Threading.Tasks; |
|
||||||
using ErsatzTV.Core.Interfaces.Search; |
|
||||||
using ErsatzTV.Core.Search; |
|
||||||
using MediatR; |
|
||||||
|
|
||||||
namespace ErsatzTV.Application.Search.Queries |
|
||||||
{ |
|
||||||
public class QuerySearchIndexHandler : IRequestHandler<QuerySearchIndex, SearchResult> |
|
||||||
{ |
|
||||||
private readonly ISearchIndex _searchIndex; |
|
||||||
|
|
||||||
public QuerySearchIndexHandler(ISearchIndex searchIndex) => _searchIndex = searchIndex; |
|
||||||
|
|
||||||
public Task<SearchResult> Handle(QuerySearchIndex request, CancellationToken cancellationToken) => |
|
||||||
_searchIndex.Search(request.Query, 0, 100); |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,6 @@ |
|||||||
|
using System.Collections.Generic; |
||||||
|
|
||||||
|
namespace ErsatzTV.Application.Search |
||||||
|
{ |
||||||
|
public record SearchResultAllItemsViewModel(List<int> MovieIds, List<int> ShowIds, List<int> MusicVideoIds); |
||||||
|
} |
||||||
Loading…
Reference in new issue