orest
2 weeks ago
178
8
Laravel

set searchable attributes to Algolia

Posted 2 weeks ago by orest

I'm trying to figure out how I can set the searchable attributes to an index during runtime.

I have the model Thread which is searchable and based on a query parameter, I want to search only the title of the index.

class Thread extends Model 
{
	use Searchable;
}

What I have tried :

1

if (request('only_title')){
	Thread::search('query', [
                'restrictSearchableAttributes' => [
                    'title',
                ],
}

2

Thread::setSettings(
  [
    'restrictSearchableAttributes' => ['title']
  ],

3

There is also a configuration file named scout-threads where I can set the restrictSearchableAttributes value.

config('scout-threads.restrictSearchableAttributes', 'title');

Any thoughts ?

Please sign in or create an account to participate in this conversation.