Ejemplo n.º 1
0
        /// <summary>
        /// Get the top package search suggestions for the data catalog group.
        /// </summary>
        /// <param name="prefix"></param>
        /// <param name="suggestionCount"></param>
        /// <param name="searchParameters"></param>
        /// <param name="cacheSettings"></param>
        /// <returns></returns>
        public List <string> GetPackageSearchSuggestions(string prefix, int suggestionCount, PackageSearchParameters searchParameters, CacheSettings cacheSettings)
        {
            var list = new List <string>();

            var trie = SuggestionHelper.GetTrie(this, searchParameters, cacheSettings);

            if (trie != null)
            {
                list = trie.GetCompletionList(prefix);
                list.Sort();
                list = list.Take(suggestionCount).ToList();
            }
            return(list);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Get the top 10 package search suggestions for the data catalog group.
 /// </summary>
 /// <param name="prefix"></param>
 /// <param name="searchParameters"></param>
 /// <param name="cacheSettings"></param>
 /// <returns></returns>
 public List <string> GetPackageSearchSuggestions(string prefix, PackageSearchParameters searchParameters, CacheSettings cacheSettings)
 {
     return(GetPackageSearchSuggestions(prefix, 10, searchParameters, cacheSettings));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Search for packages in the CKAN repository and just return tag counts with caching.
        /// </summary>
        /// <param name="parameters">Provides that parameters to use in the search.</param>
        /// <param name="settings">The cache settings.</param>
        /// <returns>Search results</returns>
        public List <Tag> SearchPackagesGetTagCounts(PackageSearchParameters parameters, CacheSettings settings)
        {
            // Execute the search request
            parameters.Offset = 0;
            parameters.Limit  = GetPackageCount(parameters, settings);

            PackageSearchResponse <Package> response = SearchPackages <Package>(parameters, settings);

            List <Package> packages = response.Results;

            List <Tag> tags = TagHelper.GetTagCounts(packages);

            return(tags);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Search for resources in the CKAN repository with caching.
        /// </summary>
        /// <param name="parameters">Provides that parameters to use in the search.</param>
        /// <param name="settings">The cache settings.</param>
        /// <returns>Search results</returns>
        public ResourceSearchResponse <T> SearchResources <T>(ResourceSearchParameters parameters, CacheSettings settings)
        {
            var request = new RestRequest();

            request.Resource = "2/search/resource";

            // Apply url parameter
            if (!String.IsNullOrEmpty(parameters.Url))
            {
                request.AddParameter("url", parameters.Url);
            }

            // Apply format parameter
            if (!String.IsNullOrEmpty(parameters.Format))
            {
                request.AddParameter("format", parameters.Format);
            }

            // Apply description parameter
            if (!String.IsNullOrEmpty(parameters.Description))
            {
                request.AddParameter("description", parameters.Description);
            }

            // Apply hash parameter
            if (!String.IsNullOrEmpty(parameters.Hash))
            {
                request.AddParameter("hash", parameters.Hash);
            }

            // Set the offset and limit parameters
            request.AddParameter("offset", parameters.Offset);
            request.AddParameter("limit", parameters.Limit);

            // Apply all_fields parameter
            if (typeof(T) == typeof(Resource))
            {
                request.AddParameter("all_fields", 1);
            }

            // Execute the request
            ResourceSearchResponse <T> response = Execute <ResourceSearchResponse <T> >(request, settings);

            // If no results, return an empty results object
            if (response == null)
            {
                response = new ResourceSearchResponse <T>();
            }

            return(response);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Search for packages in the CKAN repository with caching.
        /// </summary>
        /// <param name="parameters">Provides that parameters to use in the search.</param>
        /// <param name="settings">The cache settings.</param>
        /// <returns>Search results</returns>
        public PackageSearchResponse <T> SearchPackages <T>(PackageSearchParameters parameters, CacheSettings settings)
        {
            var request = new RestRequest();

            request.Resource = "2/search/package";

            // Apply query parameter
            foreach (var group in parameters.Groups)
            {
                request.AddParameter("q", "organization:" + group);
            }

            // Apply title parameter
            if (!String.IsNullOrEmpty(parameters.Title))
            {
                request.AddParameter("title", parameters.Title);
            }

            // Apply tag parameters
            foreach (var tag in parameters.Tags)
            {
                request.AddParameter("tags", tag);
            }

            // Apply notes parameter
            if (!String.IsNullOrEmpty(parameters.Notes))
            {
                request.AddParameter("notes", parameters.Notes);
            }

            //// Apply group parameters
            //foreach (var group in parameters.Groups)
            //{
            //    request.AddParameter("groups", group);
            //}

            // Apply author parameter
            if (!String.IsNullOrEmpty(parameters.Author))
            {
                request.AddParameter("author", parameters.Author);
            }

            // Apply update_frequency parameter
            if (!String.IsNullOrEmpty(parameters.UpdateFrequency))
            {
                request.AddParameter("update_frequency", parameters.UpdateFrequency);
            }

            // Apply maintainer parameter
            if (!String.IsNullOrEmpty(parameters.Maintainer))
            {
                request.AddParameter("maintainer", parameters.Maintainer);
            }

            // Apply all_fields parameter
            if (typeof(T) == typeof(Package))
            {
                request.AddParameter("all_fields", 1);
            }

            // Apply filter_by_openness parameter
            if (parameters.FilterByOpenness)
            {
                request.AddParameter("filter_by_openness", "1");
            }

            // Apply filter_by_downloadable parameter
            if (parameters.FilterByDownloadable)
            {
                request.AddParameter("filter_by_downloadable", "1");
            }

            // Apply order_by parameter
            if (!String.IsNullOrEmpty(parameters.OrderBy))
            {
                request.AddParameter("order_by", parameters.OrderBy);
            }

            // Set the offset and limit parameters
            if (parameters.Offset > -1)
            {
                request.AddParameter("offset", parameters.Offset);
            }

            if (parameters.Limit > -1)
            {
                request.AddParameter("limit", parameters.Limit);
            }

            // Execute the search request
            PackageSearchResponse <T> response = Execute <PackageSearchResponse <T> >(request, settings);

            // If no results, return an empty results object
            if (response == null)
            {
                response = new PackageSearchResponse <T>();
            }
            else
            {
                if (typeof(T) == typeof(Package) && parameters.AggregateTagCounts && response.Results.Count > 0)
                {
                    if (response.Results.Count == response.Count)
                    {
                        // If we have all of the results on the current page just aggregate the tags
                        if (typeof(T) == typeof(Package))
                        {
                            List <Package> packages = response.Results.ConvertAll(item => (Package)((object)item));
                            response.Tags = TagHelper.GetTagCounts(packages);
                        }
                    }
                    else
                    {
                        // If we don't have all of the results submit another request to
                        // get all of the tags
                        response.Tags = SearchPackagesGetTagCounts(parameters, settings);
                    }
                }
            }

            return(response);
        }