Gravatar for

Question by Simon, Oct 13, 2016 4:09 PM

Custom component unable to set the advanced query

This is following up this question:

I am still trying to create a custom facet. I was able to create my custom component and create the following method:

            CustomFacet.prototype.customFacetClick = function() {
                this.bindings.queryStateModel.set('aq', '@syssource=="John West Blog"');
                   name : 'facetSelect',
                   type : 'facet'

As you can see, I am trying to set the "aq" parameter of my state in order to add additional filtering. This said, it will still fail with the following Console error:

"ERROR", "Assert", "Assertion Failed!" in the underscore template ts file

If I set the "q" parameter instead, it does work… I believe it is affecting the existing facets in a way. But I don't know why.

1 Reply
Gravatar for

Answer by ssartell, Oct 14, 2016 10:50 AM

I don't believe aq is managed by state. The components I've seen in the CoveoJsSearch source all register a handler for the Coveo.QueryEvents.buildingQuery event and use queryBuilder.advancedExpression.add or queryBuilder.advancedExpression.addFieldExpression. Also the QueryStateModel.attributesEnum object does not contain an entry for aq.

Gravatar for

Comment by Jean-François L'Heureux, Oct 14, 2016 1:58 PM

You are absolutely right.

Gravatar for

Comment by Simon, Oct 14, 2016 4:27 PM

This is correct, so you mostly need to add your own GroupByRequest on the queryBuilder on the query success of the search interface component. From then, you will have the field values and the count of each. Then you can create a click event on the custom facet component which will add the advanced expression to the current query being built by the interface. This will provide a basic clickable facet. From there you can add analytics logging and url management. A bit too long for an answer post however…

Ask a question