示例#1
0
        private QuerySource GetResult(QueryTerm queryTerm)
        {
            const int PageSize = 15;
            var       model    = new QuerySource();
            var       query    = new List <LinkItem>();
            int       totalHits;
            Dictionary <string, string> cacheDic = CreateSearchDic("ResultList", queryTerm);
            Dictionary <string, string> countDic = CreateSearchDic("ResultCount", queryTerm);

            if (string.IsNullOrWhiteSpace(queryTerm.Dq))
            {
                if (string.IsNullOrWhiteSpace(queryTerm.Query) &&
                    CacheService.Exists(cacheDic) &&
                    CacheService.Exists(countDic))
                {
                    query     = CacheService.Get <List <LinkItem> >(cacheDic);
                    totalHits = CacheService.GetInt32Value(countDic);
                }
                else
                {
                    var searchFilter = GetSearchFilter(queryTerm.Query, queryTerm.Order, queryTerm.Descending, queryTerm.Page, PageSize);
                    query = OutDoorLuceneService.Search(queryTerm, searchFilter, out totalHits);
                    //query = OutDoorLuceneService.Search(out totalHits);

                    if (string.IsNullOrWhiteSpace(queryTerm.Query))
                    {
                        CacheService.Add <List <LinkItem> >(query, cacheDic, 10);
                        CacheService.AddInt32Value(totalHits, countDic, 10);
                    }
                }
            }
            else
            {
                var searchFilter = GetSearchFilter(queryTerm.Query, queryTerm.Order, queryTerm.Descending, queryTerm.Page, PageSize);
                query = OutDoorLuceneService.Search(queryTerm, searchFilter, out totalHits);
            }
            model.Items       = query;
            model.TotalCount  = totalHits;
            model.CurrentPage = queryTerm.Page;
            model.PageSize    = PageSize;
            model.Querywords  = string.IsNullOrEmpty(queryTerm.Query) ? "" : queryTerm.Query;
            return(model);
        }