我正在尝试将一些现有记录导入algolia。现在使用FileReader
和Laravel 5.5
与algolia-php-sdk。当我执行scout 3.0.0
时,它会抛出以下异常
php artisan scout:import "App\Listings" -v
我在模型中包含了 [BadMethodCallException]
Call to undefined method Illuminate\Database\Query\Builder::searchable()
Exception trace:
() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2457
Illuminate\Database\Query\Builder->__call() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1273
Illuminate\Database\Eloquent\Builder->__call() at /home/vagrant/Code/vendor/laravel/scout/src/Searchable.php:102
App\Listings::makeAllSearchable() at /home/vagrant/Code/vendor/laravel/scout/src/Console/ImportCommand.php:43
Laravel\Scout\Console\ImportCommand->handle() at n/a:n/a
call_user_func_array() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29
Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:87
Illuminate\Container\BoundMethod::callBoundMethod() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:31
Illuminate\Container\BoundMethod::call() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Container/Container.php:549
Illuminate\Container\Container->call() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Console/Command.php:180
Illuminate\Console\Command->execute() at /home/vagrant/Code/vendor/symfony/console/Command/Command.php:262
Symfony\Component\Console\Command\Command->run() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Console/Command.php:167
Illuminate\Console\Command->run() at /home/vagrant/Code/vendor/symfony/console/Application.php:888
Symfony\Component\Console\Application->doRunCommand() at /home/vagrant/Code/vendor/symfony/console/Application.php:224
Symfony\Component\Console\Application->doRun() at /home/vagrant/Code/vendor/symfony/console/Application.php:125
Symfony\Component\Console\Application->run() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Console/Application.php:88
Illuminate\Console\Application->run() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:121
Illuminate\Foundation\Console\Kernel->handle() at /home/vagrant/Code/artisan:35
`
特征,还有Searchable
方法来自定义要插入的记录。
我有另一个名为toSearchableArray()
的模型。我可以毫无问题地将该模型导入algolia。我经历过this link。但是我的模型都扩展了相同的basemodel类,所以上面的链接也没有帮助我。
任何关于前进的提示都将不胜感激。
修改 代码示例
Store
答案 0 :(得分:1)
我自己已经弄明白了。该模型包含$indices
数组/属性,用于表示插入记录的algolia索引。同时,它还包含searchableAs()
方法,该方法执行指定algolia索引的相同任务。并且$indices
数组是通过构造函数填充的,所以在第一眼看来我无法揭示罪魁祸首。
所以简单地删除$indices
数组和构造函数初始化$indices
的代码对我有用。但仍然不知道为什么Scout抛出Call to undefined method::Searchable()
异常