search_results

Table of contents

A block where the search results of the passed search query are available. Expects one argument, which is the search query.

The following variables are available within the block:

  • search_results: An array of Posts that match the search query.

Use request.query_object to use a search term passed as a URL parameter.

The block accepts the following extra optional parameters:

  • size, e.g. size: 50. The maximum search results, so the request load time can be limited, even when there is a very large amount of search results. Default: 100.

  • filter_by_language. If true only search results for the current language are returned. If  only search results for the current language are returned. If  only search results for the current language are returnedThe search results will be filtered by the current language by default, so you don't have to specify this parameter.

  • filters: refine search results by specifying conditions that must be met by the returned data. This parameter allows structured filtering based on field values, operators, and conditions.

{% search_results "<search query>" %}

  {% for post in search_results %}
    <h3><a href="{{ post.url }}">{{ post.title }}</a></h3>
    <hr>
  {% endfor %}

{% endsearch_results %}
Liquid Search block

Search weights

Default weight value:
  • post title: 4
  • post slug: 3
  • post SEO Title/Description: 2
  • post body content: 1

The importance of a content field ranges from 1 to 5. Set it to 5 if you consider this field the most important.

Customize search weights

You can specify the following weight parameters:

  • title_weight
  • slug_weight
  • seo_title_weight
  • seo_description_weight
  • post_body_content_weight
Excluding Search Body Content

If you do not want to include post_body_content in the search, set exclude_body_content to true.

Ngram Search

Ngram (partial word) search will be enabled for title, SEO fields, slug, and body content if the search keyword is 10 characters or fewer. The importance of ngrams for these fields will be 0.6 times the importance of the respective field.

{% search_results "test", title_weight: 2, exclude_body_content: true %}
 ....
{% endsearch_results %}

Filters

{%- capture plateFilters -%}
  [
    { 
      "field": "post.title",
      "operator": "=",
      "value": "Test"
    },
    {
      "field": post.slug",
      "opeartors": "in",
      "value": ["test", "dev-test"]
    }
  ]
{%- endcapture -%}
{% search_results "cms", filters: plateFilters %}
 ....
{% endsearch_results %}
Filters Parameter:

The filters parameter accepts an array of filter objects, where each object contains the following attributes:

  • field (string): Specifies the data field to be filtered. It should be a valid field path within the data structure.
  • operator (string): Defines the comparison operation to apply. Supported operators include:
    • =: Equals
    • !=: Not equal
    • >: Greater than
    • <: Less than
    • >=: Greater than or equal to
    • <=: Less than or equal to
    • in: Matches any value within a given list
    • not_in: Excludes values within a given list
    • exists: Checks if a field exists
    • not_exists: Checks if a field does not exist
    • contains: Checks if a field contains a specified substring
    • not_contains: Checks if a field does not contain a specified substring
  • value (varied type): Specifies the value to compare against the field. The data type should match the field’s expected type (e.g., string, number, boolean, or array for in/not_in).
Operators example

{ "field": "post.author.name", "operator": "=", "value": "David" }
{ "field": "post.author.name", "operator": "!=", "value": "David" }
{ "field": "post.year", "operator": ">", "value": 1990 }
{ "field": "post.year", "operator": "<", "value": 2000 }
{ "field": "post.year", "operator": ">=", "value": 1990 }
{ "field": "post.year", "operator": "<=", "value": 2000 }
{ "field": "post.tags", "operator": "in", "value": ["tag1", "tag2"] }
{ "field": "post.tags", "operator": "not_in", "value": ["tag1"] }
{ "field": "post.author.name", "operator": "exists", "value": true }
{ "field": "post.author.name", "operator": "not_exists", "value": true }
{ "field": "post.author.name", "operator": "contains", "value": "delta" }
{ "field": "post.author.name", "operator": "not_contains", "value": "delta" }
Usage Considerations 

  • Ensure that field names match the structure of the dataset. 
  • Use appropriate data types for value to prevent mismatches. 
  • Combining multiple filters will result in an AND operation; ensure filters are structured correctly for the desired logic.
  •  Use debug search in the dashboard to analyze query, troubleshoot filter conditions, and ensure expected results are returned.

Need help?

Do you have any question which is not answered in this knowledge base? Contact us. We are here to help you.