ES配置搜索规则

搜索规则是描述如何执行搜索查询的类。要创建搜索规则,请使用以下命令:

php artisan make:search-rule MySearchRule
在文件中,app/MySearchRule.php您将找到一个类定义:

<?php

namespace App;

use ScoutElastic\SearchRule;

class MySearchRule extends SearchRule
{
    /**
     * @inheritdoc
     */
    public function buildHighlightPayload()
    {
        //
    }
    
    /**
     * @inheritdoc
     */
    public function buildQueryPayload()
    {
        
        return [
            'must' => [
                'query_string' => [
                    'query'  => $this->builder->query,
                    'fields' => ["sell_point^10", "name^5", "title_tags^5", "cate_tags^3", "category_name^8", "share_intro", "reason"],
                    'type'   => "most_fields"
                ]
            ],
        
        
        ];
    }
}
搜索模型添加
protected $searchRules = [
    MySearchRule::class
];

 

posted @ 2021-04-21 10:55  飞翔的贺兰猪  阅读(344)  评论(0编辑  收藏  举报