예제 #1
0
        protected override Facets InitialiseViewModel(Rendering rendering, DataSource dataSource)
        {
            var searchContext    = additionalContexts.Get <ISearchContext>();
            var facetedResultSet = additionalContexts.Get <IFacetedResultSet>();
            var resultAspect     = additionalContexts.Get <IPagedResultsAspect>();

            var vm = new Facets();

            // show the sorting button only if there is more than 1 result (and sorting is enabled)
            vm.ShowMobileSorting = resultAspect.ResultsTotal > 1 && searchContext.CollectionSettings.SortOptions != null &&
                                   searchContext.CollectionSettings.SortOptions.Any();

            vm.ClearAllFacetsLink = selectedFacetsFactory.ClearAllFiltersUrl(searchContext);
            vm.SelectedFacets     = selectedFacetsFactory.CreateSelectedFacets(searchContext);
            vm.ShowKeywordFacet   = searchContext.CollectionSettings.ShowKeywordFacet;
            vm.AvailableFacets    = facetFactory.Create(searchContext, facetedResultSet.Facets);
            vm.ShowMobileFilters  = (resultAspect.ResultsTotal > 1 && vm.AvailableFacets.Any()) || vm.ShowKeywordFacet;

            vm.Query        = searchContext.Query.Value;
            vm.FormBaseUrl  = HttpContext.Current.Request.Url.AbsolutePath;
            vm.HiddenFields =
                searchContext.AsNameValueCollection()
                .RemoveKey(Business.Search.Constants.SearchContext.Keys.Query)
                .RemoveKey(Business.Search.Constants.SearchContext.Keys.PageNumber)
                .RemoveKey(Business.Search.Constants.SearchContext.Keys.Facets);
            return(vm);
        }
예제 #2
0
        public ActionResult Index()
        {
            var res = contextStore.Get <PagedSearchResult <ISearchResult> >();

            if (res != null && res.ResultsTotal > 0)
            {
                return(View("~/Modules/Search/Results/ResultsView.cshtml",
                            new Results(res.Results, Sitecore.Context.Item.ID.ToString(), resultPartialFactory)));
            }

            var searchContext = contextStore.Get <ISearchContext>();
            var vm            = new NoResults.NoResults(selectedFacetsFactory.AnyFiltersActive(searchContext), selectedFacetsFactory.ClearAllFiltersUrl(searchContext), Sitecore.Context.Item.ID.ToString());

            return(View("~/Modules/Search/Results/NoResults/NoResultsView.cshtml", vm));
        }