Gravatar for matthieu.keromen@gmail.com

Question by kmelkez, Jun 2, 2014 2:58 PM

Standalone search box call twice

Hi,

I try to set a different url than current page for my page results. I do this :

JS

$('#searchBox').coveo('initSearchBox', $searchBox.data('mycoveo-searchurl'));

HTML

<div class="coveo-search-section-wrapper" id="searchBox" data-mycoveo-searchurl="/search">
                        <div class="CoveoSearchBox" data-activate-omnibox="true"></div>

After that, I call the 'init' event :

JS

$('#search').coveo('init', {});

'#search' is call from my body tag and so on each page load. My searchBox component is inside my body tag.

The problem is my input text box is called twice in my html markup. I think it's initialize on both event.

Any ideas ?

Thx

-- EDIT : Solution --

It's documented here : https://developers.coveo.com/display/JsSearch/Standalone+Search+Box

Gravatar for apare@coveo.com

Comment by Alexandre Paré, Jun 2, 2014 3:12 PM

Did your JS is in a dom ready function?

$(function () { $('#searchBox').coveo('initSearchBox', $searchBox.data('mycoveo-searchurl')); })

Gravatar for matthieu.keromen@gmail.com

Comment by kmelkez, Jun 2, 2014 4:27 PM

yes absolutely

1 Reply
Gravatar for mlaporte@coveo.com

Answer by Martin Laporte, Jun 2, 2014 3:11 PM

You don't need to call 'init' when using 'initSearchBox' --- that explains the double call I think.

Also, I'm not sure how $searchBox can work, but maybe I'm missing something?

Gravatar for matthieu.keromen@gmail.com

Comment by kmelkez, Jun 2, 2014 3:17 PM

Thanks, in fact $searchBox is my var shortcut for $('#$searchBox'). On the other side, I use params in my second argument like : .coveo('init', { SearchInterface: { hiddenExpression: etc.. How can I pass my arguments object AND my URL value with 'initSearchBox'

Gravatar for matthieu.keromen@gmail.com

Comment by kmelkez, Jun 2, 2014 4:35 PM

According to the code implementation, this one should work but it don't : $searchInterface.coveo('initSearchBox', $searchBox.data('mycoveo-searchurl'), { SearchInterface: { hiddenExpression: '(@syscollection==' + $searchInterface.data('mycoveo-collection') + ')' } });

Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, Jun 3, 2014 3:41 AM

That's right. I just realized this wasn't mentionned in the doc, so I added a note. Thanks!

Gravatar for matthieu.keromen@gmail.com

Comment by kmelkez, Jun 11, 2014 7:21 PM

@mlaporte I try again with implementation of 'initSearchBox' according to the documentation. If I try something like : $('#searchInterface').coveo('initSearchBox', 'myURL', [options]), my results list failed.

Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, Jun 12, 2014 3:35 AM

Can you paste the options you are using, as well as explain a little more how it's failing?

Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, Jun 12, 2014 3:43 AM

Can you describe a little more how it's failing? I tried your code pretty much as is and it works fine here… Do you get any error in the browser console?

Gravatar for matthieu.keromen@gmail.com

Comment by kmelkez, Jun 12, 2014 10:05 AM

No error in console, I'm redirected on my result page but all it's empty. I notice that my query is not sended to Rest API. Console log only print ["INFO", "JQuery", "Internal Coveo JQuery version", "1.9.1"].

Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, Jun 12, 2014 10:16 AM

But you do have the #q=query in the url bar when you're redirected to the search page, right?

Gravatar for matthieu.keromen@gmail.com

Comment by kmelkez, Jun 12, 2014 10:18 AM

Yes something like : /search#q=test&first=0. In the coveo-error-report tags : OOPS! SOMETHING WENT WRONG ON THE SERVER. If the problem persists contact the administrator. Maybe a problem with my endpoint. Is there a way to have a debug trace ?

Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, Jun 12, 2014 11:03 AM

OK then the searchbox part is working. Hmm must be something I don't understand about your setup. Are you using initSearchBox only on non-search page pages and init only on the search page?

Gravatar for matthieu.keromen@gmail.com

Comment by kmelkez, Jun 12, 2014 12:07 PM

Ok, you mean I have to do something like : $('#search'), $('#searchBox') with #search reference a div into my search page and #searchBox is a reference to the searchBox div (call in my header and so everywhere in my site). And so, two initialization like :

$('#searchBox') .coveo('initSearchBox', 'search') .on("populateOmniBox", onPopulateOmniBox);

$('#search') .coveo('init', ….);

Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, Jun 16, 2014 4:58 AM

Not exactly, but close. I'd call initSearchBox on all pages except on the search page, where I'd call 'init' instead.

When calling initSearchBox, you'd use #searchBox as the 'target' element. When calling 'init', you'd use #search and use the 'externalComponents' option to include your #searchBox (as described here: https://developers.coveo.com/display/JsSearch/Components).

I realize this is confusing, so I added a sample for this on this page - tell me what you think: https://developers.coveo.com/display/JsSearch/Standalone+Search+Box

Gravatar for matthieu.keromen@gmail.com

Comment by kmelkez, Jun 17, 2014 11:07 AM

Thank you, it was the point missing. It's very clear now.

Ask a question