"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "includes/search/SearchResultSet.php" between
mediawiki-1.31.1.tar.gz and mediawiki-1.32.0.tar.gz

About: MediaWiki is a wiki engine (the collaborative editing software that runs for e.g. Wikipedia, the free encyclopedia).

SearchResultSet.php  (mediawiki-1.31.1):SearchResultSet.php  (mediawiki-1.32.0)
skipping to change at line 27 skipping to change at line 27
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html * http://www.gnu.org/copyleft/gpl.html
* *
* @file * @file
* @ingroup Search * @ingroup Search
*/ */
/** /**
* @ingroup Search * @ingroup Search
*/ */
class SearchResultSet { class SearchResultSet implements Countable, IteratorAggregate {
/** /**
* Types of interwiki results * Types of interwiki results
*/ */
/** /**
* Results that are displayed only together with existing main wiki resul ts * Results that are displayed only together with existing main wiki resul ts
* @var int * @var int
*/ */
const SECONDARY_RESULTS = 0; const SECONDARY_RESULTS = 0;
/** /**
* Results that can displayed even if no existing main wiki results exist * Results that can displayed even if no existing main wiki results exist
skipping to change at line 57 skipping to change at line 56
* Lists titles of the result set, in the same order as results. * Lists titles of the result set, in the same order as results.
* @var Title[] * @var Title[]
*/ */
private $titles; private $titles;
/** /**
* Cache of results - serialization of the result iterator * Cache of results - serialization of the result iterator
* as an array. * as an array.
* @var SearchResult[] * @var SearchResult[]
*/ */
private $results; protected $results;
/** /**
* Set of result's extra data, indexed per result id * Set of result's extra data, indexed per result id
* and then per data item name. * and then per data item name.
* The structure is: * The structure is:
* PAGE_ID => [ augmentor name => data, ... ] * PAGE_ID => [ augmentor name => data, ... ]
* @var array[] * @var array[]
*/ */
protected $extraData = []; protected $extraData = [];
public function __construct( $containedSyntax = false ) { /**
* @var boolean True when there are more pages of search results availabl
e.
*/
private $hasMoreResults;
/**
* @var ArrayIterator|null Iterator supporting BC iteration methods
*/
private $bcIterator;
/**
* @param bool $containedSyntax True when query is not requesting a simpl
e
* term match
* @param bool $hasMoreResults True when there are more pages of search
* results available.
*/
public function __construct( $containedSyntax = false, $hasMoreResults =
false ) {
if ( static::class === self::class ) {
// This class will eventually be abstract. SearchEngine i
mplementations
// already have to extend this class anyways to provide t
he actual
// search results.
wfDeprecated( __METHOD__, 1.32 );
}
$this->containedSyntax = $containedSyntax; $this->containedSyntax = $containedSyntax;
$this->hasMoreResults = $hasMoreResults;
} }
/** /**
* Fetch an array of regular expression fragments for matching * Fetch an array of regular expression fragments for matching
* the search terms as parsed by this engine in a text extract. * the search terms as parsed by this engine in a text extract.
* STUB * STUB
* *
* @return array * @return array
*/ */
function termMatches() { function termMatches() {
return []; return [];
} }
function numRows() { function numRows() {
return 0; return $this->count();
}
final public function count() {
return count( $this->extractResults() );
} }
/** /**
* Some search modes return a total hit count for the query * Some search modes return a total hit count for the query
* in the entire article database. This may include pages * in the entire article database. This may include pages
* in namespaces that would not be matched on the given * in namespaces that would not be matched on the given
* settings. * settings.
* *
* Return null if no total hits number is supported. * Return null if no total hits number is supported.
* *
* @return int * @return int
*/ */
function getTotalHits() { function getTotalHits() {
return null; return null;
} }
/** /**
* Some search modes will run an alternative query that it thinks gives * Some search modes will run an alternative query that it thinks gives
* a better result than the provided search. Returns true if this has * a better result than the provided search. Returns true if this has
* occured. * occurred.
* *
* @return bool * @return bool
*/ */
function hasRewrittenQuery() { function hasRewrittenQuery() {
return false; return false;
} }
/** /**
* @return string|null The search the query was internally rewritten to, * @return string|null The search the query was internally rewritten to,
* or null when the result of the original query was returned. * or null when the result of the original query was returned.
skipping to change at line 174 skipping to change at line 200
* *
* @param int $type * @param int $type
* @return bool * @return bool
*/ */
function hasInterwikiResults( $type = self::SECONDARY_RESULTS ) { function hasInterwikiResults( $type = self::SECONDARY_RESULTS ) {
return false; return false;
} }
/** /**
* Fetches next search result, or false. * Fetches next search result, or false.
* STUB * @deprecated since 1.32; Use self::extractResults() or foreach
* FIXME: refactor as iterator, so we could use nicer interfaces.
* @return SearchResult|false * @return SearchResult|false
*/ */
function next() { public function next() {
return false; wfDeprecated( __METHOD__, '1.32' );
$it = $this->bcIterator();
$searchResult = $it->current();
$it->next();
return $searchResult ?? false;
} }
/** /**
* Rewind result set back to beginning * Rewind result set back to beginning
* @deprecated since 1.32; Use self::extractResults() or foreach
*/ */
function rewind() { 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 implement
ed. This
// class was potentially instantiated directly. It should
be
// abstract with abstract methods to enforce this but tha
t's a
// breaking change...
wfDeprecated( static::class . ' without implementing extr
actResults', '1.32' );
$this->bcIterator = new ArrayIterator( [] );
}
return $this->bcIterator;
} }
/** /**
* Frees the result set, if applicable. * Frees the result set, if applicable.
*/ */
function free() { function free() {
// ... // ...
} }
/** /**
* Did the search contain search syntax? If so, Special:Search won't off er * Did the search contain search syntax? If so, Special:Search won't off er
* the user a link to a create a page named by the search string because the * the user a link to a create a page named by the search string because the
* name would contain the search syntax. * name would contain the search syntax.
* @return bool * @return bool
*/ */
public function searchContainedSyntax() { public function searchContainedSyntax() {
return $this->containedSyntax; return $this->containedSyntax;
} }
/** /**
* @return bool True when there are more pages of search results availabl
e.
*/
public function hasMoreResults() {
return $this->hasMoreResults;
}
/**
* @param int $limit Shrink result set to $limit and flag
* if more results are available.
*/
public function shrink( $limit ) {
if ( $this->count() > $limit ) {
$this->hasMoreResults = true;
// shrinking result set for implementations that
// have not implemented extractResults and use
// the default cache location. Other implementations
// must override this as well.
if ( is_array( $this->results ) ) {
$this->results = array_slice( $this->results, 0,
$limit );
} else {
throw new \UnexpectedValueException(
"When overriding result store extending c
lasses must "
. " also override " . __METHOD__ );
}
}
}
/**
* Extract all the results in the result set as array. * Extract all the results in the result set as array.
* @return SearchResult[] * @return SearchResult[]
*/ */
public function extractResults() { public function extractResults() {
if ( is_null( $this->results ) ) { if ( is_null( $this->results ) ) {
$this->results = []; $this->results = [];
if ( $this->numRows() == 0 ) { if ( $this->numRows() == 0 ) {
// Don't bother if we've got empty result // Don't bother if we've got empty result
return $this->results; return $this->results;
} }
skipping to change at line 259 skipping to change at line 334
*/ */
public function setAugmentedData( $name, $data ) { public function setAugmentedData( $name, $data ) {
foreach ( $data as $id => $resultData ) { foreach ( $data as $id => $resultData ) {
$this->extraData[$id][$name] = $resultData; $this->extraData[$id][$name] = $resultData;
} }
} }
/** /**
* Returns extra data for specific result and store it in SearchResult ob ject. * Returns extra data for specific result and store it in SearchResult ob ject.
* @param SearchResult $result * @param SearchResult $result
* @return array|null List of data as name => value or null if none prese nt.
*/ */
public function augmentResult( SearchResult $result ) { public function augmentResult( SearchResult $result ) {
$id = $result->getTitle()->getArticleID(); $id = $result->getTitle()->getArticleID();
if ( !$id || !isset( $this->extraData[$id] ) ) { if ( $id === -1 ) {
return null; return;
} }
$result->setExtensionData( $this->extraData[$id] ); $result->setExtensionData( function () use ( $id ) {
return $this->extraData[$id]; return $this->extraData[$id] ?? [];
} );
} }
/** /**
* @return int|null The offset the current page starts at. Typically * @return int|null The offset the current page starts at. Typically
* this should be null to allow the UI to decide on its own, but in * this should be null to allow the UI to decide on its own, but in
* special cases like interleaved AB tests specifying explicitly is * special cases like interleaved AB tests specifying explicitly is
* necessary. * necessary.
*/ */
public function getOffset() { public function getOffset() {
return null; return null;
} }
final public function getIterator() {
return new ArrayIterator( $this->extractResults() );
}
} }
 End of changes. 15 change blocks. 
16 lines changed or deleted 107 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)