/// <summary> /// Orders a facet sequence /// </summary> /// <param name="source">Facets</param> /// <param name="sorting">Type of sorting</param> /// <param name="selectedFirst">Whether to display selected facets first</param> /// <returns>Ordered facets</returns> public static IOrderedEnumerable <Facet> OrderBy(this IEnumerable <Facet> source, FacetSorting sorting, bool selectedFirst = true) { Guard.NotNull(source, nameof(source)); switch (sorting) { case FacetSorting.ValueAsc: if (selectedFirst) { return(source .OrderByDescending(x => x.Value.IsSelected) .ThenBy(x => x.Value.Value)); } else { return(source.OrderBy(x => x.Value.Value)); } case FacetSorting.LabelAsc: if (selectedFirst) { return(source .OrderByDescending(x => x.Value.IsSelected) .ThenBy(x => x.Value.Label)); } else { return(source.OrderBy(x => x.Value.Label)); } case FacetSorting.DisplayOrder: if (selectedFirst) { return(source .OrderByDescending(x => x.Value.IsSelected) .ThenBy(x => x.Value.DisplayOrder)); } else { return(source.OrderBy(x => x.Value.DisplayOrder)); } default: if (selectedFirst) { return(source .OrderByDescending(x => x.Value.IsSelected) .ThenByDescending(x => x.HitCount) .ThenBy(x => x.Value.Label)); } else { return(source .OrderByDescending(x => x.HitCount) .ThenBy(x => x.Value.Label)); } } }
private void AddFacet( CatalogSearchQuery query, FacetGroupKind kind, bool isMultiSelect, FacetSorting sorting, Action <FacetDescriptor> addValues) { string fieldName; var displayOrder = 0; switch (kind) { case FacetGroupKind.Category: fieldName = _catalogSettings.IncludeFeaturedProductsInNormalLists ? "categoryid" : "notfeaturedcategoryid"; break; case FacetGroupKind.Brand: if (_searchSettings.BrandDisabled) { return; } fieldName = "manufacturerid"; displayOrder = _searchSettings.BrandDisplayOrder; break; case FacetGroupKind.Price: if (_searchSettings.PriceDisabled || !_services.Permissions.Authorize(Permissions.Catalog.DisplayPrice)) { return; } fieldName = "price"; displayOrder = _searchSettings.PriceDisplayOrder; break; case FacetGroupKind.Rating: if (_searchSettings.RatingDisabled) { return; } fieldName = "rating"; displayOrder = _searchSettings.RatingDisplayOrder; break; case FacetGroupKind.DeliveryTime: if (_searchSettings.DeliveryTimeDisabled) { return; } fieldName = "deliveryid"; displayOrder = _searchSettings.DeliveryTimeDisplayOrder; break; case FacetGroupKind.Availability: if (_searchSettings.AvailabilityDisabled) { return; } fieldName = "available"; displayOrder = _searchSettings.AvailabilityDisplayOrder; break; case FacetGroupKind.NewArrivals: if (_searchSettings.NewArrivalsDisabled) { return; } fieldName = "createdon"; displayOrder = _searchSettings.NewArrivalsDisplayOrder; break; default: throw new SmartException($"Unknown field name for facet group '{kind.ToString()}'"); } var descriptor = new FacetDescriptor(fieldName) { Label = _services.Localization.GetResource(FacetUtility.GetLabelResourceKey(kind) ?? kind.ToString()), IsMultiSelect = isMultiSelect, DisplayOrder = displayOrder, OrderBy = sorting, MinHitCount = _searchSettings.FilterMinHitCount, MaxChoicesCount = _searchSettings.FilterMaxChoicesCount }; addValues(descriptor); query.WithFacet(descriptor); }