Using restrictSearchableAttributes gives error if searchableAttributes are unordered, same level in PHP client

I get this error:
The query you provided could not be parsed by the search engine: invalid setting for restrictSearchableAttributes, you should requests all attributes with same priority: name, address, description, does not exists

when restrictSearchableAttributes is name.

The index’s searchableAttributes are unordered name, address, description.

The query works fine if I order the searchableAttributes.

Is this the expected behaviour?

Thanks

Hi there,

restrictSearchableAttributes takes a list of strings not a string.
Could you provide us with the code your are using? Maybe there is an issue here.

Thanks

Hi @rcs,

Thanks for getting back. Below are the steps to reciprocate the issue I’m facing.
I’m using the PHP client (1.17.0)

  1. Create the index (set searchableAttributes)
    $settings['searchableAttributes'] = array('name, address, description'); $index->setSettings($settings);

  2. Fire a search query having restrictSearchableAttributes parameter.
    $q = 'hello'; $args = array( 'length' => 10, 'offset' => 0, 'restrictSearchableAttributes' => array('name') );

  3. $index->search($q, $args);

Gives the following error:
Error executing the provided query: invalid setting for restrictSearchableAttributes, you should requests all attributes with same priority: name, address, description, does not exist

In Algolia’s dashboard, I can see that the index’s search attributes are “name, address, description” (unordered).

Thanks.

When you do this:

$settings['searchableAttributes'] = array('name, address, description');

you put in searchableAttributes a list of one element, not 3 elements.
You probably want to do this:

$settings['searchableAttributes'] = array('name', 'address', 'description');

I’d put them in one, as I wanted all the attributes to be unordered. If I add them as an array, they are set as ordered.

@rcs I’m following the docs from here 1

Hi @rcs.

Just wondering if there is any update on this one?

Sorry for the delay.

When you specify searchableAttributes as unordered on the same level (as you did), you need to put the same attributes in the restrictSearchableAttributes.

If you need to restrictSearchableAttributes to only name, you will need to do

$settings['searchableAttributes'] = array('unordered(name)', 'unordered(address)', 'unordered(description)')

@rcs, I forgot to mention that I need to set all attributes as unordered and on the same level. Apologies for that.

My requirement is: To have a set of attributes indexed as unordered and on the same level. After indexing, I want to search on only one of those attributes.

Your way of setting up the searchableAttributes as unordered and on the same level won’t work.
Instead, $settings['searchableAttributes'] = array('name, address, description') will work. 1

Now, if I do restrictSearchableAttributes during search time 2, I’m get the error:
Invalid setting for restrictSearchableAttributes, you should requests all attributes with same priority: name, address, description, does not exists

I’m sorry but it’s not possible to have what you want.

When you specify $settings['searchableAttributes'] = array('name, address, description'), internally, it’s computed as one virtual attribute containing the values of the 3 attributes. So they are linked, so it’s not possible to separate them again.

Could explain me what is your business need? There might be another way of achieving this.

@rcs The requirement is to make all attributes equal (same priority) and treat all words within attributes as of equal rank.

For the search, we need to give a (sort of) filter to search (string search) inside only a particular attribute.

So, to sum up; the problem isn’t of unordered but of the same priority. (as attributes on the same level are automatically unordered)

Thanks for the details. But I would need more what is your business need, without any technical requirement. If you can’t post it on this public channel, feel free to send it to support@algolia.com

Thanks @rcs. Will contact support.

Cheers.