gpt4 book ai didi

php - 使用ongr-io/ElasticsearchDSL软件包添加突出显示

转载 作者:行者123 更新时间:2023-12-02 22:21:50 28 4
gpt4 key购买 nike

找不到任何示例如何使用higlighthttps://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);

关于php - 使用ongr-io/ElasticsearchDSL软件包添加突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56720692/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com