X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fsearch%2FSearchDatabase.php;h=93f8d2301f473c6301852646cb99253f2eaf52f1;hb=098e23fb9dc76bc715095f51c9547986874eea37;hp=643c2c13648dc4381f538aa8f21bf4462957be6d;hpb=36395150104588f2afea866c330b683e4329fa48;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/search/SearchDatabase.php b/includes/search/SearchDatabase.php index 643c2c1364..93f8d2301f 100644 --- a/includes/search/SearchDatabase.php +++ b/includes/search/SearchDatabase.php @@ -28,14 +28,14 @@ use Wikimedia\Rdbms\IDatabase; * @ingroup Search * @since 1.23 */ -class SearchDatabase extends SearchEngine { +abstract class SearchDatabase extends SearchEngine { /** * @var IDatabase Slave database for reading from for results */ protected $db; /** - * @param IDatabase $db The database to search from + * @param IDatabase|null $db The database to search from */ public function __construct( IDatabase $db = null ) { if ( $db ) { @@ -45,6 +45,38 @@ class SearchDatabase extends SearchEngine { } } + /** + * @param string $term + * @return SearchResultSet|Status|null + */ + final public function doSearchText( $term ) { + return $this->doSearchTextInDB( $this->extractNamespacePrefix( $term ) ); + } + + /** + * Perform a full text search query and return a result set. + * + * @param string $term Raw search term + * @return SqlSearchResultSet + */ + abstract protected function doSearchTextInDB( $term ); + + /** + * @param string $term + * @return SearchResultSet|null + */ + final public function doSearchTitle( $term ) { + return $this->doSearchTitleInDB( $this->extractNamespacePrefix( $term ) ); + } + + /** + * Perform a title-only search query and return a result set. + * + * @param string $term Raw search term + * @return SqlSearchResultSet + */ + abstract protected function doSearchTitleInDB( $term ); + /** * Return a 'cleaned up' search string * @@ -58,4 +90,19 @@ class SearchDatabase extends SearchEngine { $lc = $this->legalSearchChars( self::CHARS_ALL ); return trim( preg_replace( "/[^{$lc}]/", " ", $text ) ); } + + /** + * Extract the optional namespace prefix and set self::namespaces + * accordingly and return the query string + * @param string $term + * @return string the query string without any namespace prefix + */ + final protected function extractNamespacePrefix( $term ) { + $queryAndNs = self::parseNamespacePrefixes( $term ); + if ( $queryAndNs === false ) { + return $term; + } + $this->namespaces = $queryAndNs[1]; + return $queryAndNs[0]; + } }