Description

The query directive constructs a query string and stores it in a scoped variable, Query Filter’s can be added to add or remove filters from the query. You can also use the Query Custom Tag to add custom parameters to the query.

Usage

as element:
<search:query
       var="{string}"
       parameters="{string}"
       [from="{string}"]
       [query="{string}"]
       [modified-query="{string}"]
       [type="{string}"]
       [results-per-page="{string}"]
       [max-results="{string}"]
       [page="{string}"]
       [facets="{string}"]
       [fields="{string}"]
       [sorts="{string}"]
       [view="{string}"]
       [filters="{string}"]
       [collection="{string}"]
       [custom="{string}"]>
</search:query>

Directive info

  • This directive creates new scope.

Parameters

ParamTypeDetails
varstringThe variable to assign the query to
parametersstringThe URL parameters to query with.
from (optional)stringName of a previously defined query to extend
query (optional)stringSet the search query value.
modified-query (optional)stringSpecify an alternative query which will be submitted to the search engine in place of the query parameter supplied by the user (but can include user submitted parameter). To the user it will appear as the query parameter had been used, but the modifiedQuery will be submitted to the search engine.
type (optional)stringSpecifies how to interpret multiple query terms. Takes one of three values: any (boolean OR the terms), all (boolean OR/AND the terms), or adv (interpret using search platform-specific advanced query language).
results-per-page (optional)stringThe number of results to display per page.
max-results (optional)stringThe maximum number of results to evaluate. Defaults to -1 which means no upper limit.
page (optional)stringSet the page of results to display. Default value is 1
facets (optional)stringSpecifies which facets to evaluate and return.
fields (optional)stringA comma-separated list of fields which should be returned in the Response.
sorts (optional)stringSpecifies fields and order for sorting. Sort order is specified by one of two characters: + for ascending and - for descending. To sort ascending by the field price, the sort would be specified as sorts=“+price”.
view (optional)stringSet which search engine view to use. Behaviour will vary by installation.
filters (optional)stringSpecifies filters to apply, specified as an ampersand (&) separated String
collection (optional)stringSpecifies the collection you want to use.
custom (optional)stringSpecifies custom parameters to apply, specified as an ampersand (&) separated String

Example

Source

<search:query var="query" filters='zipcode["75216"]["75216"],bar["foo"]["foo"]' max-results="1">
    <query:filter field="foo" value="bar"></query:filter>
    <query:custom name="foo" value="bar"></query:custom>
</search:query>
<search:query var="copyQuery" from="query"></search:query>

<div ng-if="query != null">
    <code>Original - {{query | setQueryParameter:'q':'foo'}}</code>
</div>
<code>Copy - {{copyQuery}}</code>
angular.module('lightning')
.controller('ExampleController', ['$scope','$timeout', function($scope,$timeout) {
        }]);

angular
.module('lightning')
.filter('setQueryParameter', setQueryParameter);

setQueryParameter.$inject = ['$timeout'];

function setQueryParameter($timeout) {
        return function (query, parameter, value) {
                if (query && parameter && value) {
                    query[parameter] = value;
                    return query;
                } else {
                    return query
                }
        };
    }

Result

Result