The search object
The search
object has the following attributes:
search.default_sort_by
Anchor link to section titled "search.default_sort_by"Returns relevance
, which is the default search sort order.
search.filters
Anchor link to section titled "search.filters"Returns an array of filter objects that have been set up on the search page.
Only returns filters relevant to the current search results. Filters will be empty for search results that contain over 1000 products.
search.performed
Anchor link to section titled "search.performed"Returns true
if an HTML form with the attribute action="/search"
was submitted successfully. This allows you to show content based on whether a search was performed.
search.results
Anchor link to section titled "search.results"Returns an array of matching search result items. The items in the array can be a(n):
You can access the attributes of individual search results by looping through search.results
.
Search result object_type
Anchor link to section titled "Search result object_type"Search results have an additional object_type
attribute which returns the type of each result. This is useful for identifying result types when outputting results.
search.results_count
Anchor link to section titled "search.results_count"Returns the number of results found.
search.sort_by
Anchor link to section titled "search.sort_by"Returns the sort order applied to the search query by the sort_by
URL parameter. If there's no sort_by
URL parameter, then the default value is relevance
.
For example, given the following URL, the following input would lead to the following output:
search.sort_options
Anchor link to section titled "search.sort_options"Returns an array of sorting options for the search query.
For example, the following input would lead to the following output:
Each option has the following attributes:
option.name
Anchor link to section titled "option.name"The customer-facing label for the sort option, which can be edited by merchants in the language editor.
option.value
Anchor link to section titled "option.value"The value of the sort option to be assigned to the sort_by
property in a form submission.
search.terms
Anchor link to section titled "search.terms"Returns the string that was entered in the search input box.
Use the liquid highlight filter to apply a different style to any instances in the search results that match up with search.terms
. For example:
search.types
Anchor link to section titled "search.types"Returns an array of strings representing the types that the search was performed on. The items in the array can be any combination of article
, page
, product
.
The search types can be seen in the URL parameters of the search page. For example, given the following URL, the following input would lead to the following output: