November Happy Hour will be moved to Thursday December 5th.

Orderby on list

Vote:
 

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.

BR,

Henrik

#118110
Feb 27, 2015 10:58
Vote:
 

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

#118207
Mar 02, 2015 14:38
Vote:
 

Hi, is that API available for EPiServer 7? The customer hasn't upgraded yet and won't be able to any time soon.


Br,
Henrik

#118214
Mar 02, 2015 15:45
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.