Searching CMS Objects

Searching CMS Objects

You can search for CMS objects using JavaScript by means of the following function:

The parameters are similar to those of the BasicObj.where ruby method. The function returns a chainable search query object for which the following chainable functions are available:

To actually retrieve the search results, call the following function of a query object:

The function returns a Promise. The Promise resolves to the result and next parameters.

result is an object that has two keys, total and hits: total is a number representing the total number of available search hits. hits is an array containing the actual search hits, the IDs of the CMS objects:

Note that load_batch retrieves at most batch_size items. It may also return fewer items, even if the search is not yet exhausted. This happens, for example, if the request exceeds the rate limit.

If the search is exhausted (i.e. all search hits have been retrieved), next is undefined. Otherwise, next is another chainable search query object whose offset specifies the number of hits that can be skipped since they have already been retrieved.

Example usage:

You may also use size instead of load_batch if you are merely interested in the total number of hits:

The search query object provides a chainable method, format, for specifying the formatter to be used. If a formatter is given, the hits returned are formatted accordingly.

The formatter needs to be defined in your application. The recommended location is config/initializers/scrivito.rb:

A search example in which the formatter above is used:

If no formatter is specified, only the IDs of the CMS objects are returned.