The Query search-model
Using the query search API you can generate lists of pages in various ways.
The query search-model is a powerful search model that accepts a lot of options. This page documents those options.
You access the query model in the following way:
{% for id in m.search[{query (options go here...) }] %}For instance, to select all news items, ordered by their modification date, newest first:
{% for id in m.search[{query cat='news' sort='-rsc.modified'}] %}
{{ id }}
{% endfor %}Trying it out
Ofcourse you can create your own for-loop in a template, but there are more easier ways to check out the inner workings of the query-model: through your browser.
The queyr-model is exposed to the browser in (currently) 2 URLs: the Atom feed module for creating a customized update feed, and the API for receiving lists of ids in JSON.
Get all "documentation" pages of zotonic.com:
http://zotonic.com/api/search?cat=documentation
Get a feed of most recent documentation containg the word "filter":
http://zotonic.com/feed/search?cat=documentation&text=filter
Note that mod_atom_feed automatically appends a sorting on last-modified date, something which api/search does not do.
All query-model arguments
| Argument | Description | Example |
| authoritative | Boolean, filters whether a page is considered "authoritative" (belonging on this site) or not. | authoritative=1 |
| cat | Filter pages on a specific category. Specifying multiple 'cat' arguments will do an "or" on the categories. | cat='news' |
| cat_exclude | Filter pages to exclude the given category. | cat_exclude='meta' |
| hassubject | Select all pages that have an outgoing connection to the given page, which is specified by the argument (123 in the example). Optionally, you can give the name of a predicate as second argument, to specify that the connection should have this predicate. Specifying this multiple times does an "or" of the conditions. | hassubject=123 hassubject=[123,'author'] |
| hasobject | Like hassubject, but selects all pages that have an incoming connection to the given page, which is specified by the argument. Optionally, you can give the name of a predicate as second argument, to specify that the connection should have this predicate. | hasobject=123 |
| is_featured | A boolean option that specifies if a page should be featured or not. | is_featured |
| is_published | Select published, unpublished or omit the publish check. Legal values are true,false or all. | is_published='all' |
| is_public | Filter on whether an item is publicly visible or not. Valid values are 'true', 'false', 'all'. | is_public='false' |
| upcoming | Specifying 'upcoming' means that you only want to select things that have a start date which lies in the future. Like the name says, useful to select upcoming events. | upcoming |
| sort | Sort the result on a field. The name of the field is a string which directly refers to the sql-join that is being used. If you specify a dash ("-") in front of the field, the order is descending. Leaving this out or specifying a "+" means ascending. Some sort fields:
| sort='-rsc.modified' |
| custompivot | Add a join on the given custom pivot table. The table is joined to the primary "rsc" table. The alias | custompivot=foo (add pivot_foo to join) |
| hasobjectpredicate | Filter on all things which have any outgoing edge with given predicate. | hasobjectpredicate='document' |
| hassubjectpredicate | Filter on all things which have any incoming edge with given predicate. | hasobject='author' |
| text | Perform a fulltext search on the primary "rsc" table. The result will automatically be ordered on the relevancy (rank) of the result. | text="test" |
| query_id | Load the query arguments from the saved 'query' resource. | query_id=331 |
| publication_month | Filter on month of publication date | |
| publication_year | Filter on year of publication date | |
| date_start_after | Select items with a start date greater than given value | date_start_after="2010-01-01" |
| date_start_before | Select items with a start date smaller than given value | date_start_before="2010-01-01" |
| date_start_year | Select items with a "event start date" in the given year. | date_start_year=2012 |
| date_end_year | Select items with a "event end date" in the given year. | date_end_year=2012 |
This page is part of the Zotonic documentation, which is licensed under the Apache License 2.0.