dsdqpdjpq16640651 2019-07-06 01:50
浏览 70

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

I'm having issue of BadMethodCallException : Call to undefined method App\Service::makeAllSearchable() though I have Searchable (ScoutElastic\Searchable) trait.

I'm using laravel 5.8 and elasticsearch 6.8.1, also using babenkoivan/scout-elasticsearch-driver. I have 2 Model to search. 1. Doctor.php and 2. Service.php When I run command php artisan scout:import "App\Doctor" it works fine but php artisan scout:import "App\Service" throw error. For Doctor and Service model I have bellow files

  1. Service.php -- ServiceIndexConfigurator.php -- ServiceSearchRule.php
  2. Doctor.php --- DoctorIndexConfigurator.php -- DoctorSearchRule.php

FYI Code for Doctor is almost same. Here is 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_'
                ]
            ]
        ]
    ];
}

ServiceSearchRule.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
                        ]
                    ]
                ]
            ]
        ];
    }
}

Error Message

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
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 公交车和无人机协同运输
    • ¥15 stm32代码移植没反应
    • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
    • ¥100 连续两帧图像高速减法
    • ¥15 组策略中的计算机配置策略无法下发
    • ¥15 如何绘制动力学系统的相图
    • ¥15 对接wps接口实现获取元数据
    • ¥20 给自己本科IT专业毕业的妹m找个实习工作
    • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
    • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)