Gravatar for nicolas.a.slavik@accenture.com

Question by yonico, Feb 4, 2015 9:35 AM

coveo facet allowed values

Hello - we are trying to implement the allowed values feature for facets and I was wondering if you can provide examples of where should be placed and the syntax.

allowedValues

allowedValues: ["File,People"]

Specifies an explicit list of allowedValues in the group by request. (See : Group By Parameters )

Does this go as a script inside Coveo.Search.ascx?

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Feb 4, 2015 9:48 AM

This question was already answered here: https://answers.coveo.com/questions/2117/custom-facets-in-coveo

If you go with the Javascript code way, it goes in a copy of the CoveoSearch.ascx file to preserve the original one. Be sure to follow these instructions to set custom initialization options: https://developers.coveo.com/display/SC201502/Setting+Custom+Initialization+Options

If you want to go with the HTML data attribute way, you'll need to duplicate the CoveoFacet.ascx file and add your data attribute in it.

In all cases, when you copy the original ascx files, you need to create new sublayouts in Sitecore that targets your new ascx files and use those sublayouts in your search page presentation details.

Gravatar for nicolas.a.slavik@accenture.com

Comment by yonico, Feb 4, 2015 10:16 AM

I was doing the javascript way.

CoveoForSitecore.componentsOptions.Facet.AllowedValues:["SizesFolder","CTA"]

It says "Your query has an error: Invalid exact phrase. in 0.02 second"

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Feb 4, 2015 10:25 AM

Do you have any error in your browser console? I suspect your Javascript code isn't valid. You cannot set a variable with the : operator.

Gravatar for nicolas.a.slavik@accenture.com

Comment by yonico, Feb 4, 2015 12:12 PM

yes, how you should I write it? if it's a json, it will be something like this: CoveoForSitecore.componentsOptions.Facet.AllowedValues = { "CatalogProduct,People"};

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Feb 4, 2015 1:36 PM

Are you familiar with Javascript, JSON objects, variables and arrays?

https://developers.coveo.com/display/JsSearch/Facet+Component#FacetComponent-allowedValues

The documentation says: allowedValues: ["File","People"]

You're right that this representation is for a JSON object that can be passed to the coveo/coveoForSitecore jQuery plugins function to initialize the JS UI like this:

var options = { Facet : { allowedValues: ["File","People"] } };
Coveo.$("#search")coveo("init", options);
Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Feb 4, 2015 1:37 PM

You can see that the key is allowedValues and the value is an array of strings. The same data types should be used when setting the key/value as a variable assignment like this:

CoveoForSitecore.componentsOptions.Facet.allowedValues = ["File","People"];

The CoveoForSitecore.componentsOptions.Facet key will probably be undefined by default. You will need to initialize it to an empty JSON object if it doesn't exist before trying to assign its allowedValues key. You have an example of this in your related question: https://answers.coveo.com/questions/2244/coveo-facet-value-caption

Ask a question