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); }
/// <summary> /// Initializes this instance with JSON data from an API response. /// </summary> /// <param name="data">JSON object</param> public ProductProjectionQueryResult(dynamic data) : base((object)data) { if (data == null) { return; } this.Results = Helper.GetListFromJsonArray <ProductProjection>(data.results); this.Facets = new Dictionary <string, Facet>(); if (data.facets != null) { foreach (JProperty facet in data.facets) { Facet f = FacetFactory.Create(facet.Value); this.Facets.Add(facet.Name, f); } } }