PerRowAugmentor.php 821 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Perform augmentation of each row and return composite result,
  4. * indexed by ID.
  5. */
  6. class PerRowAugmentor implements ResultSetAugmentor {
  7. /**
  8. * @var ResultAugmentor
  9. */
  10. private $rowAugmentor;
  11. /**
  12. * @param ResultAugmentor $augmentor Per-result augmentor to use.
  13. */
  14. public function __construct( ResultAugmentor $augmentor ) {
  15. $this->rowAugmentor = $augmentor;
  16. }
  17. /**
  18. * Produce data to augment search result set.
  19. * @param ISearchResultSet $resultSet
  20. * @return array Data for all results
  21. */
  22. public function augmentAll( ISearchResultSet $resultSet ) {
  23. $data = [];
  24. foreach ( $resultSet->extractResults() as $result ) {
  25. $id = $result->getTitle()->getArticleID();
  26. if ( !$id ) {
  27. continue;
  28. }
  29. $data[$id] = $this->rowAugmentor->augment( $result );
  30. }
  31. return $data;
  32. }
  33. }