Skip to content

Commit

Permalink
Adding highlighting to Returned ResultList of DataObjects/Pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Finnie, Claire committed Oct 5, 2017
1 parent 2e995dd commit 70fd92c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/ResultList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -166,6 +167,7 @@ public function toArray()
} else {
$needed[$type][] = $item->getId();
}

}

foreach ($needed as $class => $ids) {
Expand All @@ -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()];
}
}
Expand Down

0 comments on commit 70fd92c

Please sign in to comment.