public ContentFilterService( FilterConfiguration filterConfiguration, CheckedOptionsService filterModelFactory, IContentRepository contentRepository, ISynchronizedObjectInstanceCache synchronizedObjectInstanceCache, SearchSortingService searchSorter, ReferenceConverter referenceConverter, IClient client) : base(filterConfiguration, filterModelFactory, contentRepository, synchronizedObjectInstanceCache, searchSorter, referenceConverter, client) { }
protected FilteringServiceBase( FilterConfiguration filterConfiguration, CheckedOptionsService filterModelFactory, IContentRepository contentRepository, ISynchronizedObjectInstanceCache synchronizedObjectInstanceCache, SearchSortingService searchSorter, ReferenceConverter referenceConverter, IClient client) { _filterConfiguration = filterConfiguration; CheckedOptionsService = filterModelFactory; ContentRepository = contentRepository; _synchronizedObjectInstanceCache = synchronizedObjectInstanceCache; SearchSortingService = searchSorter; ReferenceConverter = referenceConverter; Client = client; //FilterContentsWithGenericTypes = new Lazy<IEnumerable<FilterContentModelType>>(FilterContentsWithGenericTypesValueFactory, false); }
public override IEnumerable <IContent> GetItems(EPiServer.Cms.Shell.UI.Rest.ContentQuery.ContentQueryParameters parameters) { var filterModelString = parameters.AllParameters["filterModel"]; var productGroupedString = parameters.AllParameters["productGrouped"]; var sortColumn = parameters.SortColumns != null ? (parameters.SortColumns.FirstOrDefault() ?? new SortColumn()) : new SortColumn(); bool productGrouped; Boolean.TryParse(productGroupedString, out productGrouped); var listingMode = GetListingMode(parameters); var contentLink = GetContentLink(parameters, listingMode); var filterModel = CheckedOptionsService.CreateFilterModel(filterModelString); var searchType = typeof(CatalogContentBase); // make this selectable using Conventions api var filters = new Dictionary <string, IEnumerable <object> >(); if (filterModel != null && filterModel.CheckedItems != null) { filters = filterModel.CheckedItems.Where(x => x.Value != null) .ToDictionary(k => k.Key, v => v.Value.Select(x => x)); var receivedSearchType = GetSearchType(filterModel); if (receivedSearchType != null) { searchType = receivedSearchType; } } var content = ContentRepository.Get <IContent>(contentLink); var includeProductVariationRelations = productGrouped && !(content is ProductContent); var supportedFilters = GetSupportedFilterContentModelTypes(searchType).ToList(); var query = CreateSearchQuery(searchType); var startIndex = parameters.Range.Start ?? 0; var endIndex = includeProductVariationRelations ? MaxItems : parameters.Range.End ?? MaxItems; var cacheKey = String.Concat("ContentFilterService#", content.ContentLink.ToString(), "#"); if (!String.IsNullOrEmpty(sortColumn.ColumnName)) { cacheKey += sortColumn.ColumnName + sortColumn.SortDescending; } if (!includeProductVariationRelations) { cacheKey += startIndex + endIndex; } query = GetFiltersToQuery(content, supportedFilters, filters, query, ref cacheKey); query = SearchSortingService.Sort(sortColumn, query); var cachedItems = GetCachedContent <Tuple <IEnumerable <IFacetContent>, int> >(cacheKey); if (cachedItems != null) { parameters.Range.Total = cachedItems.Item2; return(cachedItems.Item1); } var properties = ContentRepository.GetDefault <FacetContent>(content.ContentLink).Property; var contentList = new List <IFacetContent>(); var linkedProductLinks = new List <ContentReference>(); var total = AddFilteredChildren(query, contentList, linkedProductLinks, properties, includeProductVariationRelations, startIndex, endIndex); parameters.Range.Total = includeProductVariationRelations ? contentList.Count : total; Cache(cacheKey, new Tuple <IEnumerable <IFacetContent>, int>(contentList, parameters.Range.Total.Value)); return(contentList); }