'BadTitleError' => __DIR__ . '/includes/exception/BadTitleError.php',
'BagOStuff' => __DIR__ . '/includes/libs/objectcache/BagOStuff.php',
'BaseDump' => __DIR__ . '/includes/export/BaseDump.php',
+ 'BaseSearchResultSet' => __DIR__ . '/includes/search/BaseSearchResultSet.php',
'BaseTemplate' => __DIR__ . '/includes/skins/BaseTemplate.php',
'BashkirUppercaseCollation' => __DIR__ . '/includes/collation/BashkirUppercaseCollation.php',
'BatchRowIterator' => __DIR__ . '/includes/utils/BatchRowIterator.php',
--- /dev/null
+<?php
+
+/**
+ * BaseSearchResultSet is the base class that must be extended by SearchEngine
+ * search result set implementations.
+ *
+ * This base class is meant to hold B/C behaviors and to be useful it must never:
+ * - be used as type hints (ISearchResultSet must be used for this)
+ * - implement a constructor
+ * - declare utility methods
+ *
+ * @ingroup Search
+ */
+abstract class BaseSearchResultSet implements ISearchResultSet {
+
+ /**
+ * @var ArrayIterator|null Iterator supporting BC iteration methods
+ */
+ private $bcIterator;
+
+ /**
+ * Fetches next search result, or false.
+ * @deprecated since 1.32; Use self::extractResults() or foreach
+ * @return SearchResult|false
+ */
+ public function next() {
+ wfDeprecated( __METHOD__, '1.32' );
+ $it = $this->bcIterator();
+ $searchResult = $it->current();
+ $it->next();
+ return $searchResult ?? false;
+ }
+
+ /**
+ * Rewind result set back to beginning
+ * @deprecated since 1.32; Use self::extractResults() or foreach
+ */
+ public function rewind() {
+ wfDeprecated( __METHOD__, '1.32' );
+ $this->bcIterator()->rewind();
+ }
+
+ private function bcIterator() {
+ if ( $this->bcIterator === null ) {
+ $this->bcIterator = 'RECURSION';
+ $this->bcIterator = $this->getIterator();
+ } elseif ( $this->bcIterator === 'RECURSION' ) {
+ // Either next/rewind or extractResults must be implemented. This
+ // class was potentially instantiated directly. It should be
+ // abstract with abstract methods to enforce this but that's a
+ // breaking change...
+ wfDeprecated( static::class . ' without implementing extractResults', '1.32' );
+ $this->bcIterator = new ArrayIterator( [] );
+ }
+ return $this->bcIterator;
+ }
+
+ /**
+ * Fetch an array of regular expression fragments for matching
+ * the search terms as parsed by this engine in a text extract.
+ * STUB
+ *
+ * @return string[]
+ * @deprecated since 1.34 (use SqlSearchResult)
+ */
+ public function termMatches() {
+ return [];
+ }
+
+ /**
+ * Frees the result set, if applicable.
+ * @deprecated noop since 1.34
+ */
+ public function free() {
+ }
+}
<?php
/**
+ * A set of SearchEngine results.
+ * Must not be directly implemented by extension, please extend BaseSearchResultSet instead.
+ * This interface must only be used for type hinting.
+ *
+ * @see BaseSearchResultSet
* @ingroup Search
*/
interface ISearchResultSet extends \Countable, \IteratorAggregate {
$setAugmentors[$name] = new PerRowAugmentor( $row );
}
+ /**
+ * @var string $name
+ * @var ResultSetAugmentor $augmentor
+ */
foreach ( $setAugmentors as $name => $augmentor ) {
$data = $augmentor->augmentAll( $resultSet );
if ( $data ) {
/**
* @ingroup Search
*/
-class SearchResultSet implements ISearchResultSet {
+class SearchResultSet extends BaseSearchResultSet {
protected $containedSyntax = false;
*/
protected $results;
- /**
- * Set of result's extra data, indexed per result id
- * and then per data item name.
- * The structure is:
- * PAGE_ID => [ augmentor name => data, ... ]
- * @var array[]
- */
- protected $extraData = [];
-
/**
* @var boolean True when there are more pages of search results available.
*/
private $hasMoreResults;
- /**
- * @var ArrayIterator|null Iterator supporting BC iteration methods
- */
- private $bcIterator;
-
/**
* @param bool $containedSyntax True when query is not requesting a simple
* term match
$this->hasMoreResults = $hasMoreResults;
}
- /**
- * Fetch an array of regular expression fragments for matching
- * the search terms as parsed by this engine in a text extract.
- * STUB
- *
- * @return string[]
- * @deprecated since 1.34 (use SqlSearchResult)
- */
- public function termMatches() {
- return [];
- }
-
public function numRows() {
return $this->count();
}
return false;
}
- /**
- * Fetches next search result, or false.
- * @deprecated since 1.32; Use self::extractResults() or foreach
- * @return SearchResult|false
- */
- public function next() {
- wfDeprecated( __METHOD__, '1.32' );
- $it = $this->bcIterator();
- $searchResult = $it->current();
- $it->next();
- return $searchResult ?? false;
- }
-
- /**
- * Rewind result set back to beginning
- * @deprecated since 1.32; Use self::extractResults() or foreach
- */
- public function rewind() {
- wfDeprecated( __METHOD__, '1.32' );
- $this->bcIterator()->rewind();
- }
-
- private function bcIterator() {
- if ( $this->bcIterator === null ) {
- $this->bcIterator = 'RECURSION';
- $this->bcIterator = $this->getIterator();
- } elseif ( $this->bcIterator === 'RECURSION' ) {
- // Either next/rewind or extractResults must be implemented. This
- // class was potentially instantiated directly. It should be
- // abstract with abstract methods to enforce this but that's a
- // breaking change...
- wfDeprecated( static::class . ' without implementing extractResults', '1.32' );
- $this->bcIterator = new ArrayIterator( [] );
- }
- return $this->bcIterator;
- }
-
- /**
- * Frees the result set, if applicable.
- * @deprecated noop since 1.34
- */
- public function free() {
- }
-
/**
* Did the search contain search syntax? If so, Special:Search won't offer
* the user a link to a create a page named by the search string because the
class SearchResultSetTest extends MediaWikiTestCase {
/**
* @covers SearchResultSet::getIterator
- * @covers SearchResultSet::next
- * @covers SearchResultSet::rewind
+ * @covers BaseSearchResultSet::next
+ * @covers BaseSearchResultSet::rewind
*/
public function testIterate() {
$result = SearchResult::newFromTitle( Title::newMainPage() );
}
$this->assertEquals( 1, $count );
- $this->hideDeprecated( 'SearchResultSet::rewind' );
- $this->hideDeprecated( 'SearchResultSet::next' );
+ $this->hideDeprecated( 'BaseSearchResultSet::rewind' );
+ $this->hideDeprecated( 'BaseSearchResultSet::next' );
$resultSet->rewind();
$count = 0;
while ( ( $iterResult = $resultSet->next() ) !== false ) {