From 3b0f55c492530fd1da0e925a03e36b7071825344 Mon Sep 17 00:00:00 2001 From: Justin Du Date: Sun, 3 Jan 2016 17:10:32 -0600 Subject: [PATCH] Split SearchResultSet.php classes Change autoload.php file to accomodate the split Bug: T122637 Change-Id: I3a326aa329c3be64662825ac06b169ae96b8f53c --- autoload.php | 4 +- includes/search/SearchNearMatchResultSet.php | 26 ++++++ includes/search/SearchResultSet.php | 86 -------------------- includes/search/SqlSearchResultSet.php | 60 ++++++++++++++ 4 files changed, 88 insertions(+), 88 deletions(-) create mode 100644 includes/search/SearchNearMatchResultSet.php create mode 100644 includes/search/SqlSearchResultSet.php diff --git a/autoload.php b/autoload.php index 92c5436ea0..46da116d63 100644 --- a/autoload.php +++ b/autoload.php @@ -1101,7 +1101,7 @@ $wgAutoloadLocalClasses = array( 'SearchHighlighter' => __DIR__ . '/includes/search/SearchHighlighter.php', 'SearchMssql' => __DIR__ . '/includes/search/SearchMssql.php', 'SearchMySQL' => __DIR__ . '/includes/search/SearchMySQL.php', - 'SearchNearMatchResultSet' => __DIR__ . '/includes/search/SearchResultSet.php', + 'SearchNearMatchResultSet' => __DIR__ . '/includes/search/SearchNearMatchResultSet.php', 'SearchOracle' => __DIR__ . '/includes/search/SearchOracle.php', 'SearchPostgres' => __DIR__ . '/includes/search/SearchPostgres.php', 'SearchResult' => __DIR__ . '/includes/search/SearchResult.php', @@ -1213,7 +1213,7 @@ $wgAutoloadLocalClasses = array( 'SpecialWhatLinksHere' => __DIR__ . '/includes/specials/SpecialWhatlinkshere.php', 'SqlBagOStuff' => __DIR__ . '/includes/objectcache/SqlBagOStuff.php', 'SqlDataUpdate' => __DIR__ . '/includes/deferred/SqlDataUpdate.php', - 'SqlSearchResultSet' => __DIR__ . '/includes/search/SearchResultSet.php', + 'SqlSearchResultSet' => __DIR__ . '/includes/search/SqlSearchResultSet.php', 'Sqlite' => __DIR__ . '/maintenance/sqlite.inc', 'SqliteInstaller' => __DIR__ . '/includes/installer/SqliteInstaller.php', 'SqliteMaintenance' => __DIR__ . '/maintenance/sqlite.php', diff --git a/includes/search/SearchNearMatchResultSet.php b/includes/search/SearchNearMatchResultSet.php new file mode 100644 index 0000000000..cb4f81d8b8 --- /dev/null +++ b/includes/search/SearchNearMatchResultSet.php @@ -0,0 +1,26 @@ +result = $match; + } + + public function numRows() { + return $this->result ? 1 : 0; + } + + public function next() { + if ( $this->fetched || !$this->result ) { + return false; + } + $this->fetched = true; + return SearchResult::newFromTitle( $this->result ); + } +} diff --git a/includes/search/SearchResultSet.php b/includes/search/SearchResultSet.php index 8fb04e4a91..eccd36e8eb 100644 --- a/includes/search/SearchResultSet.php +++ b/includes/search/SearchResultSet.php @@ -171,89 +171,3 @@ class SearchResultSet { return $this->containedSyntax; } } - -/** - * This class is used for different SQL-based search engines shipped with MediaWiki - * @ingroup Search - */ -class SqlSearchResultSet extends SearchResultSet { - protected $resultSet; - protected $terms; - protected $totalHits; - - function __construct( $resultSet, $terms, $total = null ) { - $this->resultSet = $resultSet; - $this->terms = $terms; - $this->totalHits = $total; - } - - function termMatches() { - return $this->terms; - } - - function numRows() { - if ( $this->resultSet === false ) { - return false; - } - - return $this->resultSet->numRows(); - } - - function next() { - if ( $this->resultSet === false ) { - return false; - } - - $row = $this->resultSet->fetchObject(); - if ( $row === false ) { - return false; - } - - return SearchResult::newFromTitle( - Title::makeTitle( $row->page_namespace, $row->page_title ) - ); - } - - function free() { - if ( $this->resultSet === false ) { - return false; - } - - $this->resultSet->free(); - } - - function getTotalHits() { - if ( !is_null( $this->totalHits ) ) { - return $this->totalHits; - } else { - // Special:Search expects a number here. - return $this->numRows(); - } - } -} - -/** - * A SearchResultSet wrapper for SearchEngine::getNearMatch - */ -class SearchNearMatchResultSet extends SearchResultSet { - private $fetched = false; - - /** - * @param Title|null $match Title if matched, else null - */ - public function __construct( $match ) { - $this->result = $match; - } - - public function numRows() { - return $this->result ? 1 : 0; - } - - public function next() { - if ( $this->fetched || !$this->result ) { - return false; - } - $this->fetched = true; - return SearchResult::newFromTitle( $this->result ); - } -} diff --git a/includes/search/SqlSearchResultSet.php b/includes/search/SqlSearchResultSet.php new file mode 100644 index 0000000000..7a6aaf75f0 --- /dev/null +++ b/includes/search/SqlSearchResultSet.php @@ -0,0 +1,60 @@ +resultSet = $resultSet; + $this->terms = $terms; + $this->totalHits = $total; + } + + function termMatches() { + return $this->terms; + } + + function numRows() { + if ( $this->resultSet === false ) { + return false; + } + + return $this->resultSet->numRows(); + } + + function next() { + if ( $this->resultSet === false ) { + return false; + } + + $row = $this->resultSet->fetchObject(); + if ( $row === false ) { + return false; + } + + return SearchResult::newFromTitle( + Title::makeTitle( $row->page_namespace, $row->page_title ) + ); + } + + function free() { + if ( $this->resultSet === false ) { + return false; + } + + $this->resultSet->free(); + } + + function getTotalHits() { + if ( !is_null( $this->totalHits ) ) { + return $this->totalHits; + } else { + // Special:Search expects a number here. + return $this->numRows(); + } + } +} -- 2.20.1