MediaWiki  1.34.0
SearchResultSetTrait.php
Go to the documentation of this file.
1 <?php
2 
20  private $extraData = [];
21 
27  public function setAugmentedData( $name, $data ) {
28  foreach ( $data as $id => $resultData ) {
29  $this->extraData[$id][$name] = $resultData;
30  }
31  }
32 
37  public function augmentResult( SearchResult $result ) {
38  $id = $result->getTitle()->getArticleID();
39  if ( $id === -1 ) {
40  return;
41  }
42  $result->setExtensionData( function () use ( $id ) {
43  return $this->extraData[$id] ?? [];
44  } );
45  }
46 
53  public function getOffset() {
54  return null;
55  }
56 
57  final public function getIterator() {
58  return new ArrayIterator( $this->extractResults() );
59  }
60 }
getIterator
getIterator()
Definition: SearchResultSetTrait.php:57
SearchResult
NOTE: this class is being refactored into an abstract base class.
Definition: SearchResult.php:38
augmentResult
augmentResult(SearchResult $result)
Returns extra data for specific result and store it in SearchResult object.
Definition: SearchResultSetTrait.php:37
setAugmentedData
setAugmentedData( $name, $data)
Sets augmented data for result set.
Definition: SearchResultSetTrait.php:27
getOffset
getOffset()
Definition: SearchResultSetTrait.php:53
SearchResultSetTrait
trait SearchResultSetTrait
Trait useful for SearchResultSet implementations.
Definition: SearchResultSetTrait.php:12