Merge "Hard deprecate codepaths where tidy is disabled"
[lhc/web/wiklou.git] / includes / search / SearchDatabase.php
index 1d7a4a3..54bfd28 100644 (file)
@@ -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
+        * @var IDatabase Replica database from which to read 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];
+       }
 }