public void Transform(NuGetSearchTerm searchTerm)
 {
     if (!string.IsNullOrEmpty(tags))
     {
         searchTerm.Tags.Add(tags);
     }
 }
        /// <summary>
        /// Tries to apply special conditions for looking in local folder feed.
        /// </summary>
        /// <returns><c>true</c> if search reached the end of the feed; <c>false</c> otherwise.</returns>
        private Task <bool> ApplyLocalResourceSearchAsync(List <IPackage> result, SourceRepository repository, PackageSearchResource search, NuGetSearchTerm feedTerm, NuGetSearchTerm localTerm, SearchOptions options, CancellationToken cancellationToken)
        {
            if (search is LocalPackageSearchResource)
            {
                // Searching a feed from folder. Look for all packages and then filter in-app.
                if (localTerm == null)
                {
                    localTerm = feedTerm;
                }

                feedTerm = new NuGetSearchTerm();
            }

            return(ApplySearchAsync(result, repository, search, feedTerm, localTerm, options, cancellationToken));
        }
        /// <summary>
        /// Prepares instance of terms for filtering in feed and in-app.
        /// </summary>
        /// <remarks>
        /// localTerm should always have all search terms.
        /// </remarks>
        private (NuGetSearchTerm feedTerm, NuGetSearchTerm localTerm) PrepareSearchTerms(string searchText)
        {
            NuGetSearchTerm feedTerm = new NuGetSearchTerm();

            feedTerm.Id.Add(searchText);

            queryTransformer.Transform(feedTerm);
            feedTerm.Id.Remove(searchText);

            NuGetSearchTerm localTerm = null;

            if (feedTerm.IsEmpty())
            {
                feedTerm.Id.Add(searchText);
            }
            else
            {
                localTerm = feedTerm.Clone();
                localTerm.Id.Add(searchText);
            }

            return(feedTerm, localTerm);
        }
        /// <summary>
        /// Execute search on <paramref name="search"/>.
        /// </summary>
        /// <returns><c>true</c> if search reached the end of the feed; <c>false</c> otherwise.</returns>
        private async Task <bool> ApplySearchAsync(List <IPackage> result, SourceRepository repository, PackageSearchResource search, NuGetSearchTerm feedTerm, NuGetSearchTerm localTerm, SearchOptions options, CancellationToken cancellationToken)
        {
            if (localTerm != null && options.PageSize == 1)
            {
                options.PageSize = 10;
            }

            int sourceSearchPackageCount = 0;

            foreach (IPackageSearchMetadata package in await SearchAsync(search, feedTerm.ToString(), options, cancellationToken))
            {
                sourceSearchPackageCount++;

                log.Debug($"Found '{package.Identity}'.");

                if (result.Count >= options.PageSize)
                {
                    break;
                }

                if (localTerm != null && !localTerm.IsMatched(package))
                {
                    log.Debug($"Package skipped by late search term '{localTerm}'.");
                    continue;
                }

                await AddPackageAsync(result, repository, package, options.IsPrereleaseIncluded, cancellationToken);
            }

            // If package source reached end, skip it from next probing.
            if (sourceSearchPackageCount < options.PageSize)
            {
                return(false);
            }

            return(true);
        }
Exemple #5
0
 public void Transform(NuGetSearchTerm searchTerm)
 {
 }