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.
tagFilters
is a different way of filtering, which relies on the _tags
attribute.
It uses a simpler syntax than filters
. You can use it when you want to do simple filtering
based on tags.
For more advanced filtering, we recommend the filters
parameter instead.
Filters can be placed in any attribute, at any level (deep nesting included).
Tags can only be contained in a top-level _tags attribute.
Additionally, Filters provide an easier to use, SQL-like syntax.
Usage notes
-
_tags: For this setting to work, your records need to have a
_tags
attribute. -
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 is supported by prefixing the tag value with a minus sign (
-
), sometimes called a dash. For example,["tag1", "-tag2"]
translates astag1 AND NOT tag2
. -
No record count: Tag filtering is used for filtering only. You will not get a count of records that match the filters. In this way, it is the same as using filterOnly() in the attributesForFaceting.
Examples
Apply tag filters
We want to look for books or movies which are Sci-fi: "(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"