* add letter bar with no links * use lucene for search, add paged search results * add search index version * index library_name; rebuild index when folder is missing * maintain index as local movies change * fix tests * maintain index as local shows change * maintain index as plex movies change * maintain index as plex shows change * code cleanup * add duplicate filter to search * add links to letter bar * code cleanup
44 lines
1.6 KiB
C#
44 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using ErsatzTV.Application.MediaCards;
|
|
using ErsatzTV.Core.Interfaces.Repositories;
|
|
using ErsatzTV.Core.Interfaces.Search;
|
|
using ErsatzTV.Core.Search;
|
|
using LanguageExt;
|
|
using MediatR;
|
|
using static ErsatzTV.Application.MediaCards.Mapper;
|
|
|
|
namespace ErsatzTV.Application.Search.Queries
|
|
{
|
|
public class
|
|
QuerySearchIndexShowsHandler : IRequestHandler<QuerySearchIndexShows, TelevisionShowCardResultsViewModel>
|
|
{
|
|
private readonly ISearchIndex _searchIndex;
|
|
private readonly ITelevisionRepository _televisionRepository;
|
|
|
|
public QuerySearchIndexShowsHandler(ISearchIndex searchIndex, ITelevisionRepository televisionRepository)
|
|
{
|
|
_searchIndex = searchIndex;
|
|
_televisionRepository = televisionRepository;
|
|
}
|
|
|
|
public async Task<TelevisionShowCardResultsViewModel> Handle(
|
|
QuerySearchIndexShows request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
SearchResult searchResult = await _searchIndex.Search(
|
|
request.Query,
|
|
(request.PageNumber - 1) * request.PageSize,
|
|
request.PageSize);
|
|
|
|
List<TelevisionShowCardViewModel> items = await _televisionRepository
|
|
.GetShowsForCards(searchResult.Items.Map(i => i.Id).ToList())
|
|
.Map(list => list.Map(ProjectToViewModel).ToList());
|
|
|
|
return new TelevisionShowCardResultsViewModel(searchResult.TotalCount, items, searchResult.PageMap);
|
|
}
|
|
}
|
|
}
|