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
searchAsync,
browseAsync,
searchForFacetValues
Search,
Browse,
SearchForFacetValues,
GenerateSecuredApiKey,
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
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 ornull
. - You can’t use this setting on an attribute that’s part of a comma-separated list of attributes within
searchableAttributes
. For example, if yoursearchableAttributes
parameter contains['title, category', 'content']
,title
andcategory
are part of one comma-separated element and have the same priority, whilecontent
has its own priority level. You can setrestrictSearchableAttributes
to['content']
, but you can’t setrestrictSearchableAttributes
to['title']
,['category']
,['title, category']
or['title', 'category']
. - You can’t use this setting to change the priority order of
searchableAttributes
. For example, if yoursearchableAttributes
parameter contains['title', 'category', 'content']
, andrestrictSearchableAttributes
parameter contains['category', 'title']
, the engine only searches in thecategory
andtitle
attributes. Matches in thetitle
attribute still rank higher than matches in thecategory
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'
]
]);