(all string attributes)
'searchableAttributes' => [ 'attribute1', 'attribute2, attribute3', // both attributes have the same priority 'unordered(attribute4)' ]
About this parameter
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.
Whenever you change this parameter, the engine rebuilds your entire index. If you need to do near real-time indexing, try not to change the setting during your peak-traffic times.
- Default/empty list: if you don’t use this setting, or use it with an empty list, the engine searches in all attributes.
- Same priority: you can create the same priority for several attributes by setting them in the same comma-separated string.
- 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.
- 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.,
unordered: Any match anywhere in the attribute has the same weight.
By default, searchable attributes are set as ordered, meaning that matches at the beginning of an attribute are more relevant than towards the end. Setting them as
unorderedcancels out this behavior, making all matches equal regardless of their position in the attribute.
Note that if you set searchable attributes with the same priority, you can’t set different modifiers on each. You can’t have modified and unmodified searchable attributes on the same line (e.g.,
'unordered(attribute1), attribute2'is invalid).
1 2 3 4 5 6 7 8 $index->setSettings([ 'searchableAttributes' => [ 'title,alternative_title', 'author', 'unordered(text)', 'emails.personal' ] ]);