# Search

Source: https://zotonic.com/docs/1638/search

URI: https://zotonic.com/id/1638

Language: en

Query arguments and terms for searching pages using the search APIs.

Use <a href="/id/1844" class="doc-reference doc-reference-model"><code>model#search</code></a> and Zotonic's query language for ordinary content searches. Keep the query close to the page's actual task: filter by category, connection, or date, then choose an explicit sort order.

Use pagination for lists that can grow. Test with no results, one result, and enough results to reach the next page. Run the same search as a visitor to check publication and visibility behavior.

Before writing SQL, inspect existing query options and named queries. A custom query should preserve the same access rules as the page that displays it. See [Add a database query when models are not enough](/id/2956) and [Keep permission checks at the boundary](/id/1536).

For example, with `mod_search` enabled, show at most ten text resources:

```django
{% with m.search.query::%{cat: "text", sort: "-publication_start", pagelen: 10} as result %}
    <ul>
    {% for item in result %}
        <li><a href="{{ item.page_url }}">{{ item.title }}</a></li>
    {% empty %}
        <li>{_ No pages found. _}</li>
    {% endfor %}
    </ul>
{% endwith %}
```

This is a bounded preview, not a complete paginated archive. For an archive, pass the current page into the query and render <a href="/id/1396" class="doc-reference doc-reference-scomp"><code>scomp#pager</code></a> with the result and your listing route. Test the second page; raising `pagelen` is not pagination. The query reference in <a href="/id/1844" class="doc-reference doc-reference-model"><code>model#search</code></a> lists filters and result forms.

Start with the current resource-search task for a minimal query. The detailed term reference below is retained for existing links; use the installed search implementation when adding specialized terms.

:::::::: {.section}
Using the query search API you can retrieve lists of resources in various ways. In your templates, you do so through the <a class="reference internal" href="/id/1844"><span class="std std-ref">search model</span></a>:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="cp">{%</span> <span class="k">for</span> <span class="nv">id</span> <span class="k">in</span> <span class="nv">m.search</span><span class="o">[{</span><span class="nv">query</span> <span class="o">(</span><span class="nv">options</span> <span class="nv">go</span> <span class="nv">here</span><span class="p">...</span><span class="o">)</span> <span class="o">}]</span> <span class="cp">%}</span>
</pre>
:::
::::

For instance, to select all news items, ordered by their modification date, newest first:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="cp">{%</span> <span class="k">for</span> <span class="nv">id</span> <span class="k">in</span> <span class="nv">m.search</span><span class="o">[{</span><span class="nv">query</span> <span class="nv">cat</span><span class="o">=</span><span class="s1">'news'</span> <span class="nv">sort</span><span class="o">=</span><span class="s1">'-rsc.modified'</span><span class="o">}]</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">id</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre>
:::
::::

:::: {.section}
Trying it out
-------------

::: {.aside .admonition .note}
<p class="first admonition-title">Note</p>

<p class="last"><code class="docutils literal notranslate"><span class="pre">api/model/search/get</span></code> doesn’t automatically add sort terms, ensure to add <code>sort</code> terms to have a stable search result.</p>
:::

Of course you can create your own <code class="docutils literal notranslate"><span class="pre">for</span></code>-loop in a template, but there are easier ways to check out the inner workings of the query model: through your browser.

The query-model is exposed to the browser in via the API for receiving lists of ids in JSON.  For example, to get all resources of the “documentation” category on zotonic.com:

<a rel="nofollow noopener noreferrer" class="reference external" href="https://zotonic.com/api/model/search/get?qcat=documentation" target="_blank">https://zotonic.com/api/model/search/get?qcat=documentation</a>
::::

::::::: {.section}
Query arguments
---------------

::::: {.section}
### cat

Filter resources on a specific category:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">cat='news'</span>
</pre>
:::
::::

Specifying multiple ‘cat’ arguments will do an OR on the categories. So to select both news and person resources:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">cat='news' cat='person'</span>
</pre>
:::
::::
:::::

::::: {.section}
### cat\_exact

Filter resources to include the given category, but exclude any subcategory:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">cat_exact='news'</span>
</pre>
:::
::::
:::::

::::: {.section}
### cat\_exclude

Filter resources to exclude the given category:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">cat_exclude='meta'</span>
</pre>
:::
::::
:::::

::::: {.section}
### <span style="font-size:1.8rem; ">id_exclude</span>

Filter resources to exclude the ones with the given ids:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">id_exclude=123</span>
</pre>
:::
::::
:::::

::::: {.section}
### filter

Filtering on columns:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">filter=['pivot.title', 'Hello']</span>
<span class="x">filter=['pivot.mypivot.foo', 'bar']</span>
<span class="x">filter=['facet.somefacet', 'baz']</span>
</pre>
:::
::::

In its most simple form, this does an ‘equals’ compare filter. The <code class="docutils literal notranslate"><span class="pre">filter</span></code> keywords expects a list. If the list is two elements long, we expect the first column to be the filter column name from the database table, and the second column name to be the filter value:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">filter=['facet.numeric_value', 10]</span>
</pre>
:::
::::

If the filter is a three-column list, the second column is the operator. This must be an atom (surround it in backquotes!) and must be one of the following: <code class="docutils literal notranslate"><span class="pre">eq</span></code>, <code class="docutils literal notranslate"><span class="pre">ne</span></code>, <code class="docutils literal notranslate"><span class="pre">gt</span></code>, <code class="docutils literal notranslate"><span class="pre">gte</span></code>, <code class="docutils literal notranslate"><span class="pre">lt</span></code>, <code class="docutils literal notranslate"><span class="pre">lte</span></code>; or one of <code class="docutils literal notranslate"><span class="pre">=</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;&gt;</span></code>, <code class="docutils literal notranslate"><span class="pre">&gt;</span></code>, <code class="docutils literal notranslate"><span class="pre">&gt;=</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;=</span></code>:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">filter=['facet.numeric_value', `&gt;`, 10]</span>
</pre>
:::
::::

It is possible to define an OR query for multiple terms:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">filter=[ ['facet.numeric_value', `&gt;`, 10], ['facet.numeric_value', `&lt;=`, 0] ]</span>
</pre>
:::
::::
:::::

::::: {.section}
### hassubject

Select all resources that have an *incoming edge* from the given page, which is specified by the argument (the page id <code class="docutils literal notranslate"><span class="pre">123</span></code> in the example, or the unique page name <code class="docutils literal notranslate"><span class="pre">tag_gift</span></code>). Optionally, you can pass the name of a predicate as the second argument, to specify that the connection should have this predicate.

So, to select all resources that have an incoming edge from a subject with id <code class="docutils literal notranslate"><span class="pre">123</span></code>:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">hassubject=123</span>
</pre>
:::
::::

Alternatively, use the subject’s unique name:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">hassubject='tag_gift'</span>
</pre>
:::
::::

Specifying this multiple times does an AND of the conditions:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">hassubject=123</span>
<span class="x">hassubject=[123,'author']</span>
</pre>
:::
::::
:::::

::::: {.section}
### hasobject

Like <code class="docutils literal notranslate"><span class="pre">hassubject</span></code>, but selects all pages that have an **outgoing edge** to the given page, which is specified by the argument. Optionally, you can pass the name of a predicate as the second argument, to specify that the connection should have this predicate:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">hasobject=123</span>
<span class="x">hasobject='tag_gift'</span>
<span class="x">hasobject=[123,'hasdocument']</span>
</pre>
:::
::::
:::::

::::: {.section}
### hasanyobject

Like <code class="docutils literal notranslate"><span class="pre">hasobject</span></code>, but allows to define an OR operation on the edge. You can define multiple combinations of predicates and objects; any resource having such an outgoing edge will be matched. The argument is a list. Each element in the list is either an id or an id/predicate combination.

To select all resources that have an outgoing edge to an object with id 1, 2 or 3:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">hasanyobject=[1, 2, 3]</span>
</pre>
:::
::::

For each list element, you can add the connection’s predicate. So, to select all resources that have an outgoing ‘author’ edge to an object with id 123:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">hasanyobject=[[123, 'author']]</span>
</pre>
:::
::::

And to do the same but also include resources that have an ‘editor’ edge to an object with id 456:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">hasanyobject=[[123, 'author'], [456, 'editor']]</span>
</pre>
:::
::::

Substitute <code class="docutils literal notranslate"><span class="pre">'*'</span></code> for the object id to match *any* object. So, to select all resources that have any author or editor edge:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">hasanyobject=[['*', 'author'], ['*', 'editor']]</span>
</pre>
:::
::::

You can also mix the two types of elements. To select all resources that have an author or a connection (with any predicate) to resource 2 or 3:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">hasanyobject=[['*', 'author'], 2, 3]</span>
</pre>
:::
::::
:::::

::::: {.section}
### hasmedium

Only returns resources that have a <code class="docutils literal notranslate"><span class="pre">medium</span></code> record attached or only those that do not have a <code class="docutils literal notranslate"><span class="pre">medium</span></code> record attached.

For example:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">hasmedium</span>
</pre>
:::
::::

Return only resources with a medium record.

Or:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">hasmedium=false</span>
</pre>
:::
::::

Return only resources without a medium record.

The joined medium record is <cite>medium</cite>, that enables sorting on, for example, the medium record’s creation date with <code class="docutils literal notranslate"><span class="pre">sort=medium.created</span></code>.
:::::

::::: {.section}
### match\_objects

Find the resources that have similar object edges as the given resource. This is done using a full text query. The resource with most overlapping objects ids will be returned first:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">match_objects=1234</span>
</pre>
:::
::::

An <code class="docutils literal notranslate"><span class="pre">id_exclude=...</span></code> is automatically added for the resource in the argument.
:::::

::::: {.section}
### match\_object\_ids

Find the resources that have similar object edges to the given resources. This is done using a full text query. The resource with most overlapping objects ids will be returned first:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">match_object_ids=[108, 238, 1234]</span>
</pre>
:::
::::
:::::

::::: {.section}
### is\_authoritative

Boolean, filters whether a resource is considered authoritative (originating from this site) or not:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">is_authoritative</span>
</pre>
:::
::::
:::::

::::: {.section}
### is\_featured

A boolean option that specifies if a page should be featured or not:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">is_featured</span>
</pre>
:::
::::
:::::

::::: {.section}
### is\_published

Select published, unpublished or omit the publish check. Legal values are true, false or all:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">is_published='all'</span>
</pre>
:::
::::
:::::

:::::: {.section}
::::: {.section}
### is\_findable

Select resource that do not have the “Hide page from search results” set. This checkbox can be found in the *Advanced* panel of edit pages in the admin.

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">is_findable</span>
</pre>
:::
::::
:::::

::::: {.section}
### is\_unfindable

Select resource that do have the “Hide page from search results” set. This checkbox can be found in the *Advanced* panel of edit pages in the admin.

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">is_unfindable</span>
</pre>
:::
::::
:::::

### 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:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">upcoming</span>
</pre>
:::
::::
::::::

::::: {.section}
### ongoing

Specifying ‘ongoing’ means that you only want to select things that are happening now: that have a start date which lies in the past, and an end date which lies in the future:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">ongoing</span>
</pre>
:::
::::
:::::

::::: {.section}
### finished

Specifying ‘finished’ means that you only want to select things that have a end date which lies in the past:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">finished</span>
</pre>
:::
::::
:::::

::::: {.section}
### unfinished

Specifying ‘unfinished’ means that you only want to select things that have an end date which lies in the future:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">unfinished</span>
</pre>
:::
::::
:::::

::::: {.section}
### unfinished\_or\_nodate

Specifying ‘unfinished\_or\_nodate’ means that you only want to select things that have an end date which lies in the future or no start date:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">unfinished_or_nodate</span>
</pre>
:::
::::
:::::

::::: {.section}
### sort / asort / zsort

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 (<code class="docutils literal notranslate"><span class="pre">-</span></code>) in front of the field, the order is descending. Leaving this out or specifying a <code class="docutils literal notranslate"><span class="pre">+</span></code> means ascending.

The sort terms are added in the order: <code class="docutils literal notranslate"><span class="pre">asort</span></code>, <code class="docutils literal notranslate"><span class="pre">sort</span></code>, and <code class="docutils literal notranslate"><span class="pre">zsort</span></code>.

This is useful for e.g. text search. Text search will add a <code class="docutils literal notranslate"><span class="pre">sort</span></code> term on relevance. This relevance sort term is appended *after* any existing sort term. By using <code class="docutils literal notranslate"><span class="pre">zsort</span></code> you can force sub-sorting in case of the same relevance or no text for the query. Example:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">{query cat='news' text=q.qs zsort="-rsc.created"}</span>
</pre>
:::
::::

If <code class="docutils literal notranslate"><span class="pre">q.qs</span></code> is empty, this will return the newest *news* items. If <code class="docutils literal notranslate"><span class="pre">q.qs</span></code> is not empty then it will search for the text and return the best matches where equally matching news items will have the newest on top. Use <code class="docutils literal notranslate"><span class="pre">asort</span></code> instead of <code class="docutils literal notranslate"><span class="pre">zsort</span></code> to show the newest matching news, regardless on how well they match the search term:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">{query cat='news' text=q.qs asort="-rsc.created"}</span>
</pre>
:::
::::

Some sort fields:

<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">rsc.modified</span></code> - date of last modification</li>
<li><code class="docutils literal notranslate"><span class="pre">rsc.publication_start</span></code> - publication date</li>
<li><code class="docutils literal notranslate"><span class="pre">rsc.pivot_date_start</span></code> - the start date specified in the admin</li>
<li><code class="docutils literal notranslate"><span class="pre">rsc.pivot_date_end</span></code> - the end date specified in the admin</li>
<li><code class="docutils literal notranslate"><span class="pre">rsc.pivot_title</span></code> - the title of the page. For multilingual sites, the behavior of sorting on title is undefined.</li>
<li><code class="docutils literal notranslate"><span class="pre">seq</span></code> - sequence number of the first edge (ignored if no edge is joined)</li>
<li><code class="docutils literal notranslate"><span class="pre">edge.created</span></code> - creation date of the first edge (ignored if no edge is joined)</li>
</ul>

For all the sort fields, you will have to consult Zotonic’s data model. Example sorting on modification date, newest first:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">sort='-rsc.modified'</span>
</pre>
:::
::::

::: {.aside .admonition .seealso}
<p class="first admonition-title">See also</p>

<p class="last"><a class="reference internal" href="/id/1282#cookbook-pivot-templates"><span class="std std-ref">Pivot Templates</span></a></p>
:::
:::::

:::: {.section}
<a name="custompivot"></a>
### pivot.name

::: {.aside .admonition .seealso}
<p class="first admonition-title">See also</p>

<p class="last"><a class="reference internal" href="/id/1281#cookbook-custom-pivots"><span class="std std-ref">Custom pivots</span></a></p>
:::

Filter on the named pivot of the rsc table. The name is prefixed with <code class="docutils literal notranslate"><span class="pre">pivot_</span></code>.

Available pivot fields are:

<ul class="simple">
<li>pivot.category_nr,</li>
<li>pivot.first_name</li>
<li>pivot.surname</li>
<li>pivot.gender</li>
<li>pivot.date_start</li>
<li>pivot.date_end</li>
<li>pivot.date_start_month_day</li>
<li>pivot.date_end_month_day</li>
<li>pivot.street</li>
<li>pivot.city</li>
<li>pivot.state</li>
<li>pivot.postcode</li>
<li>pivot.country</li>
<li>pivot.geocode</li>
<li>pivot.title</li>
<li>pivot.location_lat</li>
<li>pivot.location_lng</li>
</ul>

These fields can also be used in <code class="docutils literal notranslate"><span class="pre">filter</span></code> and the <code class="docutils literal notranslate"><span class="pre">sort</span></code> terms.
::::

::: {.section}
### pivot.mypivot.name

Filter on the named pivot of the custom pivot <code class="docutils literal notranslate"><span class="pre">mypivot</span></code>.

Here <code class="docutils literal notranslate"><span class="pre">mypivot</span></code> is a custom pivot table defined with <code class="docutils literal notranslate"><span class="pre">z_pivot_rsc:define_custom_pivot/3</span></code>

Check the explanation and examples in <a class="reference internal" href="/id/1281#cookbook-custom-pivots"><span class="std std-ref">Custom pivots</span></a> for more information.

These fields can also be used in <code class="docutils literal notranslate"><span class="pre">filter</span></code> and the <code class="docutils literal notranslate"><span class="pre">sort</span></code> terms.
:::

::::: {.section}
### facet.name

Add a join with the facets table and filter on the named facet.

The facets table is filled from the <code class="docutils literal notranslate"><span class="pre">pivot/facet.tpl</span></code> template, each block is a facet that can be used for filters or for the <code class="docutils literal notranslate"><span class="pre">facets</span></code> query.

The <code class="docutils literal notranslate"><span class="pre">name</span></code> must be the name without types of a block. That is, if a block is called <code class="docutils literal notranslate"><span class="pre">foo_int</span></code> then the <code class="docutils literal notranslate"><span class="pre">name</span></code> is <code class="docutils literal notranslate"><span class="pre">foo</span></code> and the query term is <code class="docutils literal notranslate"><span class="pre">facet.foo</span></code>.

The value can be an operator:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">&gt;123</span>
<span class="x">&gt;=123</span>
<span class="x">&lt;123</span>
<span class="x">&lt;=123</span>
<span class="x">&lt;&gt;123</span>
</pre>
:::
::::

For example, the last one translates to the SQL clause <code class="docutils literal notranslate"><span class="pre">facet.name</span> <span class="pre">&lt;&gt;</span> <span class="pre">123</span></code>.

The facet fields can also be used in <code class="docutils literal notranslate"><span class="pre">filter</span></code> and the <code class="docutils literal notranslate"><span class="pre">sort</span></code> terms.
:::::

::::: {.section}
### hasobjectpredicate

Filter on all things which have any outgoing edge with the given predicate:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">hasobjectpredicate='hasdocument'</span>
</pre>
:::
::::
:::::

::::: {.section}
### hassubjectpredicate

Filter on all things which have any incoming edge with the given predicate:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">hassubjectpredicate='author'</span>
</pre>
:::
::::
:::::

::::: {.section}
### text

Perform a fulltext search on the primary “rsc” table. The result will automatically be ordered on the relevancy (rank) of the result:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">text="test"</span>
</pre>
:::
::::

Use prefix <code class="docutils literal notranslate"><span class="pre">id:</span></code> to find specific resources by id or name:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">text="id:1000"</span>

<span class="x">text="id:1000,1001,1002"</span>

<span class="x">text="id:category,1"</span>
</pre>
:::
::::
:::::

:::: {.section}
### query\_id

::: {.aside .admonition .seealso}
<p class="first admonition-title">See also</p>

<p class="last"><a class="reference internal" href="#guide-query-resources"><span class="std std-ref">Query resources</span></a></p>
:::

Load the query arguments from the saved <code class="docutils literal notranslate"><span class="pre">query</span></code> resource:

<code class="docutils literal notranslate"><span class="pre">query_id=331</span></code>
::::

::::: {.section}
### qargs

Take all the arguments from the current request and use these. The arguments have to start with a <code class="docutils literal notranslate"><span class="pre">q</span></code>, for example:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">http://example.com/search?qs=test&amp;qcat=text</span>
</pre>
:::
::::

With the query:

m.search.paged\[\{query qargs page=q.page pagelen=20\}\]

Will find all pages containing the string *test* in the category *text*.

As <code class="docutils literal notranslate"><span class="pre">qs</span></code> is the usual text search argument in forms it is mapped to <code class="docutils literal notranslate"><span class="pre">text</span></code>. All other arguments have the <code class="docutils literal notranslate"><span class="pre">q</span></code> removed and should map to known query-model arguments.
:::::

::: {.section}
### publication\_month

Filter on month of publication date

<code class="docutils literal notranslate"><span class="pre">publication_month=9</span></code>
:::

::: {.section}
### publication\_year

Filter on year of publication date

<code class="docutils literal notranslate"><span class="pre">publication_year=2012</span></code>
:::

::: {.section}
### publication\_after

Filter resources to only show those that are published on or after the given date.

### publication\_before

Filter resources to only show those published on or before the given date.

### date\_start\_after

Select items with a start date greater than given value

<code class="docutils literal notranslate"><span class="pre">date_start_after="2010-01-15"</span></code>

It also possible to use relative times:

<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">now</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">+0</span> <span class="pre">sunday</span></code> (last sunday or the current sunday)</li>
<li><code class="docutils literal notranslate"><span class="pre">+0</span> <span class="pre">monday</span></code> (last monday or the current monday)</li>
<li><code class="docutils literal notranslate"><span class="pre">+1</span> <span class="pre">minute</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">+1</span> <span class="pre">hour</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">+1</span> <span class="pre">day</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">+1</span> <span class="pre">week</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">+1</span> <span class="pre">month</span></code></li>
<li><code class="docutils literal notranslate"><span class="pre">+1</span> <span class="pre">year</span></code></li>
</ul>

Negative offsets are allowed as well. There //must// be a <code class="docutils literal notranslate"><span class="pre">+</span></code> or <code class="docutils literal notranslate"><span class="pre">-</span></code> sign.
:::

::::: {.section}
### date\_start\_before

Select items with a start date smaller than given value:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">date_start_before="2010-01-15"</span>
</pre>
:::
::::
:::::

::::: {.section}
### date\_start\_year

Select items with an “event start date” in the given year:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">date_start_year=2012</span>
</pre>
:::
::::
:::::

::::: {.section}
### date\_end\_after

Select items with a end date greater than given value:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">date_end_after="2010-01-15"</span>
</pre>
:::
::::
:::::

::::: {.section}
### date\_end\_before

Select items with a end date smaller than given value:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">date_end_before="2010-01-15"</span>
</pre>
:::
::::
:::::

::::: {.section}
### date\_end\_year

Select items with an “event end date” in the given year:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">date_end_year=2012</span>
</pre>
:::
::::
:::::

::::: {.section}
### created\_after

Filter resources to only show those that are created on or after the given date.

### created\_before

Filter resources to only show those created on or before the given date.

### modified\_after

Filter resources to only show those that are modified on or after the given date.

### modified\_before

Filter resources to only show those modified on or before the given date.

### content\_group

Select items which are member of the given content group (or one of its children):

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">content_group=public</span>
</pre>
:::
::::
:::::

::::: {.section}
### name

Find resources with a matching unique name. A wildcard can be defined, for example:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">name=page_*</span>
</pre>
:::
::::

Searching on an empty name or just <code class="docutils literal notranslate"><span class="pre">*</span></code> will return all resources with a defined name. The given name will be trimmed and converted to lowercase before searching.
:::::

::::: {.section}
### language

Find resources with a certain language. The language must be a language code recognized by Zotonic, including supported regional variants. Search terms with invalid language codes are ignored.

Find all resources with a German translation:

:::: {.highlight-django .notranslate}
::: {.highlight}
<pre><span class="x">language=de</span>
</pre>
:::
::::
:::::
:::::::

::: {.section}
Filter behaviour
----------------

Separate ordinary terms normally combine with AND. Some terms explicitly support OR lists, including `filter` and `hasanyobject`. The <code class="docutils literal notranslate"><span class="pre">cat=</span></code> filter: if you specify multiple categories, those categories are “OR“‘ed together, to allow to search in multiple distinct categories with a single search query.
:::

:::: {.section}
<a name="guide-query-resources"></a>
Query resources
---------------

::: {.aside .admonition .seealso}
<p class="first admonition-title">See also</p>

<ul class="last simple">
<li><a class="reference internal" href="/id/2060"><span class="std std-ref">mod_search</span></a> reference: Zotonic’s built-in search module.</li>


</ul>
:::

Query resources are, as the name implies, <a class="reference internal" href="/id/1276#guide-datamodel-resources"><span class="std std-ref">Resources</span></a> of the special category <cite>query</cite>. In the admin this category is called “search query”. it is basically a stored (and thus content manageable) search query. You create an editable search query in an admin page that then is invoked from a template.

When creating such a resource in the page, you will see on the admin edit page an extra text field in which you can add search terms. Each search term goes on its own line, and the possible search terms are equal to the ones described on this page (the <cite>Query-model arguments</cite>).
::::
::::::::

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/1638?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/1638?language=en>)
