Gravatar for slangevin@coveo.com

Question by Simon, Jun 16, 2014 9:04 AM

Sort order using LINQ, Coveo for Sitecore

Hi guys, trying to sort or order using LINQ for Coveo and it returns an exception, see bellow:

var result = context.GetQueryable().Where(i => i["GloveID"] == gloveID && i["fallbacklanguages"] == Sitecore.Context.Language.Name && i.ItemId != currentItem.ID && i.TemplateId == currentItem.TemplateID).OrderBy(p => p["StyleID"]).ToList();

It returns the below exception:

Exception: Coveo.Framework.Exceptions.LinqToCoveoIndexException Message: COVEOLINQTOCOVEOINDEX_EXCEPTION : InvalidSortField - @fstyleid60016 Source: Coveo.SearchProviderBase at Coveo.SearchProvider.LinqToCoveoIndex1.FindElements[TElement](CoveoCompositeQuery p_Query) at Sitecore.ContentSearch.Linq.Parsing.GenericQueryable2.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

Using the Sortby method returns the below exception:

Exception: System.ArgumentException Message: Instance property 'StyleID' is not defined for type 'Sitecore.ContentSearch.SearchTypes.SearchResultItem' Source: System.Core at System.Linq.Expressions.Expression.Property(Expression expression, String propertyName) at System.Web.UI.WebControls.QueryExtensions.SortBy[T](IQueryable`1 source, String sortExpression

Any ideas?

1 Reply
Gravatar for lbergeron@coveo.com

Answer by Luc Bergeron, Jun 16, 2014 9:42 AM

I guess the field @fstyleid60016 is not flagged as sortable in CES. You can just set the field as sortable in the field map. To do so, edit the Coveo.SearchProvicer.config file and insert the element below under the fieldMap element.

<fieldType fieldName='styleid' isSortable="true" settingType='Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework' />

You can also set those attributes when needed: isFacet, includeForFreeTextSearch, isMultiValue. You will need to reindex the Sitecore items after you change the configuration.

Hope this helps

Ask a question