Gravatar for shirazi@rdacorp.com

Question by aga, Jun 22, 2016 5:22 PM

NotSupportedException: Faceting Exception using Linq

Hi

I'm using Linq to execute a search and also facet the data using an attribute. The exception I'm getting is an ordering exception but I'm confused as I'm not ordering anything. FYI, EventIndexItem inherits from SearchResultItem. Also if I do not facet the results then the query succeeds.

Here's my code:

IQueryable<EventIndexItem> query = context.GetQueryable<EventIndexItem>().
    Where(x => x.TemplateName == "o Group" &&
                x.Path.StartsWith(searchPath) &&
                x.Dates.Equals(startDate.Date.Ticks.ToString())).
    CoveoWhere(keywords).
    FacetOn(f => "subjects", 100).
    Take(maxEventPerDay);

SearchResults<EventIndexItem> searchResuts = query.GetResults(); // throws exeption here!



System.NotSupportedException was unhandled by user code
  HResult=-2146233067
  Message=Ordering can only be done on 'Sitecore.ContentSearch.Linq.Nodes.FieldNode'. Expression used 'System.Linq.Expressions.Expression`1[[System.Func`2[[Web.UI.Models.EventIndexItem, Web.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'
  Source=Sitecore.ContentSearch.Linq
  StackTrace:
       at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitFacetOnMethod(MethodCallExpression methodCall)
       at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitQueryableExtensionMethod(MethodCallExpression methodCall)
       at Coveo.SearchProvider.LinqBase.CoveoExpressionParserBase.VisitMethodCall(MethodCallExpression p_MethodCall)
       at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.Visit(Expression expression)
       at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitGetResultsMethod(MethodCallExpression methodCall)
       at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitQueryableExtensionMethod(MethodCallExpression methodCall)
       at Coveo.SearchProvider.LinqBase.CoveoExpressionParserBase.VisitMethodCall(MethodCallExpression p_MethodCall)
       at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.Visit(Expression expression)
       at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.Parse(Expression expression)
       at Coveo.SearchProvider.CoveoQueryable`2.GetQuery(Expression p_Expression)
       at Sitecore.ContentSearch.Linq.Parsing.GenericQueryable`2.Execute[TResult](Expression expression)
       at Sitecore.ContentSearch.Linq.QueryableExtensions.GetResults[TSource](IQueryable`1 source)

Version Info:

Current Coveo for Sitecore version: 4.0.171.0

Current Sitecore version: 8.1.160302 
1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Jun 22, 2016 6:28 PM

Hi Aga,

Your call to FacetOn(f => "subjects", 100) seems strange. "subjects" as a literal string doesn't seem right.

I would try FacetOn(f => f["subjects"], 100) where "subjects" is the name of a Sitecore field or FacetOn(f => f.Subjects, 100) where "Subjects" is a property in the EventIndexItem class with an attribute to describe the related Sitecore field.

I hope this helps,

Jeff

Gravatar for shirazi@rdacorp.com

Comment by aga, Jun 23, 2016 9:19 AM

Jeff, i added a "Subjects" property to the EventIndexItem and changed linq to .FacetOn(f => f.Subjects, 100). This resolved the exception but the FacetCateory.Values is empty. I see that the Subjects field in the hits is populated with the subjects and I've configured that field as facetable. What could i be missing to return an empty facet?

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Jun 23, 2016 9:42 AM

Did you re-index your content tree after configuring the field as a facet? Also, if this field contains multiple values split by a semicolon, the field needs to be configured as isMultiValue="true" instead of isFacet="true".

Gravatar for shirazi@rdacorp.com

Comment by aga, Jun 23, 2016 11:47 AM

yes i rebuilt index and the sucjects are delimited by semicolon. Also i validated in the admin tool that the subjects field is facetable. And i also verified it in the index browser by running @fsubjects91546 = 'FacetValue'

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Jun 23, 2016 11:59 AM

Are you using the GetSearchResults() method on your IQueryable object? This is needed instead of the GetResults() method to get the search results and facets in a single call.

Gravatar for shirazi@rdacorp.com

Comment by aga, Jun 23, 2016 12:25 PM

i do not have GetSearchResults() (its not an extension in Sitecore.ContentSearch.Linq.QueryableExtensions). Is there another extension i need to use?

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Jun 23, 2016 1:07 PM

GetResults() is what should be used for your use case.

I see that you put the second parameter of "FacetOn" as 100. If the results has less than a 100 values for this facet, the values won't be populated. Try removing or lowering that 100 and see if you have any values.

Gravatar for shirazi@rdacorp.com

Comment by aga, Jun 23, 2016 1:22 PM

looks like that was the issue! But now I'm getting back only 10 facet values, how do i get all?

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Jun 23, 2016 3:33 PM

I have not found a way to change the maximum number of values returned for a single query, or a configuration. It is a possible improvement that we could do.

However, you can configure the default number of values with the node located in Coveo.SearchProvider.config, under the node.

It is recommended that you add a node in your Coveo.SearchProvider.Custom.config in your node like this:

<queryConfiguration type="Coveo.Framework.Configuration.QueryConfiguration, Coveo.Framework">
      <!-- The defaultNumberOfFacetValues element defines the default maximum number of facet values that are returned from a LINQ statement. -->
      <defaultNumberOfFacetValues>16</defaultNumberOfFacetValues>
</queryConfiguration>
Ask a question