We have a productmodel with a list containing the episerver category ids.Now we want to order products by the selected category. We do not want to filter out products that do not have the categories, just put the ones with the category at the top.
var storeCategory = GetCategory(sortBy); productCollection.Products = productCollection.Products .OrderByDescending(x => x.Categories.Contains(storeCategory.ID) ? 1 : 0) .ThenBy(x => x.SortIndex).ToList();What we want is var searchResult = query.TermsFacetFor(x => x.FeatureCategories, request => request.Size = 1000) .TermsFacetFor(x => x.FeatureList, request => request.Size = 1000) .TermsFacetFor(x => x.Sports, request => request.Size = 1000).OrderByDescending(x => x.Categories.Contains(storeCategory.ID) ? 1 : 0).ThenBy(x => x.SortIndex).ToList(); .Skip(page * pageSize) .Take(pageSize) .GetResult();
That's the code for the orderby but this is not done on the actual query, so some products are lost.We tested using Match(storeCategory.ID) but that is not allowed within a OrderBy, only Filter from what I understood.
Hi,I suggest you use the multisearch API (http://world.episerver.com/Blogs/Marcus-Granstrom/Dates/2014/2/Multi-Search-with-EPiServer-Find-75/) and simply issue one query where you filter on all products in the specified category and one that filter on all products not in the category. When presenting the result you then simply merge the result sets. /Henrik
Hi, is that API available for EPiServer 7? The customer hasn't upgraded yet and won't be able to any time soon.