setTagFilter method
TagFilters
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.
Warning
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
.
Source: Learn more
Implementation
AlgoliaQuery setTagFilter(String value) {
final tagFilters = List<String>.from(_parameters['tagFilters']);
assert(tagFilters.where((String item) => value == item).isEmpty,
'TagFilters $value already exists in this query');
tagFilters.add(value);
return _copyWithParameters(<String, dynamic>{'tagFilters': tagFilters});
}