public ContentFilterService( FilterConfiguration filterConfiguration, CheckedOptionsService filterModelFactory, IContentRepository contentRepository, ISynchronizedObjectInstanceCache synchronizedObjectInstanceCache, SearchSortingService searchSorter, ReferenceConverter referenceConverter, IClient client) : base(filterConfiguration, filterModelFactory, contentRepository, synchronizedObjectInstanceCache, searchSorter, referenceConverter, client) { }
public override IEnumerable <FilterContentWithOptions> GetItems(ContentQueryParameters parameters) { var listingMode = GetListingMode(parameters); var contentLink = GetContentLink(parameters, listingMode); var filterModelString = parameters.AllParameters["filterModel"]; var cacheKey = String.Concat("FacetService#", contentLink, "#", filterModelString); var cachedResult = GetCachedContent <IEnumerable <FilterContentWithOptions> >(cacheKey); if (cachedResult != null) { return(cachedResult); } var content = ContentRepository.Get <IContent>(contentLink); var filters = new Dictionary <string, IEnumerable <object> >(); var filter = CheckedOptionsService.CreateFilterModel(filterModelString); if (filter != null && filter.CheckedItems != null) { filters = filter.CheckedItems.Where(x => x.Value != null) .ToDictionary(k => k.Key, v => v.Value.Select(x => x)); } var searchType = GetSearchType(filter) ?? typeof(CatalogContentBase); var possiblefacetQueries = FilterContentsWithGenericTypes.Where(x => x.ContentType.IsAssignableFrom(searchType) || searchType.IsAssignableFrom(x.ContentType)).ToList(); var subQueries = new Dictionary <FilterContentModelType, ISearch>(); AddSubqueries(possiblefacetQueries, subQueries, searchType); var filterContentModelTypes = GetSupportedFilterContentModelTypes(searchType).ToList(); AddFiltersToSubQueries(content, subQueries, filterContentModelTypes, filters, searchType); if (subQueries.Any()) { var result = GetFilterResult(subQueries, listingMode).ToList(); Cache(cacheKey, result); return(result); } return(Enumerable.Empty <FilterContentWithOptions>()); }
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); }