Clean up database-backed SearchResultSets
SqlSearchResultSet basically handles all of the work in a DB-agnostic manner. Remove specific implementations for MySQL, Mssql and Sqlite Change-Id: Iae3fd5cc40dfbc50917be73d7ace668681e4148a
This commit is contained in:
parent
ca895b7072
commit
ff00b052ce
7 changed files with 30 additions and 85 deletions
|
|
@ -887,8 +887,6 @@ $wgAutoloadLocalClasses = array(
|
|||
'RevisionDeleteUser' => 'includes/revisiondelete/RevisionDeleteUser.php',
|
||||
|
||||
# includes/search
|
||||
'MssqlSearchResultSet' => 'includes/search/SearchMssql.php',
|
||||
'MySQLSearchResultSet' => 'includes/search/SearchMySQL.php',
|
||||
'PostgresSearchResult' => 'includes/search/SearchPostgres.php',
|
||||
'PostgresSearchResultSet' => 'includes/search/SearchPostgres.php',
|
||||
'SearchDatabase' => 'includes/search/SearchDatabase.php',
|
||||
|
|
@ -904,7 +902,6 @@ $wgAutoloadLocalClasses = array(
|
|||
'SearchResultSet' => 'includes/search/SearchResultSet.php',
|
||||
'SearchResultTooMany' => 'includes/search/SearchEngine.php',
|
||||
'SearchSqlite' => 'includes/search/SearchSqlite.php',
|
||||
'SqliteSearchResultSet' => 'includes/search/SearchSqlite.php',
|
||||
'SqlSearchResultSet' => 'includes/search/SearchResultSet.php',
|
||||
|
||||
# includes/site
|
||||
|
|
|
|||
|
|
@ -30,24 +30,24 @@ class SearchMssql extends SearchDatabase {
|
|||
* Perform a full text search query and return a result set.
|
||||
*
|
||||
* @param string $term Raw search term
|
||||
* @return MssqlSearchResultSet
|
||||
* @return SqlSearchResultSet
|
||||
* @access public
|
||||
*/
|
||||
function searchText( $term ) {
|
||||
$resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), true ) ) );
|
||||
return new MssqlSearchResultSet( $resultSet, $this->searchTerms );
|
||||
return new SqlSearchResultSet( $resultSet, $this->searchTerms );
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a title-only search query and return a result set.
|
||||
*
|
||||
* @param string $term Raw search term
|
||||
* @return MssqlSearchResultSet
|
||||
* @return SqlSearchResultSet
|
||||
* @access public
|
||||
*/
|
||||
function searchTitle( $term ) {
|
||||
$resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), false ) ) );
|
||||
return new MssqlSearchResultSet( $resultSet, $this->searchTerms );
|
||||
return new SqlSearchResultSet( $resultSet, $this->searchTerms );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -204,29 +204,3 @@ class SearchMssql extends SearchDatabase {
|
|||
return $this->db->query( $sql, 'SearchMssql::updateTitle' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup Search
|
||||
*/
|
||||
class MssqlSearchResultSet extends SearchResultSet {
|
||||
function __construct( $resultSet, $terms ) {
|
||||
$this->mResultSet = $resultSet;
|
||||
$this->mTerms = $terms;
|
||||
}
|
||||
|
||||
function termMatches() {
|
||||
return $this->mTerms;
|
||||
}
|
||||
|
||||
function numRows() {
|
||||
return $this->mResultSet->numRows();
|
||||
}
|
||||
|
||||
function next() {
|
||||
$row = $this->mResultSet->fetchObject();
|
||||
if ( $row === false ) {
|
||||
return false;
|
||||
}
|
||||
return new SearchResult( $row );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ class SearchMySQL extends SearchDatabase {
|
|||
* Perform a full text search query and return a result set.
|
||||
*
|
||||
* @param string $term Raw search term
|
||||
* @return MySQLSearchResultSet
|
||||
* @return SqlSearchResultSet
|
||||
*/
|
||||
function searchText( $term ) {
|
||||
return $this->searchInternal( $term, true );
|
||||
|
|
@ -163,7 +163,7 @@ class SearchMySQL extends SearchDatabase {
|
|||
* Perform a title-only search query and return a result set.
|
||||
*
|
||||
* @param string $term Raw search term
|
||||
* @return MySQLSearchResultSet
|
||||
* @return SqlSearchResultSet
|
||||
*/
|
||||
function searchTitle( $term ) {
|
||||
return $this->searchInternal( $term, false );
|
||||
|
|
@ -199,7 +199,7 @@ class SearchMySQL extends SearchDatabase {
|
|||
$totalResult->free();
|
||||
}
|
||||
|
||||
return new MySQLSearchResultSet( $resultSet, $this->searchTerms, $total );
|
||||
return new SqlSearchResultSet( $resultSet, $this->searchTerms, $total );
|
||||
}
|
||||
|
||||
public function supports( $feature ) {
|
||||
|
|
@ -452,17 +452,3 @@ class SearchMySQL extends SearchDatabase {
|
|||
return self::$mMinSearchLength;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup Search
|
||||
*/
|
||||
class MySQLSearchResultSet extends SqlSearchResultSet {
|
||||
function __construct( $resultSet, $terms, $totalHits = null ) {
|
||||
parent::__construct( $resultSet, $terms );
|
||||
$this->mTotalHits = $totalHits;
|
||||
}
|
||||
|
||||
function getTotalHits() {
|
||||
return $this->mTotalHits;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ class SearchOracle extends SearchDatabase {
|
|||
}
|
||||
|
||||
$resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), false ) ) );
|
||||
return new MySQLSearchResultSet( $resultSet, $this->searchTerms );
|
||||
return new SqlSearchResultSet( $resultSet, $this->searchTerms );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -222,12 +222,8 @@ class PostgresSearchResult extends SearchResult {
|
|||
* @ingroup Search
|
||||
*/
|
||||
class PostgresSearchResultSet extends SqlSearchResultSet {
|
||||
function __construct( $resultSet, $terms ) {
|
||||
parent::__construct( $resultSet, $terms );
|
||||
}
|
||||
|
||||
function next() {
|
||||
$row = $this->mResultSet->fetchObject();
|
||||
$row = $this->resultSet->fetchObject();
|
||||
if ( $row === false ) {
|
||||
return false;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -139,32 +139,34 @@ class SearchResultSet {
|
|||
* @ingroup Search
|
||||
*/
|
||||
class SqlSearchResultSet extends SearchResultSet {
|
||||
protected $resultSet;
|
||||
protected $terms;
|
||||
protected $totalHits;
|
||||
|
||||
protected $mResultSet;
|
||||
|
||||
function __construct( $resultSet, $terms ) {
|
||||
$this->mResultSet = $resultSet;
|
||||
$this->mTerms = $terms;
|
||||
function __construct( $resultSet, $terms, $total = null ) {
|
||||
$this->resultSet = $resultSet;
|
||||
$this->terms = $terms;
|
||||
$this->totalHits = $total;
|
||||
}
|
||||
|
||||
function termMatches() {
|
||||
return $this->mTerms;
|
||||
return $this->terms;
|
||||
}
|
||||
|
||||
function numRows() {
|
||||
if ( $this->mResultSet === false ) {
|
||||
if ( $this->resultSet === false ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->mResultSet->numRows();
|
||||
return $this->resultSet->numRows();
|
||||
}
|
||||
|
||||
function next() {
|
||||
if ( $this->mResultSet === false ) {
|
||||
if ( $this->resultSet === false ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$row = $this->mResultSet->fetchObject();
|
||||
$row = $this->resultSet->fetchObject();
|
||||
if ( $row === false ) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -173,11 +175,15 @@ class SqlSearchResultSet extends SearchResultSet {
|
|||
}
|
||||
|
||||
function free() {
|
||||
if ( $this->mResultSet === false ) {
|
||||
if ( $this->resultSet === false ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->mResultSet->free();
|
||||
$this->resultSet->free();
|
||||
}
|
||||
|
||||
function getTotalHits() {
|
||||
return $this->totalHits;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ class SearchSqlite extends SearchDatabase {
|
|||
* Perform a full text search query and return a result set.
|
||||
*
|
||||
* @param string $term Raw search term
|
||||
* @return SqliteSearchResultSet
|
||||
* @return SqlSearchResultSet
|
||||
*/
|
||||
function searchText( $term ) {
|
||||
return $this->searchInternal( $term, true );
|
||||
|
|
@ -155,7 +155,7 @@ class SearchSqlite extends SearchDatabase {
|
|||
* Perform a title-only search query and return a result set.
|
||||
*
|
||||
* @param string $term Raw search term
|
||||
* @return SqliteSearchResultSet
|
||||
* @return SqlSearchResultSet
|
||||
*/
|
||||
function searchTitle( $term ) {
|
||||
return $this->searchInternal( $term, false );
|
||||
|
|
@ -181,7 +181,7 @@ class SearchSqlite extends SearchDatabase {
|
|||
$totalResult->free();
|
||||
}
|
||||
|
||||
return new SqliteSearchResultSet( $resultSet, $this->searchTerms, $total );
|
||||
return new SqlSearchResultSet( $resultSet, $this->searchTerms, $total );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -303,17 +303,3 @@ class SearchSqlite extends SearchDatabase {
|
|||
__METHOD__ );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup Search
|
||||
*/
|
||||
class SqliteSearchResultSet extends SqlSearchResultSet {
|
||||
function __construct( $resultSet, $terms, $totalHits = null ) {
|
||||
parent::__construct( $resultSet, $terms );
|
||||
$this->mTotalHits = $totalHits;
|
||||
}
|
||||
|
||||
function getTotalHits() {
|
||||
return $this->mTotalHits;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue