From 6f1129df56072f7f7da54307caa0a40d45a3a7ef Mon Sep 17 00:00:00 2001 From: Nikolay Dmitrienko Date: Tue, 17 Apr 2018 18:55:55 +0300 Subject: [PATCH] Added a basic highlight method to the SearchQuery --- src/Bardex/Elastic/SearchQuery.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Bardex/Elastic/SearchQuery.php b/src/Bardex/Elastic/SearchQuery.php index 3e9968f..d72dcd6 100644 --- a/src/Bardex/Elastic/SearchQuery.php +++ b/src/Bardex/Elastic/SearchQuery.php @@ -224,6 +224,31 @@ public function limit($limit, $offset = 0) return $this; } + /** + * Включить подсветку найденного + * @param array $fields - поля, которые будут подсвечиваться + * @param int $fragment_size - размер подсвеченного фрагмента + * @param array|string $pre_tags - открывающий(ие) тэг(и) + * @param array|string $post_tags - закрывающий(ие) тэг(и) + * @return $this + */ + public function highlight($fields, $fragment_size=100, $pre_tags = '', $post_tags = '') + { + $arr = []; + foreach ($fields as $field) { + $arr[$field] = new stdClass(); + } + + $this->params['body']['highlight'] = [ + 'fields' => $arr, + 'fragment_size'=> $fragment_size, + 'pre_tags' => $pre_tags, + 'post_tags' => $post_tags + ]; + + return $this; + } + /** * Получить собранный запрос * @return array