API Reference / API Parameters / restrictSearchableAttributes

restrictSearchableAttributes

Type: list of strings
Engine default: all attributes in searchableAttributes
Parameter syntax
'restrictSearchableAttributes' => [
  'attribute'
]

Can be used in these methods:

About this parameter

Restricts a given query to look in only a subset of your searchable attributes.

This setting overrides searchableAttributes for specific searches, without changing the priority order of the searchableAttributes.

Usage notes:

  • This setting is a search parameter, and only affects searches that specify it.
  • This setting only works when searchableAttributes isn’t empty or null.
  • You can’t use this setting on an attribute that’s part of a comma-separated list of attributes within searchableAttributes. For example, if your searchableAttributes parameter contains ['title, category', 'content'], title and category are part of one comma-separated element and have the same priority, while content has its own priority level. You can set restrictSearchableAttributes to ['content'], but you can’t set restrictSearchableAttributes to ['title'], ['category'], ['title, category'] or ['title', 'category'].
  • You can’t use this setting to change the priority order of searchableAttributes. For example, if your searchableAttributes parameter contains ['title', 'category', 'content'], and restrictSearchableAttributes parameter contains ['category', 'title'], the engine only searches in the category and title attributes. Matches in the title attribute still rank higher than matches in the category attribute.

Examples

Search on a restricted set of attributes

In this example, let’s consider that searchableAttributes contains ['title', 'author', 'publisher', 'content'], but we only want to search in title and author

1
2
3
4
5
6
$results = $index->search('query', [
  'restrictSearchableAttributes' => [
    'title',
    'author'
  ]
]);

Did you find this page helpful?