* @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 ) {
}
}
+ /**
+ * @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
*
$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];
+ }
}