Esempio n. 1
0
        private async Task <QueryResult <BaseItemDto> > GetSimilarItemsResult(BaseGetSimilarItemsFromItem request)
        {
            var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;

            var item = string.IsNullOrEmpty(request.Id) ?
                       (!string.IsNullOrWhiteSpace(request.UserId) ? user.RootFolder :
                        _libraryManager.RootFolder) : _libraryManager.GetItemById(request.Id);

            var dtoOptions = GetDtoOptions(_authContext, request);

            var itemsResult = _libraryManager.GetItemList(new InternalItemsQuery(user)
            {
                Limit            = request.Limit,
                IncludeItemTypes = new[]
                {
                    typeof(Series).Name
                },
                SimilarTo  = item,
                DtoOptions = dtoOptions
            }).ToList();

            var result = new QueryResult <BaseItemDto>
            {
                Items = (await _dtoService.GetBaseItemDtos(itemsResult, dtoOptions, user).ConfigureAwait(false)).ToArray(),

                TotalRecordCount = itemsResult.Count
            };

            return(result);
        }
Esempio n. 2
0
        private QueryResult <BaseItemDto> GetSimilarItemsResult(BaseGetSimilarItemsFromItem request)
        {
            var user = !request.UserId.Equals(Guid.Empty) ? _userManager.GetUserById(request.UserId) : null;

            var item = string.IsNullOrEmpty(request.Id) ?
                       (!request.UserId.Equals(Guid.Empty) ? _libraryManager.GetUserRootFolder() :
                        _libraryManager.RootFolder) : _libraryManager.GetItemById(request.Id);

            var dtoOptions = GetDtoOptions(_authContext, request);

            var itemsResult = _libraryManager.GetItemList(new InternalItemsQuery(user)
            {
                Limit            = request.Limit,
                IncludeItemTypes = new[]
                {
                    typeof(Game).Name
                },
                SimilarTo  = item,
                DtoOptions = dtoOptions
            });

            var returnList = _dtoService.GetBaseItemDtos(itemsResult, dtoOptions, user);

            var result = new QueryResult <BaseItemDto>
            {
                Items = returnList,

                TotalRecordCount = itemsResult.Count
            };

            return(result);
        }
Esempio n. 3
0
        internal static QueryResult <BaseItemDto> GetSimilarItemsResult(DtoOptions dtoOptions, IUserManager userManager, IItemRepository itemRepository, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, BaseGetSimilarItemsFromItem request, Type[] includeTypes, Func <BaseItem, List <PersonInfo>, List <PersonInfo>, BaseItem, int> getSimilarityScore)
        {
            var user = !request.UserId.Equals(Guid.Empty) ? userManager.GetUserById(request.UserId) : null;

            var item = string.IsNullOrEmpty(request.Id) ?
                       (!request.UserId.Equals(Guid.Empty) ? libraryManager.GetUserRootFolder() :
                        libraryManager.RootFolder) : libraryManager.GetItemById(request.Id);

            var query = new InternalItemsQuery(user)
            {
                IncludeItemTypes = includeTypes.Select(i => i.Name).ToArray(),
                Recursive        = true,
                DtoOptions       = dtoOptions
            };

            // ExcludeArtistIds
            if (!string.IsNullOrEmpty(request.ExcludeArtistIds))
            {
                query.ExcludeArtistIds = BaseApiService.GetGuids(request.ExcludeArtistIds);
            }

            var inputItems = libraryManager.GetItemList(query);

            var items = GetSimilaritems(item, libraryManager, inputItems, getSimilarityScore)
                        .ToList();

            var returnItems = items;

            if (request.Limit.HasValue)
            {
                returnItems = returnItems.Take(request.Limit.Value).ToList();
            }

            var dtos = dtoService.GetBaseItemDtos(returnItems, dtoOptions, user);

            return(new QueryResult <BaseItemDto>
            {
                Items = dtos,

                TotalRecordCount = items.Count
            });
        }
Esempio n. 4
0
        internal static async Task <QueryResult <BaseItemDto> > GetSimilarItemsResult(DtoOptions dtoOptions, IUserManager userManager, IItemRepository itemRepository, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, ILogger logger, BaseGetSimilarItemsFromItem request, Type[] includeTypes, Func <BaseItem, List <PersonInfo>, List <PersonInfo>, BaseItem, int> getSimilarityScore)
        {
            var user = !string.IsNullOrWhiteSpace(request.UserId) ? userManager.GetUserById(request.UserId) : null;

            var item = string.IsNullOrEmpty(request.Id) ?
                       (!string.IsNullOrWhiteSpace(request.UserId) ? user.RootFolder :
                        libraryManager.RootFolder) : libraryManager.GetItemById(request.Id);

            var query = new InternalItemsQuery(user)
            {
                IncludeItemTypes = includeTypes.Select(i => i.Name).ToArray(),
                Recursive        = true
            };

            var inputItems = libraryManager.GetItemList(query);

            var items = GetSimilaritems(item, libraryManager, inputItems, getSimilarityScore)
                        .ToList();

            IEnumerable <BaseItem> returnItems = items;

            if (request.Limit.HasValue)
            {
                returnItems = returnItems.Take(request.Limit.Value);
            }

            var dtos = await dtoService.GetBaseItemDtos(returnItems, dtoOptions, user).ConfigureAwait(false);

            return(new QueryResult <BaseItemDto>
            {
                Items = dtos.ToArray(),

                TotalRecordCount = items.Count
            });
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the similar items.
        /// </summary>
        /// <param name="userManager">The user manager.</param>
        /// <param name="itemRepository">The item repository.</param>
        /// <param name="libraryManager">The library manager.</param>
        /// <param name="userDataRepository">The user data repository.</param>
        /// <param name="dtoService">The dto service.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="request">The request.</param>
        /// <param name="includeInSearch">The include in search.</param>
        /// <param name="getSimilarityScore">The get similarity score.</param>
        /// <returns>ItemsResult.</returns>
        internal static ItemsResult GetSimilarItemsResult(IUserManager userManager, IItemRepository itemRepository, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, ILogger logger, BaseGetSimilarItemsFromItem request, Func <BaseItem, bool> includeInSearch, Func <BaseItem, BaseItem, int> getSimilarityScore)
        {
            var user = request.UserId.HasValue ? userManager.GetUserById(request.UserId.Value) : null;

            var item = string.IsNullOrEmpty(request.Id) ?
                       (request.UserId.HasValue ? user.RootFolder :
                        (Folder)libraryManager.RootFolder) : dtoService.GetItemByDtoId(request.Id, request.UserId);

            var fields = request.GetItemFields().ToList();

            var inputItems = user == null
                                 ? libraryManager.RootFolder.GetRecursiveChildren(i => i.Id != item.Id)
                                 : user.RootFolder.GetRecursiveChildren(user, i => i.Id != item.Id);

            var items = GetSimilaritems(item, inputItems, includeInSearch, getSimilarityScore)
                        .ToList();

            IEnumerable <BaseItem> returnItems = items;

            if (request.Limit.HasValue)
            {
                returnItems = returnItems.Take(request.Limit.Value);
            }

            var result = new ItemsResult
            {
                Items = returnItems.Select(i => dtoService.GetBaseItemDto(i, fields, user)).ToArray(),

                TotalRecordCount = items.Count
            };

            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the similar items.
        /// </summary>
        /// <param name="dtoOptions">The dto options.</param>
        /// <param name="userManager">The user manager.</param>
        /// <param name="itemRepository">The item repository.</param>
        /// <param name="libraryManager">The library manager.</param>
        /// <param name="userDataRepository">The user data repository.</param>
        /// <param name="dtoService">The dto service.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="request">The request.</param>
        /// <param name="includeInSearch">The include in search.</param>
        /// <param name="getSimilarityScore">The get similarity score.</param>
        /// <returns>ItemsResult.</returns>
        internal static ItemsResult GetSimilarItemsResult(DtoOptions dtoOptions, IUserManager userManager, IItemRepository itemRepository, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, ILogger logger, BaseGetSimilarItemsFromItem request, Func <BaseItem, bool> includeInSearch, Func <BaseItem, List <PersonInfo>, List <PersonInfo>, BaseItem, int> getSimilarityScore)
        {
            var user = !string.IsNullOrWhiteSpace(request.UserId) ? userManager.GetUserById(request.UserId) : null;

            var item = string.IsNullOrEmpty(request.Id) ?
                       (!string.IsNullOrWhiteSpace(request.UserId) ? user.RootFolder :
                        libraryManager.RootFolder) : libraryManager.GetItemById(request.Id);

            Func <BaseItem, bool> filter = i => i.Id != item.Id && includeInSearch(i);

            var inputItems = user == null
                                 ? libraryManager.RootFolder.GetRecursiveChildren(filter)
                                 : user.RootFolder.GetRecursiveChildren(user, filter);

            var items = GetSimilaritems(item, libraryManager, inputItems, getSimilarityScore)
                        .ToList();

            IEnumerable <BaseItem> returnItems = items;

            if (request.Limit.HasValue)
            {
                returnItems = returnItems.Take(request.Limit.Value);
            }

            var result = new ItemsResult
            {
                Items = dtoService.GetBaseItemDtos(returnItems, dtoOptions, user).ToArray(),

                TotalRecordCount = items.Count
            };

            return(result);
        }
        /// <summary>
        /// Gets the similar items.
        /// </summary>
        /// <param name="userManager">The user manager.</param>
        /// <param name="itemRepository">The item repository.</param>
        /// <param name="libraryManager">The library manager.</param>
        /// <param name="userDataRepository">The user data repository.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="request">The request.</param>
        /// <param name="includeInSearch">The include in search.</param>
        /// <param name="getSimilarityScore">The get similarity score.</param>
        /// <returns>ItemsResult.</returns>
        internal static ItemsResult GetSimilarItemsResult(IUserManager userManager, IItemRepository itemRepository, ILibraryManager libraryManager, IUserDataRepository userDataRepository, ILogger logger, BaseGetSimilarItemsFromItem request, Func <BaseItem, bool> includeInSearch, Func <BaseItem, BaseItem, int> getSimilarityScore)
        {
            var user = request.UserId.HasValue ? userManager.GetUserById(request.UserId.Value) : null;

            var item = string.IsNullOrEmpty(request.Id) ?
                       (request.UserId.HasValue ? user.RootFolder :
                        (Folder)libraryManager.RootFolder) : DtoBuilder.GetItemByClientId(request.Id, userManager, libraryManager, request.UserId);

            var fields = request.GetItemFields().ToList();

            var dtoBuilder = new DtoBuilder(logger, libraryManager, userDataRepository, itemRepository);

            var inputItems = user == null
                                 ? libraryManager.RootFolder.RecursiveChildren
                                 : user.RootFolder.GetRecursiveChildren(user);

            var items = GetSimilaritems(item, inputItems, includeInSearch, getSimilarityScore)
                        .ToArray();

            var result = new ItemsResult
            {
                Items = items.Take(request.Limit ?? items.Length).Select(i => dtoBuilder.GetBaseItemDto(i, fields, user)).Select(t => t.Result).ToArray(),

                TotalRecordCount = items.Length
            };

            return(result);
        }