public PagedPackages Search(int pageIndex, int pageSize, 
            string category = null, 
            string query = null, 
            PackageSortOrder order = PackageSortOrder.Latest )
        {
            var packages = GetTestData()
                .Where(x => string.IsNullOrWhiteSpace(category) || x.Category == category)
                .Where(x => string.IsNullOrWhiteSpace(query) || x.Name.InvariantContains(query));

            //TODO: This will be interesting - not sure if we are using Examine for searching but if we are
            // and if the query is not empty, then we should order by score,
            // otherwise if there is no query we will order by the 'order' parameter
            Models.Package[] sorted;
            if (string.IsNullOrWhiteSpace(query))
            {
                //TODO: order by score if possible
                sorted = packages.OrderBy(x => x.Created).ToArray();
            }
            else if (order == PackageSortOrder.Latest)
            {
                sorted = packages.OrderBy(x => x.Created).ToArray();
            }
            else
            {
                //TODO: Also included downloads somehow?
                sorted = packages.OrderBy(x => x.Likes).ToArray();
            }

            return new PagedPackages
            {
                Packages = sorted.Skip(pageIndex * pageSize).Take(pageSize),
                Total = sorted.Length
            };
        }
Beispiel #2
0
        /// <summary>
        /// Returns a list of packages based on a search
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="category"></param>
        /// <param name="query"></param>
        /// <param name="version"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        /// <remarks>
        /// This caches each query for 2 minutes (non-sliding)
        /// </remarks>
        public PagedPackages GetPackages(
            int pageIndex,
            int pageSize,
            string category        = null,
            string query           = null,
            string version         = null,
            PackageSortOrder order = PackageSortOrder.Default)
        {
            var filters       = new List <SearchFilters>();
            var searchFilters = new SearchFilters(BooleanOperation.And);

            //MUST be live
            searchFilters.Filters.Add(new SearchFilter("projectLive", "1"));
            filters.Add(searchFilters);
            if (version.IsNullOrWhiteSpace() == false)
            {
                //need to clean up this string, it could be all sorts of things
                var parsedVersion = version.GetFromUmbracoString();
                if (parsedVersion != null)
                {
                    var numericalVersion = parsedVersion.GetNumericalValue();
                    var versionFilters   = new SearchFilters(BooleanOperation.Or);
                    versionFilters.Filters.Add(new RangeSearchFilter("num_version", 0, numericalVersion));
                    versionFilters.Filters.Add(new RangeSearchFilter("num_compatVersions", 0, numericalVersion));
                    filters.Add(versionFilters);
                }
            }

            query = string.IsNullOrWhiteSpace(query) ? string.Empty : query;

            var orderBy = string.Empty;

            switch (order)
            {
            case PackageSortOrder.Latest:
                orderBy = "createDate[Type=LONG]";
                break;

            case PackageSortOrder.Popular:
                orderBy = "popularity[Type=INT]";
                break;
            }

            //Return based on a query
            if (!string.IsNullOrWhiteSpace(category))
            {
                var catFilters = new SearchFilters(BooleanOperation.And);
                catFilters.Filters.Add(new SearchFilter("categoryFolder", string.Format("\"{0}\"", category)));
                filters.Add(catFilters);
            }

            var ourSearcher  = new OurSearcher(query, nodeTypeAlias: "project", maxResults: pageSize * (pageIndex + 1), orderBy: orderBy, filters: filters);
            var searchResult = ourSearcher.Search("projectSearcher", skip: pageIndex * pageSize);

            return(FromSearchResults(searchResult, pageIndex, pageSize));
        }
        public PagedPackages Search(
            int pageIndex,
            int pageSize,
            string category        = null,
            string query           = null,
            string version         = null,
            PackageSortOrder order = PackageSortOrder.Latest)
        {
            //return the results, but cache for 1 minute
            var key = string.Format("PackageRepositoryController.GetCategories.{0}.{1}.{2}.{3}.{4}", pageIndex, pageSize, category ?? string.Empty, query ?? string.Empty, order);

            return(ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem <PagedPackages>
                       (key,
                       () => Service.GetPackages(pageIndex, pageSize, category, query, version, order),
                       TimeSpan.FromMinutes(1))); //cache for 1 min
        }
Beispiel #4
0
        /// <summary>
        /// Returns a list of packages based on a search
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="category"></param>
        /// <param name="query"></param>
        /// <param name="version"></param>
        /// <param name="order"></param>
        /// <param name="includeHidden">Some packages are hidden (i.e. projectLive), set to true to ignore this switch (i.e. for starter kits)</param>
        /// <returns></returns>
        /// <remarks>
        /// This caches each query for 2 minutes (non-sliding)
        /// </remarks>
        public PagedPackages GetPackages(
            int pageIndex,
            int pageSize,
            string category        = null,
            string query           = null,
            string version         = null,
            PackageSortOrder order = PackageSortOrder.Default,
            bool?includeHidden     = false)
        {
            var filters       = new List <SearchFilters>();
            var searchFilters = new SearchFilters(BooleanOperation.And);

            if (includeHidden == false)
            {
                //MUST be live
                searchFilters.Filters.Add(new SearchFilter("projectLive", "1"));
                searchFilters.Filters.Add(new SearchFilter("isRetired", "0"));
            }

            if (version.IsNullOrWhiteSpace() == false)
            {
                //need to clean up this string, it could be all sorts of things
                var parsedVersion = version.GetFromUmbracoString(reduceToConfigured: false);
                if (parsedVersion != null)
                {
                    // As of version 9, there will no longer be package files - those are on NuGet.org only so don't check file compatibility
                    if (parsedVersion.Major >= 9)
                    {
                        searchFilters.Filters.Add(new SearchFilter("isNuGetFormat", "1"));
                    }
                    else
                    {
                        var numericalVersion = parsedVersion.GetNumericalValue();
                        var versionFilters   = new SearchFilters(BooleanOperation.Or);

                        //search for all versions from the current major to the version passed in
                        var currMajor = new System.Version(parsedVersion.Major, 0, 0).GetNumericalValue();

                        versionFilters.Filters.Add(
                            new RangeSearchFilter("num_version", currMajor, numericalVersion));
                        filters.Add(versionFilters);
                    }
                }
            }

            filters.Add(searchFilters);

            query = string.IsNullOrWhiteSpace(query) ? string.Empty : query;

            var orderBy = string.Empty;

            switch (order)
            {
            case PackageSortOrder.Latest:
                orderBy = "createDate[Type=LONG]";
                break;

            case PackageSortOrder.Popular:
                orderBy = "popularity[Type=INT]";
                break;

            case PackageSortOrder.Default:
                orderBy = "updateDate[Type=LONG]";
                break;

            case PackageSortOrder.Downloads:
                orderBy = "downloads[Type=INT]";
                break;
            }

            //Return based on a query
            if (!string.IsNullOrWhiteSpace(category))
            {
                var catFilters = new SearchFilters(BooleanOperation.And);
                if (category.InvariantEquals("uaas"))
                {
                    catFilters.Filters.Add(new SearchFilter("worksOnUaaS", string.Format("\"{0}\"", "True")));
                }
                else
                {
                    catFilters.Filters.Add(new SearchFilter("categoryFolder", string.Format("\"{0}\"", category)));
                }
                filters.Add(catFilters);
            }

            var ourSearcher  = new OurSearcher(query, nodeTypeAlias: "project", maxResults: pageSize * (pageIndex + 1), orderBy: orderBy, filters: filters);
            var searchResult = ourSearcher.Search("projectSearcher", skip: pageIndex * pageSize);

            return(FromSearchResults(searchResult, pageIndex, pageSize));
        }
 public PagedPackages Search(
     int pageIndex,
     int pageSize,
     string category = null,
     string query = null,
     PackageSortOrder order = PackageSortOrder.Latest)
 {
     return Service.GetPackages(pageIndex, pageSize, category, query, order);
 }
 public PagedPackages Search(
     int pageIndex,
     int pageSize,
     string category = null,
     string query = null,
     string version = null,
     PackageSortOrder order = PackageSortOrder.Latest)
 {
     //return the results, but cache for 1 minute
     var key = string.Format("PackageRepositoryController.GetCategories.{0}.{1}.{2}.{3}.{4}", pageIndex, pageSize, category ?? string.Empty, query ?? string.Empty, order);
     return ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem<PagedPackages>
         (key,
             () => Service.GetPackages(pageIndex, pageSize, category, query, version, order),
             TimeSpan.FromMinutes(1)); //cache for 1 min
 }