blob: 8cdca571aee2e6c5025a87f22dfd42b4b33c02fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<?php
use Wikimedia\Rdbms\IDatabase;
/**
* Factory class for SearchEngine.
* Allows to create engine of the specific type.
*/
class SearchEngineFactory {
/**
* Configuration for SearchEngine classes.
* @var SearchEngineConfig
*/
private $config;
public function __construct( SearchEngineConfig $config ) {
$this->config = $config;
}
/**
* Create SearchEngine of the given type.
* @param string $type
* @return SearchEngine
*/
public function create( $type = null ) {
$dbr = null;
$configType = $this->config->getSearchType();
$alternatives = $this->config->getSearchTypes();
if ( $type && in_array( $type, $alternatives ) ) {
$class = $type;
} elseif ( $configType !== null ) {
$class = $configType;
} else {
$dbr = wfGetDB( DB_REPLICA );
$class = self::getSearchEngineClass( $dbr );
}
$search = new $class( $dbr );
return $search;
}
/**
* @param IDatabase $db
* @return string SearchEngine subclass name
* @since 1.28
*/
public static function getSearchEngineClass( IDatabase $db ) {
switch ( $db->getType() ) {
case 'sqlite':
return SearchSqlite::class;
case 'mysql':
return SearchMySQL::class;
case 'postgres':
return SearchPostgres::class;
case 'mssql':
return SearchMssql::class;
case 'oracle':
return SearchOracle::class;
default:
return SearchEngineDummy::class;
}
}
}
|