Merge "Special:Upload should not crash on failing previews"
[mediawiki.git] / includes / search / SearchEngineFactory.php
bloba767bc313097a83e14937852f3b1dd3a60c6078c
1 <?php
3 /**
4 * Factory class for SearchEngine.
5 * Allows to create engine of the specific type.
6 */
7 class SearchEngineFactory {
8 /**
9 * Configuration for SearchEngine classes.
10 * @var SearchEngineConfig
12 private $config;
14 public function __construct( SearchEngineConfig $config ) {
15 $this->config = $config;
18 /**
19 * Create SearchEngine of the given type.
20 * @param string $type
21 * @return SearchEngine
23 public function create( $type = null ) {
24 $dbr = null;
26 $configType = $this->config->getSearchType();
27 $alternatives = $this->config->getSearchTypes();
29 if ( $type && in_array( $type, $alternatives ) ) {
30 $class = $type;
31 } elseif ( $configType !== null ) {
32 $class = $configType;
33 } else {
34 $dbr = wfGetDB( DB_REPLICA );
35 $class = self::getSearchEngineClass( $dbr );
38 $search = new $class( $dbr );
39 return $search;
42 /**
43 * @param IDatabase $db
44 * @return string SearchEngine subclass name
45 * @since 1.28
47 public static function getSearchEngineClass( IDatabase $db ) {
48 switch ( $db->getType() ) {
49 case 'sqlite':
50 return 'SearchSqlite';
51 case 'mysql':
52 return 'SearchMySQL';
53 case 'postgres':
54 return 'SearchPostgres';
55 case 'mssql':
56 return 'SearchMssql';
57 case 'oracle':
58 return 'SearchOracle';
59 default:
60 return 'SearchEngineDummy';