# 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.

{% hint style="info" %}
**BoldMinded can not offer support on how to construct queries.** Filtering can be very complex and as you can see in the example below each provider has a unique syntax. We have added support for both, so long as you construct the query correctly and have properly set the fields in the respective providers to be filterable or faceted fields (the most common mistake is querying a field that is not set to be filterable). If you are experiencing an issue, check your ExpressionEngine developer logs.
{% endhint %}

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](https://www.zappos.com/mens-shoes), we highly recommend using a JavaScript based search component.

#### Aliased Parameters

For the sake of consistency, and flexibility, the 2 most commonly used parameter names have aliases. In the Meilisearch or Algolia docs you may see references to `query` or q`.` You can use whichever you want, or even use `term`. They all map to the correct value depending on the chosen search provider.

Similarly, the `index`, `indexName`, and `indexUid` act the same way. Choose whichever you prefer.

#### Searching

For more information on how to use the search params refer to the [Meilisearch docs](https://www.meilisearch.com/docs/reference/api/search#filter) or [Algolia search docs](https://www.algolia.com/doc/rest-api/search/#tag/Search/operation/search). `searchParams` is used for any additional query parameters. E.g. `facets`, `aroundLatLng`, etc when used in the single index search.

```twig
{% set results = craft.dexter.search({
    index: 'demo_collections',
    searchParams: {},
    perPage: 50,
}) %}

{% if results %}
    <ul>
        {% for result in results %}
            <li>{{ result.title }}</li>
        {% endfor %}
    </ul>
{% else %}
    <p>No results found.</p>
{% endif %}
```

#### Searching Multiple Indices

When performing a `multiSearch` you will need to refer to the documentation of your chosen search provider for exact parameter names and values to properly construct the `queries` array. The `federation` parameter is specific to Meilisearch, but Dexter also recognizes it for Algolia, and applies all the parmeter options from the `federation` object to each query. In the example below instead of repeating `q: 'van gogh'` you an add it to the `federation` object once.

```twig
{% set results = craft.dexter.multiSearch({
    federation: {
        limit: 10,
    },
    queries: [
        {
            index: 'demo_collections',
            q: 'van gogh'
        },
        {
            index: 'demo_images',
            q: 'van gogh'
        }
    ]
})
%}
```

{% hint style="info" %}
There are differences in how each provider handles search parameters and faceting. We can't provide all examples or support querying. For example, the `perPage` parameter is unique to Algolia. Use the `limit` parameter as noted above for Meilisearch. Also note in the Meilisearch example you can sort the results at run time by adding the sort filter. Algolia does not support similar functionality. You would need to add dateCreated as a `sortableAttribute` , then add to the `ranking` setting  `asc(`dateCreated`)`.  If you export the Algolia index settings with Dexter you should see the `sortableAttributes` and `ranking` attributes in the json file.

```json
"sortableAttributes": [
    "dateCreated"
]
"ranking": [
    "desc(entry_date)",
    "typo",
    "geo",
    "words",
    "filters",
    "proximity",
    "attribute",
    "exactness"
 ],
```

{% endhint %}

#### Using craft.entries to display results

If the `craft.dexter.search` tag is not rendering as you expect, perhaps because of how the data is structured in the index, you can use the `idsOnly` parameter to set an ids variable to filter the `craft.entries` tag with, 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 `idsOnly` parameter, remember that the variables in the result are the properties you have indexed in Algolia or Meilisearch, so it may not align exactly with what you normally expect to see in a `craft.entries` result.

```twig
{% set ids = craft.dexter.search({
    index: 'demo_collections',
    q: 'empire',
    searchParams: {},
    perPage: 50,
    idsOnly: true,
}) %}

{% set entries = craft.entries.section('collection').uid(ids).all() %}

{% if entries %}
    <ul>
        {% for result in entries %}
            <li>{{ result.title }}</li>
        {% endfor %}
    </ul>
{% else %}
    <p>No results found.</p>
{% endif %}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.boldminded.com/dexter/docs-craft/template-tags.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
