summaryrefslogtreecommitdiff
path: root/www/wiki/includes/search/PerRowAugmentor.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/includes/search/PerRowAugmentor.php')
-rw-r--r--www/wiki/includes/search/PerRowAugmentor.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/www/wiki/includes/search/PerRowAugmentor.php b/www/wiki/includes/search/PerRowAugmentor.php
new file mode 100644
index 00000000..a3979f7b
--- /dev/null
+++ b/www/wiki/includes/search/PerRowAugmentor.php
@@ -0,0 +1,37 @@
+<?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 SearchResultSet $resultSet
+ * @return array Data for all results
+ */
+ public function augmentAll( SearchResultSet $resultSet ) {
+ $data = [];
+ foreach ( $resultSet->extractResults() as $result ) {
+ $id = $result->getTitle()->getArticleID();
+ if ( !$id ) {
+ continue;
+ }
+ $data[$id] = $this->rowAugmentor->augment( $result );
+ }
+ return $data;
+ }
+}