public IActionResult SearchOld(int p, string o, string q, int t)
        {
            if (p == 0)
            {
                p = 1;
            }

            int?tagId = t;

            if (t == 0)
            {
                tagId = null;
            }

            if (o == null)
            {
                o = "created-desc";
            }

            var searchRequest = new SearchRequest();

            searchRequest.Text    = q;
            searchRequest.Page    = p;
            searchRequest.OrderBy = o;
            searchRequest.Type    = "question";
            searchRequest.TagId   = tagId;

            var manager    = new ContentManager();
            var results    = manager.Search(searchRequest);
            var resultPage = new SearchResultViewModel()
            {
                Results = results, Request = searchRequest
            };

            resultPage.ResultsCount = ContentApi.GetSearchResultCount("question", q, t);
            resultPage.MaxPages     = Math.Min(5, (int)Math.Floor((double)resultPage.ResultsCount / 10));

            if (resultPage.ResultsCount % 10 != 0)
            {
                resultPage.MaxPages++;
            }

            //move to Tag controller
            resultPage.Tags = TagApi.Select().OrderByDescending(tag => tag.Count).Take(8).ToList();

            return(View("Results", resultPage));
        }
Beispiel #2
0
        public IActionResult Search(int p, string o, string q, int t)
        {
            var db = new DbApi();

            if (p == 0)
            {
                p = 1;
            }

            int?tagId = t;

            if (t == 0)
            {
                tagId = null;
            }

            if (o == null)
            {
                o = "created-desc";
            }

            var content = ContentApi.Search(10, p, "question", q, o, tagId);

            var result = new ContentListModel();

            result.Content      = content;
            result.ResultsCount = ContentApi.GetSearchResultCount("question", q, t);

            result.MaxPages = Math.Min(5, (int)Math.Floor((double)result.ResultsCount / 10));

            if (result.ResultsCount % 10 != 0)
            {
                result.MaxPages++;
            }

            result.Page       = p;
            result.SearchText = q;
            result.OrderBy    = o;
            result.Tags       = TagApi.Select().OrderByDescending(tag => tag.Count).Take(8).ToList();

            return(View("Results", result));
        }