public dynamic Search(
            string query = "",
            bool includePrerelease = false,
            bool latestOnly = true,
            int offset = 0,
            int count = 20,
            PackageOriginFilter originFilter = PackageOriginFilter.Any,
            SearchSortField sort = SearchSortField.Score,
            SearchSortDirection order = SearchSortDirection.Ascending)
        {
            var criteria = new SearchCriteria(query)
            {
                AllowPrereleaseVersions = includePrerelease,
                PackageOriginFilter = originFilter,
                SortField = sort,
                SortDirection = order
            };

            LuceneQueryStatistics stats = null;
            List<IPackage> hits;

            try
            {
                var queryable = LuceneRepository.Search(criteria).CaptureStatistics(s => stats = s);

                if (latestOnly)
                {
                    queryable = queryable.LatestOnly(includePrerelease);
                }

                hits = queryable.Skip(offset).Take(count).ToList();
            }
            catch (InvalidSearchCriteriaException ex)
            {
                var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, message);
            }

            dynamic result = new ExpandoObject();

            // criteria
            result.Query = query;
            result.IncludePrerelease = includePrerelease;
            result.TotalHits = stats.TotalHits;
            result.OriginFilter = originFilter;
            result.Sort = sort;
            result.Order = order;

            // statistics
            result.Offset = stats.SkippedHits;
            result.Count = stats.RetrievedDocuments;
            result.ElapsedPreparationTime = stats.ElapsedPreparationTime;
            result.ElapsedSearchTime = stats.ElapsedSearchTime;
            result.ElapsedRetrievalTime = stats.ElapsedRetrievalTime;

            var chars = stats.Query.ToString().Normalize(NormalizationForm.FormD);
            result.ComputedQuery = new string(chars.Where(c => c < 0x7f && !char.IsControl(c)).ToArray());

            // hits
            result.Hits = hits;
            return result;
        }
        public dynamic Search(
            string query           = "",
            bool includePrerelease = false,
            bool latestOnly        = true,
            int offset             = 0,
            int count = 20,
            PackageOriginFilter originFilter = PackageOriginFilter.Any,
            SearchSortField sort             = SearchSortField.Score,
            SearchSortDirection order        = SearchSortDirection.Ascending)
        {
            var criteria = new SearchCriteria(query)
            {
                AllowPrereleaseVersions = includePrerelease,
                PackageOriginFilter     = originFilter,
                SortField     = sort,
                SortDirection = order
            };

            LuceneQueryStatistics stats = null;
            List <IPackage>       hits;

            try
            {
                var queryable = LuceneRepository.Search(criteria).CaptureStatistics(s => stats = s);

                if (latestOnly)
                {
                    queryable = queryable.LatestOnly(includePrerelease);
                }

                hits = queryable.Skip(offset).Take(count).ToList();
            }
            catch (InvalidSearchCriteriaException ex)
            {
                var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, message));
            }

            dynamic result = new ExpandoObject();

            // criteria
            result.Query             = query;
            result.IncludePrerelease = includePrerelease;
            result.TotalHits         = stats.TotalHits;
            result.OriginFilter      = originFilter;
            result.Sort  = sort;
            result.Order = order;

            // statistics
            result.Offset = stats.SkippedHits;
            result.Count  = stats.RetrievedDocuments;
            result.ElapsedPreparationTime = stats.ElapsedPreparationTime;
            result.ElapsedSearchTime      = stats.ElapsedSearchTime;
            result.ElapsedRetrievalTime   = stats.ElapsedRetrievalTime;

            var chars = stats.Query.ToString().Normalize(NormalizationForm.FormD);

            result.ComputedQuery = new string(chars.Where(c => c < 0x7f && !char.IsControl(c)).ToArray());

            // hits
            result.Hits = hits;
            return(result);
        }
Esempio n. 3
0
        public dynamic Search(string query = "", bool includePrerelease = false, int offset = 0, int count = 20, PackageOriginFilter originFilter = PackageOriginFilter.Any, SearchSortField sort = SearchSortField.Score, SearchSortDirection order = SearchSortDirection.Ascending)
        {
            var criteria = new SearchCriteria(query)
            {
                AllowPrereleaseVersions = includePrerelease,
                PackageOriginFilter = originFilter,
                SortField = sort,
                SortDirection = order
            };

            var queryable = LuceneRepository.Search(criteria).LatestOnly(includePrerelease);

            var totalHits = queryable.Count();
            var hits = queryable.Skip(offset).Take(count).ToList();

            dynamic result = new ExpandoObject();
            result.Query = query;
            result.IncludePrerelease = includePrerelease;
            result.TotalHits = totalHits;
            result.Hits = hits;
            result.Offset = offset;
            result.OriginFilter = originFilter;
            result.Sort = sort;
            result.Order = order;
            return result;
        }
Esempio n. 4
0
        public dynamic Search(string query = "", bool includePrerelease = false, int offset = 0, int count = 20, PackageOriginFilter originFilter = PackageOriginFilter.Any, SearchSortField sort = SearchSortField.Score, SearchSortDirection order = SearchSortDirection.Ascending)
        {
            var criteria = new SearchCriteria(query)
            {
                AllowPrereleaseVersions = includePrerelease,
                PackageOriginFilter = originFilter,
                SortField = sort,
                SortDirection = order
            };

            LuceneQueryStatistics stats = null;
            var queryable = LuceneRepository.Search(criteria).CaptureStatistics(s => stats = s).LatestOnly(includePrerelease);

            var hits = queryable.Skip(offset).Take(count).ToList();

            dynamic result = new ExpandoObject();

            // criteria
            result.Query = query;
            result.IncludePrerelease = includePrerelease;
            result.TotalHits = stats.TotalHits;
            result.OriginFilter = originFilter;
            result.Sort = sort;
            result.Order = order;

            // statistics
            result.Offset = stats.SkippedHits;
            result.Count = stats.RetrievedDocuments;
            result.ElapsedPreparationTime = stats.ElapsedPreparationTime;
            result.ElapsedSearchTime = stats.ElapsedSearchTime;
            result.ElapsedRetrievalTime = stats.ElapsedRetrievalTime;
            result.ComputedQuery = stats.Query.ToString().Replace("`\b\u0000\u0000\u0000\u0001", "true").Replace("`\b\u0000\u0000\u0000\u0000", "false");

            // hits
            result.Hits = hits;
            return result;
        }