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 |
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:
Where
|
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
|
fragments
If you specify a |
isFirstPage
|
isLastPage
|
nextPage
The number of the next page in the result set, or |
nextPageUrl
The URL of the next page in the result set, or |
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 |
previousPage
The number of the previous page in the result set, or |
previousPageUrl
The URL of the previous page in the result set, or |
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
|
total
The total number of matching results for the search across all pages. |
totalPages
The total number of pages available in the result set. |