Example #1
0
        private ListSource GetResult(ListSearchItemViewModel search)
        {
            const int PageSize = 15;
            var model = new ListSource();
            var query = new List<HttpLinkItem>();
            int totalHits;
            Dictionary<string, string> cacheDic = CreateSearchDic("ResultList", search);
            Dictionary<string, string> countDic = CreateSearchDic("ResultCount", search);
            if (string.IsNullOrWhiteSpace(search.Query)
                && CacheService.Exists(cacheDic)
                && CacheService.Exists(countDic))
            {
                query = CacheService.Get<List<HttpLinkItem>>(cacheDic);
                totalHits = CacheService.GetInt32Value(countDic);
            }
            else
            {
                var searchFilter = GetSearchFilter(search.Query, search.Order, search.Descending, search.Page, PageSize);

                using (MiniProfiler.Current.Step("LuceneSearch"))
                {
                    query = searchService.Search(search, searchFilter, out totalHits);
                }
                if (string.IsNullOrWhiteSpace(search.Query))
                {
                    CacheService.Add<List<HttpLinkItem>>(query, cacheDic, 10);
                    CacheService.AddInt32Value(totalHits, countDic, 10);
                }
            }
            model.Items = query;
            model.TotalCount = totalHits;
            model.CurrentPage = search.Page;
            model.PageSize = PageSize;
            model.Querywords = string.IsNullOrEmpty(search.Query) ? "" : search.Query;
            return model;
        }
Example #2
0
        public ActionResult GetSearchArea(float minX, float minY, float maxX, float maxY, int page = 1, int category = 0, int childcategory = 0, int price = 0)
        {
            var model = new ListSource();

            var result = new List<HttpLinkItem>();

            ListSearchItemViewModel query = new ListSearchItemViewModel();

            query.MinX = minX;
            query.MinY = minY;
            query.MaxX = maxX;
            query.MaxY = maxY;
            if (category != 0)
            {
                query.MediaCode = category;
                if (childcategory != 0)
                {
                    query.ChildMediaCode = childcategory;
                }
            }
            if (price != 0)
            {
                query.Price = price;
            }

            var pageSize = 10;

            int totalHits = 0;

            SearchFilter sf = new SearchFilter();

            sf.PageSize = pageSize;

            sf.Skip = (page - 1) * pageSize;

            sf.Take = pageSize;

            sf.SortProperty = SortProperty.Published;

            sf.SortDirection = SortDirection.Descending;

            result = searchService.Search(query, sf, out totalHits);

            model.Items = result;

            model.TotalCount = totalHits;

            model.CurrentPage = page;

            model.PageSize = pageSize;

            return Json(model, JsonRequestBehavior.AllowGet);
        }