示例#1
0
        /// <summary>
        /// Gets the search hints async.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Task{IEnumerable{SearchHintResult}}.</returns>
        private async Task <SearchHintResult> GetSearchHintsAsync(GetSearchHints request)
        {
            var inputItems = GetAllLibraryItems(request.UserId, _userManager, _libraryManager);

            var results = await _searchEngine.GetSearchHints(inputItems, request.SearchTerm).ConfigureAwait(false);

            var searchResultArray = results.ToList();

            IEnumerable <SearchHintInfo> returnResults = searchResultArray;

            if (request.StartIndex.HasValue)
            {
                returnResults = returnResults.Skip(request.StartIndex.Value);
            }

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

            return(new SearchHintResult
            {
                TotalRecordCount = searchResultArray.Count,

                SearchHints = returnResults.Select(GetSearchHintResult).ToArray()
            });
        }
示例#2
0
        /// <summary>
        /// Gets the search hints async.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Task{IEnumerable{SearchHintResult}}.</returns>
        private async Task <SearchHintResult> GetSearchHintsAsync(GetSearchHints request)
        {
            IEnumerable <BaseItem> inputItems;

            if (request.UserId.HasValue)
            {
                var user = _userManager.GetUserById(request.UserId.Value);

                inputItems = user.RootFolder.GetRecursiveChildren(user);
            }
            else
            {
                inputItems = _libraryManager.RootFolder.RecursiveChildren;
            }

            var results = await _searchEngine.GetSearchHints(inputItems, request.SearchTerm).ConfigureAwait(false);

            var searchResultArray = results.ToArray();

            IEnumerable <SearchHintInfo> returnResults = searchResultArray;

            if (request.StartIndex.HasValue)
            {
                returnResults = returnResults.Skip(request.StartIndex.Value);
            }

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

            return(new SearchHintResult
            {
                TotalRecordCount = searchResultArray.Length,

                SearchHints = returnResults.Select(GetSearchHintResult).ToArray()
            });
        }