Coveo LINQ Extensions
Coveo LINQ Extensions
Coveo for Sitecore (November 2018)
You can use the Coveo LINQ extensions by adding a reference to the Coveo.SearchProvider.LinqBase
assembly in your project.
Note that throughout this tutorial, the term Field
is used as a generic way to identify any property of type string
on a Sitecore item. For example, for Sitecore.ContentSearch.SearchTypes.SearchResultItem
, you could specify Name
, Url
, TemplateName
, Language
, etc.
Coveo LINQ Extensions
CoveoAdvancedExpression
Coveo for Sitecore (January 2017)
The CoveoAdvancedExpression
is used to apply a filtering expression as an advanced expression. The advanced expression is typically used to restrict the scope of the user search query given the context.
The extension can be used in two ways: with a predicate or with free text terms.
With the predicate:
queryable.CoveoAdvancedExpression(item => item.Field == "value" || item.Field2 == "value2").ToList();
With free text terms:
queryable.CoveoAdvancedExpression("Free Text Terms").ToList();
CoveoBoost
The CoveoBoost
is used to create a QRE on a query. The results returned from the inner expression is boosted by the amount specified in the second parameter.
queryable.CoveoBoost(item => item.Field == "value" || item.Field2 == "value2", 200).Tolist();
CoveoConstantExpression
Coveo for Sitecore (January 2017)
The CoveoConstantExpression
is used to apply a filtering expression as a constant expression. The constant expression must be used carefully. Using this expression can make query execution faster, as the search index prefetches the results matching the various constant expressions. However, relying heavily on constant expressions may put too much pressure on the search index and reduce the overall performance.
The extension can be used in two ways: with a predicate or with free text terms.
With predicates:
queryable.CoveoConstantExpression(item => item.Field == "value" || item => item.Field2 == "value2").ToList();
With free text terms:
queryable.CoveoConstantExpression("Free Text Terms").ToList();
CoveoWhere
The CoveoWhere
is used to add free text terms or Coveo query syntax terms to a query. The result is a query using the AND operator between the original query and the terms specified in the parameter.
queryable.CoveoWhere("Free Text Terms").Tolist();
CoveoOr
The CoveoOr
is used to add free text terms or Coveo query syntax terms to a query. The result is a query using the OR operator between the original query and the terms specified in the parameter.
queryable.CoveoOr("Free Text Terms").Tolist();
CoveoIn
The CoveoIn
extension is used to create a nested query inside another query. This extension is used on a specific field and must specify an inner object, a field from the inner object, and an inner expression.
queryable.Where(item => item.InField.CoveoIn((InnerType i) => i.OutField, i => i.Field == "value")).Tolist();
PhoneticMatch
The phoneticMatch
can be used on a string field to create a phonetic search on this specific field.
queryable.Where(item => item.Field.PhoneticMatch("vahluh")).Tolist();
ExactMatch
The ExactMatch
extension performs an exact match on a string field by comparing it to the specified value.
queryable.Where(item => item.Field.ExactMatch("exact value")).Tolist();
ContainsKeyword
The ContainsKeyword
extension looks up in a string field for the specified keyword by using stemming, so similar keywords also match.
queryable.Where(item => item.Field.ContainsKeyword("keyword")).Tolist();
GetCoveoQueryResults
Coveo for Sitecore (July 2016)
The GetCoveoQueryResults
extension returns an object containing the query results and metadata (see Using QueryResults to Retrieve Query Metadata).
queryable.Take(10).GetCoveoQueryResults()