Skip to main content

search

Information about a storefront search query.

To learn about storefront search and how to include it in your theme, refer to Storefront search.

Properties

Anchor to
default_sort_by

The default sort order of the search results, which is relevance.

Anchor to
filters
array of filter

The filters that have been set up on the search page.

Only filters that are relevant to the current search results are returned. If the search results contain more than 1000 products, then the array will be empty.

Tip

To learn about how to set up filters in the admin, visit the Shopify Help Center.

Returns true if a search was successfully performed. Returns false if not.

Anchor to
results

The search result items.

An item can be an article, a page, or a product.

Tip

Use the paginate tag to choose how many results to show per page, up to a limit of 50.

Example
Search result object_type

Search results have an additional object_type property that returns the object type of the result.

{% for item in search.results %}
<!-- Result {{ forloop.index }}-->
<h3>
{{ item.title | link_to: item.url }}
</h3>

{% if item.object_type == 'article' -%}
{%- comment -%}
'item' is an article
All article object properties can be accessed.
{%- endcomment -%}

{% if item.image -%}
<div class="result-image">
<a href="{{ item.url }}" title="{{ item.title | escape }}">
{{ item | image_url: width: 100 | image_tag }}
</a>
</div>
{% endif %}
{%- elsif item.object_type == 'page' -%}
{%- comment -%}
'item' is a page.
All page object properties can be accessed.
{%- endcomment -%}
{%- else -%}
{%- comment -%}
'item' is a product.
All product object properties can be accessed.
{%- endcomment -%}

{%- if item.featured_image -%}
<div class="result-image">
<a href="{{ item.url }}" title="{{ item.title | escape }}">
{{ item.featured_image | image_url: width: 100 | image_tag }}
</a>
</div>
{% endif %}
{%- endif -%}

<span>{{ item.content | strip_html | truncatewords: 40 | highlight: search.terms }}</span>
{% endfor %}

Output


Anchor to
results_count

The number of results.

Anchor to
sort_by

The sort order of the search results. This is determined by the sort_by URL parameter.

If there's no sort_by URL parameter, then the value is nil.

Anchor to
sort_options
array of sort_option

The available sorting options for the search results.

Example
Output the sort options
{%- assign sort_by = search.sort_by | default: search.default_sort_by -%}

<select>
{%- for option in search.sort_options %}
<option
value="{{ option.value }}"
{%- if option.value == sort_by %}
selected="selected"
{%- endif %}
>
{{ option.name }}
</option>
{% endfor -%}
</select>

Output


The entered search terms.

Tip

Use the highlight filter to highlight the search terms in search result content.

Anchor to
types
array of string

The object types that the search was performed on.

A search can be performed on the following object types:

Note

The types are determined by the type query parameter.

{
"default_sort_by": "relevance",
"filters": {},
"performed": true,
"results": [],
"results_count": 16,
"sort_by": "relevance",
"sort_options": [],
"terms": "potion",
"types": [
"article",
"page",
"product"
]
}
Was this section helpful?