/search.json

Query searchable Page, Product and Categoryobjects via Ajax returned as JSON in a comabined stream. You should be aware that data returned within this facility may not be as detailed as data returned within specific object search facilities.

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

Example using JQuery


    jQuery.getJSON('/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="@/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. This may be supplied as /search.json?fragment=search/result.partial

sort

Column and direction to sort results. Adheres to orderable values of Search.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 partial/include.

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 Search.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 SearchResult object. Note that only basic settings may be available by comparison to the full Objects.

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.




COVID-19 NOTICE – Business as Usual
Evance continues to provide all services and support throughout this difficult period. See our full statement here .