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 ];