Add ISearchResultSet
[lhc/web/wiklou.git] / includes / search / SearchDatabase.php
index 54bfd28..0c5d4da 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 use Wikimedia\Rdbms\IDatabase;
+use Wikimedia\Rdbms\ILoadBalancer;
 
 /**
  * Base search engine base class for database-backed searches
@@ -29,25 +30,28 @@ use Wikimedia\Rdbms\IDatabase;
  * @since 1.23
  */
 abstract class SearchDatabase extends SearchEngine {
+       /** @var ILoadBalancer */
+       protected $lb;
+       /** @var IDatabase (backwards compatibility) */
+       protected $db;
+
        /**
-        * @var IDatabase Replica database from which to read results
+        * @var string[] search terms
         */
-       protected $db;
+       protected $searchTerms = [];
 
        /**
-        * @param IDatabase|null $db The database to search from
+        * @param ILoadBalancer $lb The load balancer for the DB cluster to search on
         */
-       public function __construct( IDatabase $db = null ) {
-               if ( $db ) {
-                       $this->db = $db;
-               } else {
-                       $this->db = wfGetDB( DB_REPLICA );
-               }
+       public function __construct( ILoadBalancer $lb ) {
+               $this->lb = $lb;
+               // @TODO: remove this deprecated field in 1.35
+               $this->db = $lb->getLazyConnectionRef( DB_REPLICA ); // b/c
        }
 
        /**
         * @param string $term
-        * @return SearchResultSet|Status|null
+        * @return ISearchResultSet|Status|null
         */
        final public function doSearchText( $term ) {
                return $this->doSearchTextInDB( $this->extractNamespacePrefix( $term ) );
@@ -63,7 +67,7 @@ abstract class SearchDatabase extends SearchEngine {
 
        /**
         * @param string $term
-        * @return SearchResultSet|null
+        * @return ISearchResultSet|null
         */
        final public function doSearchTitle( $term ) {
                return $this->doSearchTitleInDB( $this->extractNamespacePrefix( $term ) );