AI OnAI Off
Hi,
First, create a new property on the page and fill it with the value that you have for the selected category.
public virtual IEnumerable<string> SearchCategories { get { var main = !ContentReference.IsNullOrEmpty(this.MainCategory) ? new List<string> { this.MainCategory.ID.ToString() } : new List<string>(); return main; } }
Then on the search function - you can use "BuildFilter" to do this task.
var categoriesFilterBuilder = _client.BuildFilter<BaseFeedPage>(); if (categories != null) { foreach (var filter in categories) { categoriesFilterBuilder = categoriesFilterBuilder.Or(x => x.SearchCategories.Match(filter)); } } var searchQuery = this._client.Search<T>(); searchQuery = searchQuery.Filter(categoriesFilterBuilder); var batch = searchQuery.GetContentResult();
Regards
Ravindra
You can't sort a list using a bool by passing it to OrderBy. Like you did in your code
ThenByDescending(x=>x.MainCategoryForFind.Match(desiredcategory))
You can filter the query first and then sort it
searchclient.Search<CourseProduct.CoursProduct>()
.Filter(x=> x.MatchTypeHierarchy(typeof(T)))
.FilterForVisitor()
.Filter(x=>x.MainCategoryForFind.Match(desiredcategory))
.OrderByDescending(x=> x.Featured)
.OrderByDescending(x=> x.MainCategoryForFind)
.ThenByDescending(x=>x.Created);
I have a requirement to sort products using a condition.
For ex -
First, products need to be sorted from the boolean property Featured
Then by a dynamic product category (coming from a algorithm which decides the category which the user has mostly bought)
Then by the created date
Following is the search query:
Please note that desiredCategory is the product category which describes above (This value is dynamic).
MainCategoryForFind is the top category of the product
Following exception throws from the query when trying to get the result.
Error - System.ApplicationException: 'Unable to retrieve the field type (such as return value) from expression of type MethodBinaryExpression.'
Then Modified code as below.
it also didn't work. Following error throws when trying to get the result.
System.NotSupportedException: 'Sorting by expressions of type EPiServer.Find.DelegateFilterBuilder is not supported. Change the sorting expression x => x.CourseTypeForFind.Match(value(EPiServer.UTS.Web.UTS.Features.ContentListing.ContentListingService+<>c__DisplayClass5_0`1[EPiServer.UTS.Web.UTS.Features.CourseProduct.CourseProduct]).courseType). Supported types to sort by are native value types such as int, DateTime, nullable versions of the same and strings.'
Is there any other proper way to fulfill this requirement ?