X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fsearch%2FSearchDatabase.php;h=93f8d2301f473c6301852646cb99253f2eaf52f1;hb=09b4f0db06e8e2aafa42b4240d0ca66eb0116736;hp=1d7a4a338ec6860c343760c1dc22a746fb6002b3;hpb=187ada1cf404f5943f8962c6241aa53eb3fa139c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/search/SearchDatabase.php b/includes/search/SearchDatabase.php index 1d7a4a338e..93f8d2301f 100644 --- a/includes/search/SearchDatabase.php +++ b/includes/search/SearchDatabase.php @@ -28,15 +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; /** - * Constructor - * @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 ) { @@ -46,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 * @@ -59,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]; + } }