I have a client who is using facets for their location vertical (think ATM, Branch, Surcharge-free atm, etc…). Right now it looks like the facets show up in an order based on which facet has the most relevant results. So for example:
Surcharge Free ATM (25)
Branch (24)
ITM (5)
My client has asked whether or not we can customize this order, because they would ideally like “Branches” to show at the top. What do you think?
Also somewhat related to this - can we customize the name of the Facet filter (ideally, I want to leave the name of the Custom Field as-is)? Example screenshot:
Unfortunately no, currently there is no way to control the order in which facets options appear. We hear you, though, and we’re considering ways to make facet order configurable.
The name (i.e. “Answers Specialty”) of the facet filter pulls directly from the Display Name of the field itself, so you’d have to change that in your account settings. There is no way to override it on the front-end.
Thanks for following up! I did see this code in the Answers ReadMe, however, which caused me a bit of confusion. This code implied you can customize. Or is this for static filters and not facets? It’s hard to tell!
Correct! Those are static filters. Since static filters do not depend on the query itself and are defined client-side, on the page, you can customize everything about them - their order, labels, etc. Facets, on the other hand, are returned by the server and depend on the query, so we haven’t yet created a mechanism for controlling the order in which they appear. It’s on the roadmap, though!
Related to this post - my client is looking to adjust the order of facet types (e.g., not the order of the content in the field themselves, but the larger field).
For example, if I have 5 types of facets - Gender, Languages, Specialty, Subspecialty. Can I make Specialty facet to be first rather than the Gender field?
Ah I see! To clear up any confusion, when I say facets I mean the overarching field (i.e. Insurance AcceptedI) and when I say facet options I mean the individual options within it (i.e. Aetna, Cigna etc.)
But alas, today you cannot control the order of either of these things. What’s on the more immediate roadmap is to control the order of the facets. As you point out, you should be able to make Specialty appear first or Gender appear last. Important facets should be first; unimportant ones should go last.
Controlling the order of facet options is not something that is currently on the roadmap, but we would be interested to hear about the use case!
Are there any updates on being able to change Facet Names in the Search Configuration? We currently use naming conventions for the “Display Name” in the KG and wouldn’t want those to display on the FE of answers
There are currently no updates in being able to change the Facet Names (these will reflect the Knowledge Graph Display Names), we’ll keep this post updated with any further development here!
Controlling the order of facet options is not yet supported but on the product roadmap. We recommend making your facet options searchable in the meantime, which will allow a user to type for an option. There is more info in the facets component section of our Github documentation.
Wanted to follow-up on Ella’s previous question - do we have any update on timing for when ordering options within a facet will be enabled? And will that ordering be customizable, or will it be limited to only alphabetical ascending/descending?
Thanks for reaching out! This is still on the roadmap and we hope to have an update for you in the later this Spring. We’ll keep you posted as soon as this functionality is possible.
You can sort facet options by using transformFacets (more info on our Github).
transformFacets takes in and returns an array of the facet options, so you can write your own custom sorting logic in Javascript. Some examples:
transformFacets: facets => {
return facets.map(facet => {
//Sort address.region by ascending
if (facet.fieldId === 'address.region') {
facet.options.sort((a, b) => (a.value > b.value) ? 1 : -1)
}
//Sort languages by descending
if (facet.fieldId === 'languages') {
facet.options.sort((a, b) => (a.value > b.value) ? -1 : 1);
}
//Pin New York to the top of address.city when sorted by descending
if (facet.fieldId === 'address.city') {
topPinIndex = facet.options.map(option => option.value).indexOf('New York');
topPin = facet.options.splice(topPinIndex, 1);
facet.options.sort((a, b) => (a.value > b.value) ? -1 : 1);
facet.options.splice(0, 0, topPin[0]);
}
return facet;
});
}
If you are using the Answers UI SDK, you can pass transformFacets as part of the parameters of ANSWERS.addComponent('Facets', {})
If you are using the Code Editor, you can do a jambo override for this file and replace lines 11-13 with your transformFacets. It’s an .hbs file, but you can put JavaScript there.
As a follow up, the ability to control this via the config/json file was released in our October '21 Monthly release. Read more here: Facet Options Order (October '21 Release)
In case anyone needs, you can update the overarching facet order by going to Search > Your Search Experience > Edit as JSON and finding the vertical you’d like to change the facet order for. Add the following code within the vertical; make sure that you’re using the field API name (i.e. address.postalCode):