wiki.techinc.nl/includes/search/PerRowAugmentor.php
David Causse 6af636fb03 Add ISearchResultSet
Bug: T228626
Change-Id: I3306bf6107c97dd58adf578fd965bd11a422627d
2019-07-22 18:27:39 +00:00

37 lines
821 B
PHP

<?php
/**
* Perform augmentation of each row and return composite result,
* indexed by ID.
*/
class PerRowAugmentor implements ResultSetAugmentor {
/**
* @var ResultAugmentor
*/
private $rowAugmentor;
/**
* @param ResultAugmentor $augmentor Per-result augmentor to use.
*/
public function __construct( ResultAugmentor $augmentor ) {
$this->rowAugmentor = $augmentor;
}
/**
* Produce data to augment search result set.
* @param ISearchResultSet $resultSet
* @return array Data for all results
*/
public function augmentAll( ISearchResultSet $resultSet ) {
$data = [];
foreach ( $resultSet->extractResults() as $result ) {
$id = $result->getTitle()->getArticleID();
if ( !$id ) {
continue;
}
$data[$id] = $this->rowAugmentor->augment( $result );
}
return $data;
}
}