Example #1
0
        /// <summary>
        /// This returns the results for Search Result View
        /// </summary>
        /// <param name="searchText">search Text</param>
        /// <param name="selectedTab">selected Tab Text</param>
        /// <returns>EntityViewModel collection</returns>
        private async Task<JsonResult> GetSearchResults(string searchText, string selectedTab, int currentPage, SearchViewModel searchQuery, SearchSortBy sortBy = SearchSortBy.Rating)
        {
            ViewData["SearchText"] = searchText = (string.IsNullOrWhiteSpace(searchText) || searchText.ToLower(CultureInfo.CurrentCulture).Equals(Resources.DefaultSearchText.ToLower(CultureInfo.CurrentCulture))) ? string.Empty : searchText;
            ViewData["SearchMessage"] = string.Empty;
            IEnumerable<EntityViewModel> results = null;
            var pageDetails = new PageDetails(currentPage);
            
                if (!string.IsNullOrWhiteSpace(searchText))
                {
                    
                    pageDetails.ItemsPerPage = searchQuery.ResultsPerPage;

                    var searchQueryDetails = new SearchQueryDetails();

                    if (searchQuery.ContentTypeFilter != null)
                    {
                        foreach (var contentFilterValue in searchQuery.ContentTypeFilter.Split(','))
                        {
                            searchQueryDetails.ContentTypeFilter.Add(Convert.ToInt32(contentFilterValue, CultureInfo.CurrentCulture));
                        }
                    }

                    if (searchQuery.CategoryFilter != null)
                    {
                        foreach (var categoryFilterValue in searchQuery.CategoryFilter.Split(','))
                        {
                            searchQueryDetails.CategoryFilter.Add(Convert.ToInt32(categoryFilterValue, CultureInfo.CurrentCulture));
                        }
                    }

                    searchQueryDetails.SortBy = searchQuery.SortBy.ToEnum<string, SearchSortBy>(sortBy);

                    results = await _searchService.SimpleSearch(searchText.Replace("'", "''"), CurrentUserId, pageDetails, searchQueryDetails);

                    // If the total count of items are less than the selected per page items, select previous per page items
                    //ViewData["CurrentPage"] = currentPage;
                    //ViewData["TotalPage"] = pageDetails.TotalPages;
                    //ViewData["TotalCount"] = pageDetails.TotalCount;
                }
                

            return Json(new{
                searchResults=results,
                pageInfo = pageDetails
            });
        }
Example #2
0
        public async Task<JsonResult> AjaxRenderResults(string searchText, string categories, string contentTypes, int currentPage, int pageSize)
        {

            if (categories == "0")
            {
                categories = null;
            }
            if (contentTypes == "0")
            {
                contentTypes = null;
            }
            var searchQuery = new SearchViewModel {ResultsPerPage = pageSize,CategoryFilter = categories, ContentTypeFilter = contentTypes};
            // It creates the prefix for id of links
            SetSiteAnalyticsPrefix(HighlightType.None);
            SessionWrapper.Set<string>("SelectedSearchType", "basic");
            var results = await GetSearchResults(searchText, "basic", currentPage, searchQuery);
            return Json(results);
        }