Search Tag

This is how you do search. This is the tag you're looking for.

Overview

An overview on how to configure search, indexing, and the query form can be found in the Search Docs.

Example

On a search result page, you can loop through the results of the search like they were entries. You’ll have access to all the data of all the content of your search results returned so you can format them any way you wish.

{{ search:results }}

  {{ if no_results }}
    <h2>No results.</h2>
  {{ else }}

    <a href="{{ url }}" class="result">
      <h2>{{ title }}</h2>
      <p>{{ content | truncate:240 }}</p>
    </a>

  {{ /if }}

{{ /search:results }}

Search Forms

The search form itself — that text box users type into, is a normal, every day HTML form with a search input that submits to a URL containing a search:results tag in the template. Nice and simple.

<form action="/search/results">
    <input type="search" name="q" placeholder="Search">
    <button type="submit">Make it so!</button>
</form>

Parameters

index string

The search index to query. Default: default.

query string

The query string parameter used for the search term. Default: q.

limit integer

Limit the total results returned.

offset integer

Skip the first n number of results.

supplement_data string

When true will include all non-indexed content field. Disabling may result in performance increases with the trade-off that only indexed fields will be available. Default: true.

Variables

Variable Type Description

no_results

boolean

If there are no results.

first

boolean

If this is the first item in the loop.

last

boolean

If this is the last item in the loop.

count

integer

The number of current iteration in the loop.

index

integer

The zero-based count of the current iteration in the loop.

total_results

integer

The number of results in the loop.

search_score

float

The internal relevance score that Statamic given to this result. Helpful for debugging, but useless to the public. Only applies when using the local driver.

is_entry

boolean

Whether the current item is an entry.

is_term

boolean

Whether the current item is a taxonomy term.

_highlightResult

array

Available when using the Algolia driver. Displays a field with the search term automatically highlighted. Example: {{ _highlightResult:myfield:value }}

Betterify this page on Github!