Page Search Ajax API

GET /page/search.json

Query searchable Page objects via Ajax returned as JSON.

For familiarity we have tried to ensure consistency in terminology with PageSearch and Pagination objects.

Example using JQuery


    jQuery.getJSON('/page/search.json', function(returnValue) {
        console.log(returnValue);
    } );

Internationalisation

If your website has multiple languages you will want to ensure search results are returned in the language, country and currency of your locales. To achieve this you can localise the URL as follows.

In your EVML view file:


<div id="myDiv" data-url="@/page/search.json"></div>

Within your view's JavaScript file:


    var myDiv = jQuery('#myDiv');
    jQuery.getJSON(myDiv.attr('data-url'), function(returnValue) {
        console.log(returnValue);
    } );

With the code above it won't matter which locale you visit the URL and results will be correct.

Accepted Parameters

The search script allows you to define the following optional parameters.

fragment

An EVML include/partial to render per result. You may supply one fragment to render only. The fragment path should be supplied in the format controller/filename. For example the file page/page.partial.evml may be available. This may be supplied as /page/search.json?fragment=page/page.partial

id

The numeric system ID for the page is an optional parameter that allows you to search within the descendants of a given page. This may be supplied as a query string parameter or in the following format:


<div id="myDiv" data-url="@/page/[id]/search.json"></div>

Where [id] is replaced with a Page's system ID e.g.:


<div id="myDiv" data-url="@/page/{{ page.id }}/search.json"></div>
orderBy

Column and direction to sort results. Adheres to orderable values of PageSearch.orderBy(). Defaults to 'title:asc'.

page

The page of results to return.

perPage

The number of results to show per page. Defaults to 10.

q

Define a search string.



Returned Object

The search script returns an object with the following properties.

code

200 if the request was successful, or 400 if the request was bad.

fragments

If you specify a fragment parameter a fragments property will be available containing the rendered partial per result. This is an ideal way of quickly building HTML from your Ajax queries using the Theme engine rather than through JavaScript. Note that the fragment parameter supplied must be a legitimate page partial/include. Each page in the result set is supplied to the fragment file as a fully qualified Page Object within a page variable.

isFirstPage

TRUE if the current page is the first in the result set, else FALSE.

isLastPage

TRUE if the current page is the last in the result set, else FALSE.

nextPage

The number of the next page in the result set, or NULL if there isn't a next page.

nextPageUrl

The URL of the next page in the result set, or NULL if there isn't a next page.

orderBy

The sort order of the results. Adheres to orderable values of PageSearch.orderBy().

page

The number of the current page (starts at 1 for first page).

perPage

The number of results returned per page.

phrase

The search phrase supplied by the q parameter.

previousPage

The number of the previous page in the result set, or NULL if there isn't a previous page.

previousPageUrl

The URL of the previous page in the result set, or NULL if there isn't a previous page.

results

A JSON array with each element (if any) containing an flattended representation of a Page object. Note that only basic settings may be available by comparison to the full Page Object.

success

TRUE if the request was successful, or FALSE if not.

total

The total number of matching results for the search across all pages.

totalPages

The total number of pages available in the result set.