Javascript API

The Zoovu Search Plugin provides a set of methods that can be used to trigger specific behavior from outside of the plugin or to dynamically update some of the configuration options.

Configuration

Update configuration

The changeConfig method allows you to update a configuration parameter at runtime (after Zoovu Search has been initialized).

Parameters

  • key:String - the key of the parameter, equal to the path through zoovuSearchConfig object, e.g. suggestions.show

  • value:* - the value to be set

Usage example

To update the included result groups you can call the changeConfig method like this:

ZOOVU_SEARCH.changeConfig('contentGroups.include',['Recipes']);

A similar result can be achieved by setting the whole contentGroups object as follows:

ZOOVU_SEARCH.changeConfig('contentGroups',{include:['Recipes'],exclude:undefined});

Update siteId

To update the siteId after the plugin initialization you can call the setSiteId method.

Parameters

  • siteId:String - the siteId to be set

Usage example

ZOOVU_SEARCH.setSiteId('mySiteId.com');

Change base URL

To update the URL from which search results are loaded you can call the setBaseUrl method.

Parameters

  • baseUrl:String - the search URL to be used

Usage example

ZOOVU_SEARCH.setBaseUrl('https://api.search-studio.zoovu.com/sites');

Change suggestion URL

To update the URL from which search suggestions are loaded you can call the setSuggestUrl method.

Parameters

  • url:String - the suggestion URL to be used

Usage example

ZOOVU_SEARCH.setSuggestUrl('https://api.search-studio.zoovu.com/sites/suggest');

Controls

(Re-)Initialize

The Zoovu Search Plugin initializes automatically when the page is loaded. In case you need to trigger the initialization at a later point in time (e.g. you are creating the search field dynamically), you can call the init function to "restart" the plugin.

Usage example

ZOOVU_SEARCH.init();

Show search results

You don't have to rely only on our search field and search button bindings in order to be able to show search results. You can also call the showResults method from outside of the plugin to trigger the search.

Parameters

  • query:String - the search query

  • sort:String (optional) - the sorting to apply, default: undefined

  • pushState:Boolean (optional) - whether to push state to the window history, default: true

  • searchButton:Node (optional) - the search button that triggered the search (for tracking purposes), default: undefined

  • callback:Function (optional) - the callback to be executed after the search results have been rendered, default: undefined

Usage example

ZOOVU_SEARCH.showResults('pizza');

Open specific result group (tab)

If you're using result grouping, by default the search result page will open with the All results tab. If you want searchers to focus on a different result group instead (e.g. all queries coming from the News page should open the "News" tab first), you can use the openTab('') method. NB: This is different from limiting your results to a specific result group instead (hiding all other groups).

Usage example

ZOOVU_SEARCH.openTab('News')

Show fullscreen layer

If you are using the fullscreen search results, you can call the showFullscreenLayer method in order to make it slide down and show.

Usage example

ZOOVU_SEARCH.showFullscreenLayer();

Close search results

By calling the closeLayer method you can make the Search Plugin hide the rendered search result. This method only works for overlay or fullscreen integration.

Usage example

ZOOVU_SEARCH.closeLayer();

Hide search results

By calling the hideSearchResults method you can make the Search Plugin hide the rendered search result. This method is independent of the search result type.

Usage example

ZOOVU_SEARCH.hideSearchResults();

Show/hide loading animation

You can show or hide the (customized) Zoovu Search loader by calling showLoading(); or hideLoading();.

Helpers

Is Initialized?

In order to find out whether the Zoovu Search Plugin has been successfully initialized, you can call the isInitialized method.

Please note that a false return value does not have to mean that the search won't work - it only indicates that there was an error while initializing the plugin (e.g. the script is being embedded multiple times).

Returns

  • initialized:Boolean - flag indicating whether the initialization was successful

Usage example

var success=ZOOVU_SEARCH.isInitialized();