Gravatar for alexander.kravchuk@apiqu.com

Question by Alexander Kay, Nov 27, 2017 2:41 PM

Coveo for Sitecore Query is Undefined

Hi everybody,

We are using Coveo for Sitecore 4.1 (October) cloud pro version.

The website has global coveo search box at the top bar and it redirects user to the search page with query string parameter q={users input}.

On the search page we have additional advanced and constant queries specified in javascript. Everything works fine except query itself. I have "q" parameter in url:

http://{domain}/en/Search#q=geoparks

But for some reason, in ajax request to coveo rest services I have "q"=undefined. But "aq" and "cq" is okay.

Do you have any idea what can be wrong with it?

Thanks,

Alex.

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Nov 27, 2017 2:54 PM

Can you check if the `enableHistory` property is set on your Coveo Search Interface component?

It is required to read the `q` state in the URL.

Can you also validate that entering a new search term in the Search Box _updates_ the `q` part of the URL?

2 Replies
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Nov 27, 2017 2:52 PM

This can happen if you initialize your searchbox separately from the main search interface (if they are not linked together in the search page). On the search page, you have to link the searchbox and the search interface components with an External Components Section component. See this tutorial for more info: https://developers.coveo.com/x/-SkvAg

Gravatar for alexander.kravchuk@apiqu.com

Comment by Alexander Kay, Nov 27, 2017 3:09 PM

Hi @Jean-François L'Heureux, checking that...

Gravatar for alexander.kravchuk@apiqu.com

Answer by Alexander Kay, Nov 27, 2017 3:46 PM

I'm end up with this piece of javascript on the search page:

Coveo.$('#@Model.Id').on('buildingQuery',
            function(e, args) {
                var queryBuilder = args.queryBuilder;
                queryBuilder.constantExpression.addFieldExpression('@Model.ToCoveoFieldName("Show in Search Results")', '==', ['1']);
                queryBuilder.constantExpression.addFieldExpression('@Model.ToCoveoFieldName("_id")', '<>', ['@Sitecore.Context.Item.ID.ToShortID()']);
                var q = getHashValue('q');
                if (q) queryBuilder.expression.add(q);
            });

Works as a charm nevertheless, I do undestand this is not Feng Shui. If you have any thoughts how I can make it work in more elegant way it would be good.

Thanks,

Alex.

Ask a question