restrictSearchableAttributes
searchableAttributes
'restrictSearchableAttributes' => [ 'attribute' ]
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,
GenerateSecuredApiKeys,
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
Limit the search for a given query to a subset of your searchable attributes.
Usage notes
- This setting is a search parameter, and only affects searches that specify it.
- Only works when
searchableAttributesisn’t empty ornull. - Attribute names are case-sensitive.
You can’t use this setting:
- On an attribute that’s part of a comma-separated list of attributes within
searchableAttributes. For example, if yoursearchableAttributesparameter contains['title, category', 'content'],titleandcategoryare part of one comma-separated element and have the same priority, whilecontenthas its own priority level. You can setrestrictSearchableAttributesto['content'], but you can’t setrestrictSearchableAttributesto['title'],['category'],['title, category']or['title', 'category']. - To change the priority order of
searchableAttributes. For example, if yoursearchableAttributesparameter contains['title', 'category', 'content'], andrestrictSearchableAttributesparameter contains['category', 'title'], the engine only searches in thecategoryandtitleattributes. Matches in thetitleattribute still rank higher than matches in thecategoryattribute.
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'
]
]);