Gravatar for ravigupta020287@gmail.com

Question by Ravi, Dec 14, 2016 6:40 AM

Expanding the hierarchical facet when it is selected

Coveo facets should expand when browsed from URL. When browsed with URL like: https:///search#t=resources&f:@fz95xhierarchicalcategory56890_3b371d413c9c401685a1d1dc470181a9=[Publication%20Type%7CAccessory%20Catalog]

The corresponding Facet should be expanded with the selected facet checked.

How can i implement this in coveo for sitecore mvc view?

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Dec 14, 2016 8:10 AM

Facets should behave the same way when using the Coveo for Sitecore MVC views.

What is the problem you are facing?

Gravatar for ravigupta020287@gmail.com

Comment by Ravi, Dec 14, 2016 10:23 PM

When i am browsing the URL: https:///search#t=resources&f:@fz95xhierarchicalcategory56890_3b371d413c9c401685a1d1dc470181a9=[Publication%20Type%7CAccessory%20Catalog] The Facet are not expanding by default.

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Dec 15, 2016 7:39 AM

Is your facet ID really fz95xhierarchicalcategory56890_3b371d413c9c401685a1d1dc470181a9 ? Try setting an "friendly" ID to ensure we have the right one.

Where does that URL comes from? Is it a link from a previous search or is it generated by some code in another part of the site?

Gravatar for ravigupta020287@gmail.com

Comment by Ravi, Dec 15, 2016 11:08 PM

this URL get generated when user select the facet, we have copied that URL and added in a menu link of the website to redirect the user to the search page with the relevant facet selected.

1 Reply
Gravatar for flguillemette@coveo.com

Answer by François Lachance-Guillemette, Dec 19, 2016 7:59 AM

The problem here is that the Facet uses a generated ID in the rendering.

However, the ID can change since it concatenates the Facet's Field ID with a Unique ID based on the order the renderings were added.

To solve this problem, set a fixed unique ID in the Facet component properties and use this ID instead in your pages that references it.

This solution has been improved in 4.0.290, we now set a new generated unique ID that is created on component creation instead.

Gravatar for ravigupta020287@gmail.com

Comment by Ravi, Dec 21, 2016 1:19 AM

i tried using unique ID in the facet attribute, but doesn't work form me. tried using the script to expand facet, this also doesn't seems to work, what i am doing wrong here?

Coveo.$(function () { Coveo.$('#tabbed-search').on('querySuccess', function (e, data) { Coveo.$('.CoveoHierarchicalFacet').coveo('expandFacet'); }); });

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Dec 21, 2016 8:18 AM

i tried using unique ID in the facet attribute, but doesn't work form me.

What doesn't work? Could you explain your problem so I can help you with it? What have you tried?

tried using the script to expand facet …

You should probably enter another question for this since it is unrelated to the problem here.

Gravatar for ravigupta020287@gmail.com

Comment by Ravi, Dec 21, 2016 11:39 PM

I am trying to expand the facet when a facet value is selected in the Hierarchical facet components. When browsed with URL like: https:///search#t=resources&f:@fz95xhierarchicalcategory56890_3b371d413c9c401685a1d1dc470181a9=[Publication%20Type%7CAccessory%20Catalog]

I have tried the solution mentioned above by using uniqueID in component properties of Hierarchical Facet compoent, but doesn't work.

I also tried one solution in a post, that uses the script to expand the selected facets Coveo.$('.CoveoHierarchicalFacet').coveo('expandFacet'); }); }); but no luck with this as well getting error in browser console Uncaught TypeError: Cannot read property 'hide' of undefined

Gravatar for ravigupta020287@gmail.com

Comment by Ravi, Dec 21, 2016 11:42 PM

For the error above i tried the solution in the post https://answers.coveo.com/questions/4093/unable-to-collapse-hierarchical-facet but that also doesn't seems to work.

Ask a question