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?
Answer by Jean-François L'Heureux · Feb 04, 2015 at 09: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.
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"
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.
yes, how you should I write it? if it's a json, it will be something like this: CoveoForSitecore.componentsOptions.Facet.AllowedValues = { "CatalogProduct,People"};
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);
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