Gravatar for

Question by coveoriz, Oct 29, 2015 2:13 PM

Coveo for Sitecore Linq Query producing strange CES Console query

We are using Sitecore 7.1 version with Coveo as Indexing Service.

A template is created in Sitecore with a field name as Auto Suggestion.

In sitecore code, I need to get the CustomSearchResultItem based on this Index field. So in my class I define an index field as

[IndexField("auto suggestion keyword")]
public string Keyword {get; set;}

The class inherits the SearchResultItem class.

In the calling method, I use this field to search the items by passing some value. But there is no response. Here's my Linq expression:-

var items = context.GetQueryable<CustomSearchResultItem>().Where(item => item.Keyword.StartsWith("test"));

In the CES console, it evaluates the query by adding * at the end to this field.


This is the reason that there are no indexed items. If the asterisk is removed from the query from the CES Console (i.e @fautoz32xsuggestionz32xkeyword97518="test*") and the query is evaluated in the CES admin panel, it provides proper results.

I would like to know as to why an asterisk gets added to the field for evaluation, and if there's something that is missing from my CustomSearchResultItem model, or the Linq expression?

1 Reply
Gravatar for

Answer by Jean-François L'Heureux, Oct 29, 2015 2:58 PM

The *= field operator is used to do wildcard field searches. When using wildcard search on a field, this field must be facet in CES unless it won't return any result.

When using the "Contains" or "StartsWith" LINQ operators, Coveo for Sitecore automatically generates wildcard queries. To match a keywork inside the field value, you should use the "ContainsKeyword" LINQ operator added by Coveo for Sitecore (see Coveo LINQ Extensions).

If you really want to continue with the "StartsWith" operator, here is the documentation to set the field as a facet field (see Creating a rule based on a field using a comparator different from "equals").

Hope this helps,


Gravatar for

Comment by sholmesby, Oct 29, 2015 5:38 PM

How about using the Coveo Query Syntax?

Could that work with .StartsWith(), or would that require the field to be a Free Text Query field in the field set?

Gravatar for

Comment by Jean-François L'Heureux, Oct 29, 2015 5:44 PM

I don't understand what do you mean by Coveo Query syntax when using the LINQ module?

.StartsWith() only work with fields. It doesn't work for free text search.

Coveo does add two extensions .CoveoWhere(string) and .CoveoOr(string) that can be used for free text search or with fields that are not translated (e.g.: @syssource).

Gravatar for

Comment by sholmesby, Oct 30, 2015 10:06 AM

I was wondering if you can do something like the following:

context.GetQueryable<CustomSearchResultItem>().CoveoWhere(coveoFieldName + " = \"test*\"");

I figure this translates to @fautoz32xsuggestionz32xkeyword97518 = "test*"

I'm not sure if this works, but I was wondering if this is a way to get the 'StartsWith' functionality without needing any configuration changes for the field.

Gravatar for

Comment by sholmesby, Oct 30, 2015 11:30 AM

I noticed that when setting up Auto Suggestions in Sitecore, you add a Facet to the Facts folders. Step 5.

After doing this and rebuilding the indexes, I see that Coveo sets the field to a 'free text query'. So I suppose this could be done in order to automatically get the field with the '.StartsWith()' functionality working.

Ask a question