Gravatar for

Question by Cris Corra, Jul 29, 2014 5:48 PM

How can I pass additional query params from the standalone search box?

I have a standalone search box in the header of my website that correctly passes the value entered to the search results page and executes the query on that page. I would like to also pass additional query parameters to the search results page depending on the selected item in a drop-down list. I tried setting a hidden expression element:

. But it did not add it to the url. Is there a way to interrupt the standalone search box before it builds the url params and add my additional data?

Thanks! Cris Corra

*Update: here is a printout of the errors I am receiving on the results page:

Gravatar for

Comment by Cris Corra, Jul 29, 2014 5:55 PM


1 Reply
Gravatar for

Answer by Martin Laporte, Jul 29, 2014 6:00 PM

The standalone search box is in fact a fully working search interface that forwards it's state to the real search page, so you can add additional arguments by putting them in the state after calling initSearchBox (or when your selected value changes, etc.):

$('#mySearchBox').coveo('state', 't', 'Email');

Then the query string argument will be included in the hash when redirecting to the search page.

Gravatar for

Comment by Cris Corra, Jul 30, 2014 3:25 PM

That worked great! Thanks!

Gravatar for

Comment by Cris Corra, Jul 30, 2014 3:28 PM

I'm now having an issue with the facet value being selected. This is my generated url from the header searchbox: /search#q=release&first=0&f:@fcontentitemtype29877=[Latest]

I have a facet on the search page, but the "Latest" item is not being selected on load (nor are the results filtered). If put my cursor in the address bar and click enter, the facet value is selected. Do I need to re-init the query at some point? The text in the url is being used correctly in the query. -Cris

Gravatar for

Comment by Cris Corra, Aug 4, 2014 5:08 PM

I am getting errors on the search results page when it is trying to set the facet to my passed in value. I believe it's in the Model.prototype.validateType call where value="Meeting" and attribute="f:@fcontentitemtype29877".

Gravatar for

Comment by Martin Laporte, Aug 5, 2014 3:36 AM

State values for facets are arrays, so you must set their values like this:

        $('#search').coveo('state', 'f:@field', ['foo']);
Gravatar for

Comment by Cris Corra, Aug 6, 2014 12:32 PM

I am still getting the errors. I've updated my original post to include a printout of the errors.

Gravatar for

Comment by olamothe, Aug 6, 2014 7:24 PM

In your first screenshot, we can see that it's creating an url with f:@fcontentitemtype29877=['Meeting']. I think the problem come from the quotes around 'Meeting'.

For this to work correctly, the url needs to be f:@fcontentitemtype29877=[Meeting]

Gravatar for

Comment by Martin Laporte, Aug 7, 2014 3:31 AM

I've just done some additional testing both with a standalone search box and directly in the search page, and the code I posted in the comment above does produces the correct syntax in the query string (without quotes). The format we use in the query string looks a bit like json but it's not exactly the same.

Do you still get the error if you load the page anew in a tab without any argument?

Ask a question