elasticsearch,laravel-5,laravel-scout,Php,elasticsearch,Laravel 5,Laravel Scout" /> elasticsearch,laravel-5,laravel-scout,Php,elasticsearch,Laravel 5,Laravel Scout" />

Php 在scout:import上调用未定义的方法App\Service::makeAllSearchable()

Php 在scout:import上调用未定义的方法App\Service::makeAllSearchable(),php,elasticsearch,laravel-5,laravel-scout,Php,elasticsearch,Laravel 5,Laravel Scout,我遇到了BadMethodCallException的问题:调用未定义的方法App\Service::makeAllSearchable(),尽管我具有可搜索(ScoutElastic\Searchable)特性。 我使用的是laravel 5.8和elasticsearch 6.8.1,还使用了babenkoivan/scout elasticsearch驱动程序。我有两个模型要搜索。 1.php和 2.Service.php namespace App; use ScoutElastic\

我遇到了BadMethodCallException的问题:调用未定义的方法App\Service::makeAllSearchable(),尽管我具有可搜索(ScoutElastic\Searchable)特性。

我使用的是laravel 5.8和elasticsearch 6.8.1,还使用了babenkoivan/scout elasticsearch驱动程序。我有两个模型要搜索。 1.php和 2.Service.php
namespace App;

use ScoutElastic\Searchable;
use Illuminate\Database\Eloquent\Model;

class Service extends Model
{
    use Searchable;

    /**
     * @var string
     */
    protected $indexConfigurator = ServiceIndexConfigurator::class;

    /**
     * @var array
     */
    protected $searchRules = [
        ServiceSearchRule::class
    ];

    /**
     * @var array
     */
    protected $mapping = [
        'properties' => [
            'service_name' => [
                'type' => 'text'
            ],
            'description' => [
                'type' => 'text'
            ]
        ]
    ];

    public function toSearchableArray()
    {
        return $this->only('service_name', 'description');
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

}
当我运行命令
php artisan scout:import“App\Doctor”
时,它工作正常,但
php artisan scout:import“App\Service”
抛出错误。 对于医生和服务模式,我有以下文件

  • Service.php--ServiceIndexConfigurator.php--ServiceSearchRule.php
  • namespace App;
    
    use ScoutElastic\Searchable;
    use Illuminate\Database\Eloquent\Model;
    
    class Service extends Model
    {
        use Searchable;
    
        /**
         * @var string
         */
        protected $indexConfigurator = ServiceIndexConfigurator::class;
    
        /**
         * @var array
         */
        protected $searchRules = [
            ServiceSearchRule::class
        ];
    
        /**
         * @var array
         */
        protected $mapping = [
            'properties' => [
                'service_name' => [
                    'type' => 'text'
                ],
                'description' => [
                    'type' => 'text'
                ]
            ]
        ];
    
        public function toSearchableArray()
        {
            return $this->only('service_name', 'description');
        }
    
        public function user()
        {
            return $this->belongsTo(User::class);
        }
    
    }
    
    namespace App;
    
    use ScoutElastic\SearchRule;
    
    class ServiceSearchRule extends SearchRule
    {
        /**
         * @inheritdoc
         */
        public function buildHighlightPayload()
        {
            //
        }
    
        /**
         * @inheritdoc
         */
        public function buildQueryPayload()
        {
            $query = $this->builder->query;
            return [
                'should' => [
                    [
                        'match' => [
                            'service_name' => [
                                'query' => $query,
                                'boost' => 1
                            ]
                        ]
                    ],
                    [
                        'match' => [
                            'country' => [
                                'query' => $query,
                                'boost' => 2
                            ]
                        ]
                    ],
                    [
                        'match' => [
                            'description' => [
                                'query' => $query,
                                'boost' => 3
                            ]
                        ]
                    ],
                    [
                        'match' => [
                            'approx_cost' => [
                                'query' => $query,
                                'boost' => 4
                            ]
                        ]
                    ],
                    [
                        'match' => [
                            'currency' => [
                                'query' => $query,
                                'boost' => 5
                            ]
                        ]
                    ]
                ]
            ];
        }
    }
    
  • Doctor.php--DoctorIndexConfigurator.php--DoctorSearchRule.php
  • namespace App;
    
    use ScoutElastic\SearchRule;
    
    class ServiceSearchRule extends SearchRule
    {
        /**
         * @inheritdoc
         */
        public function buildHighlightPayload()
        {
            //
        }
    
        /**
         * @inheritdoc
         */
        public function buildQueryPayload()
        {
            $query = $this->builder->query;
            return [
                'should' => [
                    [
                        'match' => [
                            'service_name' => [
                                'query' => $query,
                                'boost' => 1
                            ]
                        ]
                    ],
                    [
                        'match' => [
                            'country' => [
                                'query' => $query,
                                'boost' => 2
                            ]
                        ]
                    ],
                    [
                        'match' => [
                            'description' => [
                                'query' => $query,
                                'boost' => 3
                            ]
                        ]
                    ],
                    [
                        'match' => [
                            'approx_cost' => [
                                'query' => $query,
                                'boost' => 4
                            ]
                        ]
                    ],
                    [
                        'match' => [
                            'currency' => [
                                'query' => $query,
                                'boost' => 5
                            ]
                        ]
                    ]
                ]
            ];
        }
    }
    
    医生的FYI代码几乎相同。 这里是Service.php
    namespace App;
    
    use ScoutElastic\Searchable;
    use Illuminate\Database\Eloquent\Model;
    
    class Service extends Model
    {
        use Searchable;
    
        /**
         * @var string
         */
        protected $indexConfigurator = ServiceIndexConfigurator::class;
    
        /**
         * @var array
         */
        protected $searchRules = [
            ServiceSearchRule::class
        ];
    
        /**
         * @var array
         */
        protected $mapping = [
            'properties' => [
                'service_name' => [
                    'type' => 'text'
                ],
                'description' => [
                    'type' => 'text'
                ]
            ]
        ];
    
        public function toSearchableArray()
        {
            return $this->only('service_name', 'description');
        }
    
        public function user()
        {
            return $this->belongsTo(User::class);
        }
    
    }
    
    ServiceIndexConfigurator.php

    <?php
    
    namespace App;
    
    use ScoutElastic\IndexConfigurator;
    use ScoutElastic\Migratable;
    
    class ServiceIndexConfigurator extends IndexConfigurator
    {
        use Migratable;
    
        /**
         * @var array
         */
        protected $name = 'service_index';
    
        protected $settings = [
            'analysis' => [
                'analyzer' => [
                    'es_std' => [
                        'type' => 'standard',
                        'stopwords' => '_english_'
                    ]
                ]
            ]
        ];
    }
    
    错误消息

    BadMethodCallException  : Call to undefined method App\Service::makeAllSearchable()
    
      at /var/www/html/medicoocean.test/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:50
        46|      * @throws \BadMethodCallException
        47|      */
        48|     protected static function throwBadMethodCallException($method)
        49|     {
      > 50|         throw new BadMethodCallException(sprintf(
        51|             'Call to undefined method %s::%s()', static::class, $method
        52|         ));
        53|     }
        54| }
    
      Exception trace:
    
      1   Illuminate\Database\Eloquent\Model::throwBadMethodCallException("makeAllSearchable")
          /var/www/html/medicoocean.test/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:36
    
      2   Illuminate\Database\Eloquent\Model::forwardCallTo(Object(Illuminate\Database\Eloquent\Builder), "makeAllSearchable", [])
          /var/www/html/medicoocean.test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1614