是否有可能禁用toSearchableArray
当做更新到一个记录或是否有任何方法来只更新特定领域的记录在我的搜索索引?
例如:
public function toSearchableArray()
{
$item = $this->toArray();
$item['title'] = $this->title;
...
...
...
$item['category'] = $this->category->category_name;
$item['uploaded_at'] = Carbon::now('America/Montreal')->timestamp;
}
字符串
现在唯一的问题是,每次我更新一个记录时,它也会重置它的uploaded_at时间戳,并重新加载关系,这是一个我不需要的查询,因为它已经在我创建项目时设置了。
那么有没有什么方法可以暂时禁用toSearchableArray
呢?我只需要更新索引行中的几个字段,这样就不需要在toSearchableArray中删除所有内容了。
像波纹管只更新标题,然后更新标题在我的algolia索引没有重置uploaded_at
或再次加载category
关系
$order = App\Order::find(1);
$order->title = 'a new title'
$order->save();
型
2条答案
按热度按时间e4eetjau1#
你可以使用laravel scout中的
unsearchable
函数。字符串
这样当你保存或者更新的时候它就不会同步到algolia了。如果你再次想要同步模型到algolia,你可以调用
searchable
方法,如下所示。型
inb24sb22#
要完全禁用,请添加服务提供商:
字符串
暂时禁用:
型