setSearchableAttributes method

AlgoliaQuery setSearchableAttributes(
  1. List<String> value
)

SearchableAttributes

The complete list of attributes used for searching.

This setting is critical to establishing excellent relevance for two main reasons:

  • It limits the scope of a search to the listed attributes. Defining specific attributes as searchable gives you direct control over what information the search engine should look at. Some attributes contain URLs; others exist for display purposes only. Such attributes are not useful for searching.
  • It creates a priority order between attributes which the engine uses to improve relevance. The order in which the attributes appear determines their search priority. Records with matches in the first attribute(s) of the list score higher on the attribute criterion than records with matches in the second attribute(s), which score higher than records with matches in the third attribute(s), and so on.

This setting helps reduce your response size and improve performance.

Usage notes:

  • Default/empty list: if you don’t use this setting, or use it with an empty list, the engine searches in all attributes.
  • Ordering: in addition to creating attribute-level priority, you can also determine how the engine searches within an attribute. By default, the engine favors matches at the beginning of an attribute, but you can change it to ignore positioning and consider any match within an attribute of equal importance.
  • Same priority: you can create the same priority for several attributes by setting them in the same comma-separated string. Attributes that are on the same priority as others are always unordered.
  • Nested attributes: when you specify an attribute with nested attributes, the engine indexes them all. If you don’t want to search the full attribute, you can reference a child attribute (e.g., categories.lvl0.child_attribute.sub_child_attribute).

Source: Learn more

Implementation

AlgoliaQuery setSearchableAttributes(List<String> value) {
  assert(value.isNotEmpty, 'value can not be empty');
  assert(!_parameters.containsKey('searchableAttributes'));
  return _copyWithParameters(
      <String, dynamic>{'searchableAttributes': value});
}