4 * Factory class for SearchEngine.
5 * Allows to create engine of the specific type.
7 class SearchEngineFactory
{
9 * Configuration for SearchEngine classes.
10 * @var SearchEngineConfig
14 public function __construct( SearchEngineConfig
$config ) {
15 $this->config
= $config;
19 * Create SearchEngine of the given type.
21 * @return SearchEngine
23 public function create( $type = null ) {
26 $configType = $this->config
->getSearchType();
27 $alternatives = $this->config
->getSearchTypes();
29 if ( $type && in_array( $type, $alternatives ) ) {
31 } elseif ( $configType !== null ) {
34 $dbr = wfGetDB( DB_REPLICA
);
35 $class = self
::getSearchEngineClass( $dbr );
38 $search = new $class( $dbr );
43 * @param IDatabase $db
44 * @return string SearchEngine subclass name
47 public static function getSearchEngineClass( IDatabase
$db ) {
48 switch ( $db->getType() ) {
50 return 'SearchSqlite';
54 return 'SearchPostgres';
58 return 'SearchOracle';
60 return 'SearchEngineDummy';