tagFilters
'tagFilters' => [ 'value', // value1 OR value2 ['value1', 'value2'], // (value1 OR value2) AND value3 ['value1', 'value2'], 'value3', ... ]
Can be used in these methods:
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browse,
searchForFacetValues,
generateSecuredApiKey,
addAPIKey,
updateAPIKey
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
Browse,
SearchForFacetValues,
GenerateSecuredApiKey,
AddApiKey,
UpdateApiKey
Search,
browse,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
BrowseObjects,
SearchForFacetValues,
GenerateSecuredAPIKey,
AddAPIKey,
UpdateAPIKey
search,
browse index,
search into facet values,
generateSecuredApiKey,
add key,
update key
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 asBook AND Movie
[["Book", "Movie"], "SciFi"]
translates as(Book OR Movie) AND SciFi"