/** * This function returns an array of highlighted key-value pairs. * * @param maxFields - the number of highlighted fields to return, 0 = all * * @return array of key value pairs */ public function getHighlightedHitText($maxFields = 0) { $ret = array(); $highlights = $this->elasticaResult->getHighlights(); if (!empty($highlights) && is_array($highlights)) { $highlighter = new SugarSearchEngineHighlighter(); $highlighter->setModule($this->getModule()); $ret = $highlighter->processHighlightText($highlights); if ($maxFields > 0) { $ret = array_slice($ret, 0, $maxFields); } } return $ret; }
/** * Returns the highlights array for document as returned by ElasticSearch * for the executed query. * * If this is a new document, or the query used to create it did not ask for * highlights, this function will return an empty array. * * @return array */ public function highlights() { if ($this->_result) { return $this->_result->getHighlights(); } return []; }
/** * @param Result $result * @return Html */ private function getHighlightingTextFromResult(Result $result) { $highlights = $result->getHighlights(); return Html::el()->setHtml(reset($highlights['text'])); }