Template Tags
Searching is currently limited to a single index for either provider. Algolia supports searching multiple indexes out of the box, but Meilisearch does not, and requires additional steps to support multi-index searching. Thus, for the time being, searching is limited to 1 index if using the EE template tag.
The search template tags are intended for simple queries and results display. If you need users to be able to select multiple facets to filter the result set dynamically, like you're used to seeing on ecommerce sites such as Zappos, we highly recommend using a JavaScript based search component.
Due to the complex nature of the search parameters, they are not defined as native EE tag parameters. There will be too many parsing issues. For this reason Dexter looks for a specific search_filters
tag pair and uses the contents of that tag as the search filter.
Meilisearch
For more information on how to use the search filter refer to the Meilisearch docs.
The contents of the search_filters
tag pair must be a valid JSON object.
{exp:dexter:search index="test_people" term="luke skywalker"}
{search_filters}
{
"limit": 1,
"offset": 0,
"filter": [
"status = 'open'",
"entry_date >= 1732312020"
],
"sort": [
"entry_date:asc"
]
}
{/search_filters}
{if no_results}
Nope
{/if}
{title}
{ansel}
{url}
{/ansel}
{/exp:dexter:search}
Algolia
For more information on how to use the search filter refer to the Algolia search docs.
{exp:dexter:search index="test_people" term="luke skywalker" per_page="10"}
{search_filters}
status:open AND entry_date >= 1732312020
{/search_filters}
{if no_results}
Nope
{/if}
{title}
{ansel}
{url}
{/ansel}
{/exp:dexter:search}
Using channel:entries to display results
If the dexter:search
tag is not rendering as you expect, perhaps because of how the data is structured in the index (a deeply nested object will not work with the EE template parser), you can use the entry_ids_only
parameter on the tag, and the {entry_ids}
variable will print a pipe delimited list of entry IDs that you can then use in achannel:entries
tag, then you have access to anything and everything related to the entry. This is a perfectly viable approach - let a powerful search engine do the hard work and return a small set of IDs, which you can then use to display the result.
If you are not using the entry_ids_only
parameter, remember that the variables in the result are the properties you have indexed in Algolia or Meliesearch, so it may not align exactly with what you normally expect to see in a channel:entries
tag result.
{exp:dexter:search index="test_people" term="luke" entry_ids_only="yes"}
{search_filters}
{
"limit": 1,
"offset": 0,
"filter": [
"status = 'open'",
"entry_date >= 1732312020"
]
}
{/search_filters}
{exp:channel:entries entry_id="{entry_ids}"}
{title}
{/exp:channel:entries}
{/exp:dexter:search}
Coilpack Support
If you're using Coilpack you can also use Twig or Blade templates to render results. The search_filters
parameter is handled as a normal tag parameter since you don't run into template parsing issues using Twig or Blade. Here is an example of the same search tags in Twig.
{% set search = exp.dexter.search({
index: 'test_people',
term: 'luke',
search_filters: {
limit: 1,
offset: 0,
filter: '["status = \'open\'", "entry_date >= 1732312020"]'
}
}) %}
{% for result in search %}
{{ result.title }}
{% endfor %}
{% set entryIds = exp.dexter.search({
index: 'test_people',
search_filters: {
limit: 10,
offset: 0,
},
entry_ids_only: true
}) %}
{{ entryIds }}
Template Variables
Dexter creates a couple of global template variables to assist searching.
{dexter_env}
Will print out the env
config value. You can use this in your templates to keep local sites using a test
index, and production using prod
{dexter_suffix}
Will print out the suffix
config value, which is blank by default. This can be used for multiple purposes, but the most applicable is appending a langauge code to an index to keep multilingual content into it's own index.
An example usage of these variables might look like this:
{exp:dexter:search index="{dexter_env}_support_{dexter_suffix}"}
Last updated
Was this helpful?