php - 使用 ongr-io/ElasticsearchDSL 包添加高亮
问题描述
找不到任何示例如何使用https://github.com/ongr-io/ElasticsearchDSL向查询结果添加亮点
<?php
require 'vendor/autoload.php'; //Composer autoload
$client = ClientBuilder::create()->build(); //elasticsearch-php client
$matchAll = new ONGR\ElasticsearchDSL\Query\MatchAllQuery();
$search = new ONGR\ElasticsearchDSL\Search();
$search->addQuery($matchAll);
//How to highlight results in title field?
$params = [
'index' => 'your_index',
'body' => $search->toArray(),
];
$results = $client->search($params);
解决方案
<?php
require 'vendor/autoload.php'; //Composer autoload
$client = ClientBuilder::create()->build(); //elasticsearch-php client
$matchAll = new ONGR\ElasticsearchDSL\Query\MatchAllQuery();
$search = new ONGR\ElasticsearchDSL\Search();
$search->addQuery($matchAll);
$higlight = new Highlight();
$higlight->addField('title');
$search->addHighlight($higlight);
$params = [
'index' => 'your_index',
'body' => $search->toArray(),
];
$results = $client->search($params);
推荐阅读
- python - 评估数据帧上的任何表达式/条件的函数
- javascript - 我的 React 组件状态是不断返回 null 对象
- javascript - 使用 javascript 选择应用程序时如何更改链接框值
- express - 将使用 multer 存储的 pdf 转换为文本
- android - 在 RecyclerView 中使用活动
- ios - 迁移到 Twilio Voice 5.0(iOS 13,Xcode 11):自定义来电视图控制器,拒绝来电问题
- ssh - macOS 终端,使用 Socks 代理连接到 SSH
- python - 如何展平参数列表?
- python-3.x - 如何在 Python 3 中编写主函数?
- sql - 如何计算不同时间的不同时间?