用elasticsearch-php laravel为什么不能返回高亮数据?

 鲁有军_644 发布于 2022-11-30 14:17
    namespace App\Http\Controllers\Search;
    use Illuminate\Http\Request;
    use App\Http\Requests;
    use App\Http\Controllers\Controller;
    use Elasticsearch\Client;

class Index extends Controller
{
    protected $client;
    public function __construct(Client $client)
    {
        $this->client = $client;
    }
    public function search_test(Request $request,$filter='list'){
        $word = trim($request->input('word'));

        $s=is_null($request->input('s'))?10:trim($request->input('s'));//一页多少条
        $f=is_null($request->input('f'))?1:trim($request->input('f'));//当前页数
        $fr=($f-1)*$s;//当前页从第一条记录开始
        $params=[
            'index' => 's_index',
            'type' => 's_type',
            'body' => [
                'query' => [
                    'bool' => [
                        'should' => [
                            [ 'match' => [ 'title' => $word ] ],
                            [ 'match' => [ 'description' => $word ] ],
                        ]
                    ]
                ]
                ,'from'=>$fr, 'size'=>$s
                ,'highlight'=>[
                    'fields'=>[
                        'title'=>[]
                    ]
                ]
            ]
        ];

        $response = $this->client->search($params);

        echo "
";
        var_dump($response);
        echo "
"; } }

查询结果都能返回,就是无highlight数据,求朋友帮忙!!!

2 个回答
  • 假如你是用的官方的elasticsearch-php,可以参照如下设置:

    2022-11-30 14:42 回答
  • 暂时没做过搜索服务,感觉高亮的数据应该在控制器里面处理的吧。

    2022-11-30 14:42 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有