ConstantExpression partial match
In ConstantExpression condition, how to add a partial match ? e.g. args.queryBuilder.constantExpression.add('@(Model.ToCoveoFieldName("parentpath")) == "/sitecore/content/home/news"');
As @mlaporte suggested, your initial problem is that you are using the "==" (equal) operator instead of the "=" (contains keyword) operator.
This query would return all the descendants of the "news" item but will not give you the best performance due to the "contains" operator:
Secondly, there is more performant alternatives than matching a Sitecore item starts path to get the result you want. The best way is to use the "_path" Sitecore field which is a multi-value field that contains the ID of the item and the IDs of its parents. Let's say your "/sitecore/content/home/news" item has the ID aea9e38c-38a2-4d86-922b-53ee1dd8b52e.
This query would return the "news" item and all of its descendants.
To exclude the "news" item itself, you can add an exclusion like this. There's an implicit AND between the 2 field expressions.
Lastly, I want to warn you on using the
constantExpression for your filters.
The constant expression is a special expression of a query that should never change in time. It should be very static. Each time you change a constant expression by modifying your code, the expression gets added to a cache in Coveo Enterprise Search. This cache is never cleared and contains all the constant expressions the index received since its creation. Each time an index transaction is committed (after a rebuild, after an item creation/modification/delete in Sitecore, after a publish…), all the constant expressions in the cache are queried to refresh their results for performance. If the index have too many constant expressions in its cache, it will cause performance issues at each transaction commit. Thus, using the constant expressions with a lot of care in your code.
I suggest you to add those filters in the
advancedExpression instead. This expression is also hidden to the end user but not added in a cache. It is the place where to add search page filters.
I hope this answers your question.
Have a look at the
$some query extension: https://developers.coveo.com/display/SearchREST/Standard+Query+Extensions#StandardQueryExtensions-$some