public async Task <TelevisionEpisodeCardResultsViewModel> Handle(
        QuerySearchIndexEpisodes request,
        CancellationToken cancellationToken)
    {
        SearchResult searchResult = await _searchIndex.Search(
            request.Query,
            (request.PageNumber - 1) *request.PageSize,
            request.PageSize);

        Option <JellyfinMediaSource> maybeJellyfin = await _mediaSourceRepository.GetAllJellyfin()
                                                     .Map(list => list.HeadOrNone());

        Option <EmbyMediaSource> maybeEmby = await _mediaSourceRepository.GetAllEmby()
                                             .Map(list => list.HeadOrNone());

        List <EpisodeMetadata> episodes = await _televisionRepository
                                          .GetEpisodesForCards(searchResult.Items.Map(i => i.Id).ToList());

        var items = new List <TelevisionEpisodeCardViewModel>();

        foreach (EpisodeMetadata episodeMetadata in episodes)
        {
            string localPath = await episodeMetadata.Episode.GetLocalPath(
                _plexPathReplacementService,
                _jellyfinPathReplacementService,
                _embyPathReplacementService,
                false);

            items.Add(ProjectToViewModel(episodeMetadata, maybeJellyfin, maybeEmby, true, localPath));
        }

        return(new TelevisionEpisodeCardResultsViewModel(searchResult.TotalCount, items, searchResult.PageMap));
    }
    public async Task <MusicVideoCardResultsViewModel> Handle(
        QuerySearchIndexMusicVideos request,
        CancellationToken cancellationToken)
    {
        SearchResult searchResult = await _searchIndex.Search(
            request.Query,
            (request.PageNumber - 1) *request.PageSize,
            request.PageSize);

        List <MusicVideoMetadata> musicVideos = await _musicVideoRepository
                                                .GetMusicVideosForCards(searchResult.Items.Map(i => i.Id).ToList());

        var items = new List <MusicVideoCardViewModel>();

        foreach (MusicVideoMetadata musicVideoMetadata in musicVideos)
        {
            string localPath = await musicVideoMetadata.MusicVideo.GetLocalPath(
                _plexPathReplacementService,
                _jellyfinPathReplacementService,
                _embyPathReplacementService,
                false);

            items.Add(ProjectToViewModel(musicVideoMetadata, localPath));
        }

        return(new MusicVideoCardResultsViewModel(searchResult.TotalCount, items, searchResult.PageMap));
    }
        public async Task <IActionResult> Get(string terms, WorkflowStatus?status, string type, DateTime?createdFrom, DateTime?createdTo, int skip, int take = 10)
        {
            var filters = new List <SearchFilter>();

            if (status.HasValue)
            {
                filters.Add(StatusFilter.Equals(status.Value));
            }

            if (createdFrom.HasValue)
            {
                filters.Add(DateRangeFilter.After(x => x.CreateTime, createdFrom.Value));
            }

            if (createdTo.HasValue)
            {
                filters.Add(DateRangeFilter.Before(x => x.CreateTime, createdTo.Value));
            }

            if (!string.IsNullOrEmpty(type))
            {
                filters.Add(ScalarFilter.Equals(x => x.WorkflowDefinitionId, type));
            }

            var result = await _searchService.Search(terms, skip, take, filters.ToArray());

            return(Json(result));
        }
예제 #4
0
        public IEnumerable <string> Search(string searchString)
        {
            var queryParser = new QueryParser(ContentField, DefaultOperator.And);
            var query       = queryParser.Parse(searchString);
            var hits        = _searchIndex.Search(query);

            foreach (var hit in hits)
            {
                var filePath = _searchIndex.GetFieldValue(hit, NameField);
                if (!string.IsNullOrEmpty(filePath))
                {
                    yield return(filePath);
                }
            }
        }
예제 #5
0
    public async Task <SongCardResultsViewModel> Handle(
        QuerySearchIndexSongs request,
        CancellationToken cancellationToken)
    {
        SearchResult searchResult = await _searchIndex.Search(
            request.Query,
            (request.PageNumber - 1) *request.PageSize,
            request.PageSize);

        List <SongCardViewModel> items = await _songRepository
                                         .GetSongsForCards(searchResult.Items.Map(i => i.Id).ToList())
                                         .Map(list => list.Map(ProjectToViewModel).ToList());

        return(new SongCardResultsViewModel(searchResult.TotalCount, items, searchResult.PageMap));
    }
예제 #6
0
    public async Task <MovieCardResultsViewModel> Handle(
        QuerySearchIndexMovies request,
        CancellationToken cancellationToken)
    {
        SearchResult searchResult = await _searchIndex.Search(
            request.Query,
            (request.PageNumber - 1) *request.PageSize,
            request.PageSize);

        Option <JellyfinMediaSource> maybeJellyfin = await _mediaSourceRepository.GetAllJellyfin()
                                                     .Map(list => list.HeadOrNone());

        Option <EmbyMediaSource> maybeEmby = await _mediaSourceRepository.GetAllEmby()
                                             .Map(list => list.HeadOrNone());

        List <MovieCardViewModel> items = await _movieRepository
                                          .GetMoviesForCards(searchResult.Items.Map(i => i.Id).ToList())
                                          .Map(list => list.Map(m => ProjectToViewModel(m, maybeJellyfin, maybeEmby)).ToList());

        return(new MovieCardResultsViewModel(searchResult.TotalCount, items, searchResult.PageMap));
    }
예제 #7
0
    public async Task <Either <BaseError, Unit> > Handle(
        EmptyTrash request,
        CancellationToken cancellationToken)
    {
        string[] types =
        {
            SearchIndex.MovieType,
            SearchIndex.ShowType,
            SearchIndex.SeasonType,
            SearchIndex.EpisodeType,
            SearchIndex.MusicVideoType,
            SearchIndex.OtherVideoType,
            SearchIndex.SongType,
            SearchIndex.ArtistType
        };

        var ids = new List <int>();

        foreach (string type in types)
        {
            SearchResult result = await _searchIndex.Search($"type:{type} AND (state:FileNotFound)", 0, 0);

            ids.AddRange(result.Items.Map(i => i.Id));
        }

        Either <BaseError, Unit> deleteResult = await _mediaItemRepository.DeleteItems(ids);

        if (deleteResult.IsRight)
        {
            await _searchIndex.RemoveItems(ids);

            _searchIndex.Commit();
        }

        return(deleteResult);
    }
예제 #8
0
    public async Task <List <MediaItem> > GetSmartCollectionItems(int id)
    {
        await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();

        var result = new List <MediaItem>();

        Option <SmartCollection> maybeCollection = await dbContext.SmartCollections
                                                   .SelectOneAsync(sc => sc.Id, sc => sc.Id == id);

        foreach (SmartCollection collection in maybeCollection)
        {
            SearchResult searchResults = await _searchIndex.Search(collection.Query, 0, 0);

            var movieIds = searchResults.Items
                           .Filter(i => i.Type == SearchIndex.MovieType)
                           .Map(i => i.Id)
                           .ToList();
            result.AddRange(await GetMovieItems(dbContext, movieIds));

            foreach (int showId in searchResults.Items.Filter(i => i.Type == SearchIndex.ShowType).Map(i => i.Id))
            {
                result.AddRange(await GetShowItemsFromShowId(dbContext, showId));
            }

            foreach (int seasonId in searchResults.Items.Filter(i => i.Type == SearchIndex.SeasonType)
                     .Map(i => i.Id))
            {
                result.AddRange(await GetSeasonItemsFromSeasonId(dbContext, seasonId));
            }

            foreach (int artistId in searchResults.Items.Filter(i => i.Type == SearchIndex.ArtistType)
                     .Map(i => i.Id))
            {
                result.AddRange(await GetArtistItemsFromArtistId(dbContext, artistId));
            }

            var musicVideoIds = searchResults.Items
                                .Filter(i => i.Type == SearchIndex.MusicVideoType)
                                .Map(i => i.Id)
                                .ToList();
            result.AddRange(await GetMusicVideoItems(dbContext, musicVideoIds));

            var episodeIds = searchResults.Items
                             .Filter(i => i.Type == SearchIndex.EpisodeType)
                             .Map(i => i.Id)
                             .ToList();
            result.AddRange(await GetEpisodeItems(dbContext, episodeIds));

            var otherVideoIds = searchResults.Items
                                .Filter(i => i.Type == SearchIndex.OtherVideoType)
                                .Map(i => i.Id)
                                .ToList();
            result.AddRange(await GetOtherVideoItems(dbContext, otherVideoIds));

            var songIds = searchResults.Items
                          .Filter(i => i.Type == SearchIndex.SongType)
                          .Map(i => i.Id)
                          .ToList();
            result.AddRange(await GetSongItems(dbContext, songIds));
        }

        return(result);
    }