API Reference / API Parameters / tagFilters
Type: list of strings
Engine default: []
Formerly: tags
Parameter syntax
'tagFilters' => [
  'value',

  // value1 OR value2
  ['value1', 'value2'],

  // (value1 OR value2) AND value3
  ['value1', 'value2'], 'value3',

  ...
]

Can be used in these methods:

About this parameter

Filter hits by tags.

For this type of filtering to work, your records must have a _tags attribute. Use tagFilters when you want to do simple filtering based on tags.

tagFilters is only used for filtering. You won’t get a count of records that match the filters. In this way, it’s the same as using filterOnly() in attributesForFaceting`.

For more advanced filtering, use the filters parameter instead. This lets you place filters in any attribute at any level wheras tags can only be in the top-level _tags attribute.

Usage notes

Multiple filters

If you specify multiple tags, they are interpreted as a conjunction (AND). If you want to use a disjunction (OR), use a nested array.

Negation

Prefix a value with a minus sign (-) to exclude tags. For example, ["tag1", "-tag2"] translates to tag1 AND NOT tag2.

Advanced queries

Enabling advancedSyntax lets users:

  • Add double quotes around phrases in a query to specify that a record must contain that phrase.
  • Prefix a word with a minus (-) character to specify that a record must not contain that phrase.

Examples

Apply tag filters

To look for science fiction books or movies, use "(Book OR Movie) AND SciFi".

1
2
3
4
5
6
7
8
9
$results = $index->search('query', [
  'tagFilters' => [
    [
      "Book",
      "Movie"
    ],
    "SciFi"
  ]
]);
  • ["Book", "Movie"] translates as Book AND Movie
  • [["Book", "Movie"], "SciFi"] translates as (Book OR Movie) AND SciFi"
Did you find this page helpful?