Gravatar for shoffma1@fairview.org

Question by Scott Hoffman, Dec 9, 2015 4:30 PM

Restrict JS Search results by path

Is there a better way to filter results by path?

I've been able to do this with the following in the default pipeline main.js file:

var aqAppend = '@fpath' + myCoveoGuid + '="' + contentSource + '"' ;

if (query.advancedExpression) {
    query.advancedExpression += ' AND ' + aqAppend;
} else {
    query.advancedExpression = aqAppend;
}

Which works fine. But with multiple environments with different unique identifiers, I'm wondering if there is a more generic way to access the fpath field.

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Dec 9, 2015 4:39 PM

Hello Scott,

Using the Coveo Search API pipelines is a very complicated way to filter the Coveo for Sitecore search results.

If you have the Enterprise edition of Coveo for Sitecore, you can filter the results directly in the rule editor of the properties of your Coveo Search sublayout/rendering on your search page Sitecore item (see Using Boosting/Filtering Rules on the Search component).

If you are using the Free or Pro edition, you can do it using JavaScript in your own copy of the Coveo Search sublayout/rendering (see https://developers.coveo.com/display/SitecoreV3/Adding+Filter+and+Boost+Expressions+Programmatically).

Gravatar for shoffma1@fairview.org

Comment by Scott Hoffman, Dec 10, 2015 9:30 AM

We are already using the pipeline to limit results to just the web database. It seemed like using that again would be the most natural extension. We're using the JS search framework in our own sublayouts and renderings that are not copies of the Coveo ones.

Gravatar for shoffma1@fairview.org

Comment by Scott Hoffman, Dec 10, 2015 10:21 AM

I've updated the above with code that actually works for us. The only part that really concerns me, is having to manually put in the unique identifier for the Coveo index, for each environment that we have. BTW, the reason for doing this as apposed to an inbound filter, is that we have some items outside the sitecore content tree that we're sharing among sites.

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Jan 12, 2016 5:54 PM

The Coveo Search API knows nothing about the Coveo for Sitecore logic to generate Coveo Enterprise Search field names.

If you only have to add an expression on the @fz95xpathXXXXX field (you should use "path" over "path" because "path" is the real Sitecore field), you can always configure it as an external field in Sitecore. That way, Coveo for Sitecore will remove the "f" prefix and "XXXXX" suffix from the field name in CES.

In Coveo.SearchProvider.config:

<fieldNames hint="raw:AddFieldByFieldName">
  <fieldType fieldName="_path" isExternal="true" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" />
</fieldNames>
Ask a question