diff --git a/src/ResultList.php b/src/ResultList.php index 09e2768..559cbd4 100644 --- a/src/ResultList.php +++ b/src/ResultList.php @@ -28,7 +28,8 @@ public function __construct(Index $index, Query $query, LoggerInterface $logger //Optimise the query by just getting back the ids and types $query->setFields(array( '_id', - '_type' + '_type', + 'highlight' )); //If we are in live reading mode, only return published documents @@ -166,6 +167,7 @@ public function toArray() } else { $needed[$type][] = $item->getId(); } + } foreach ($needed as $class => $ids) { @@ -177,6 +179,20 @@ public function toArray() foreach ($found as $item) { // Safeguards against indexed items which might no longer be in the DB if (array_key_exists($item->getId(), $retrieved[$item->getType()])) { + + $highlights = $item->getHighlights(); + $highlightsArray = []; + + foreach ($highlights as $field => $highlight) { + $concatenatedValue = ''; + foreach ($highlight as $key => $value) { + $concatenatedValue .= $value; + } + $highlightsArray[$field] = $concatenatedValue; + } + + //add Highlights property + $retrieved[$item->getType()][$item->getId()]->highlights = new \ArrayData($highlightsArray); $this->resultsArray[] = $retrieved[$item->getType()][$item->getId()]; } }