MediaWiki  master
SearchEngineFactory.php
Go to the documentation of this file.
1 <?php
2 
5 use Wikimedia\ObjectFactory;
8 
18  private $config;
19 
21  private $hookContainer;
22 
24  $this->config = $config;
25  $this->hookContainer = $hookContainer;
26  }
27 
34  public function create( $type = null ) {
35  $configuredClass = $this->config->getSearchType();
36  $alternativesClasses = $this->config->getSearchTypes();
37 
38  $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
39  if ( $type !== null && in_array( $type, $alternativesClasses ) ) {
40  $class = $type;
41  } elseif ( $configuredClass !== null ) {
42  $class = $configuredClass;
43  } else {
44  $class = self::getSearchEngineClass( $lb );
45  }
46 
47  $mappings = $this->config->getSearchMappings();
48 
49  if ( isset( $mappings[$class] ) ) {
50  $spec = $mappings[$class];
51  } else {
52  // Convert non mapped classes to ObjectFactory spec
53  $spec = [ 'class' => $class ];
54  }
55 
56  $args = [];
57 
58  if ( isset( $spec['class'] ) && is_subclass_of( $spec['class'], SearchDatabase::class ) ) {
59  $args['extraArgs'][] = $lb;
60  }
61 
63  $engine = ObjectFactory::getObjectFromSpec( $spec, $args );
64  $engine->setHookContainer( $this->hookContainer );
65  return $engine;
66  }
67 
73  public static function getSearchEngineClass( $dbOrLb ) {
74  $type = ( $dbOrLb instanceof IDatabase )
75  ? $dbOrLb->getType()
76  : $dbOrLb->getServerType( $dbOrLb->getWriterIndex() );
77 
78  switch ( $type ) {
79  case 'sqlite':
80  return SearchSqlite::class;
81  case 'mysql':
82  return SearchMySQL::class;
83  case 'postgres':
84  return SearchPostgres::class;
85  default:
86  return SearchEngineDummy::class;
87  }
88  }
89 }
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:146
SearchEngineFactory\$hookContainer
HookContainer $hookContainer
Definition: SearchEngineFactory.php:21
SearchEngineFactory\$config
SearchEngineConfig $config
Configuration for SearchEngine classes.
Definition: SearchEngineFactory.php:18
SearchEngineFactory
Factory class for SearchEngine.
Definition: SearchEngineFactory.php:13
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
SearchEngineFactory\getSearchEngineClass
static getSearchEngineClass( $dbOrLb)
Definition: SearchEngineFactory.php:73
SearchEngineFactory\__construct
__construct(SearchEngineConfig $config, HookContainer $hookContainer)
Definition: SearchEngineFactory.php:23
$args
if( $line===false) $args
Definition: mcc.php:124
SearchEngineConfig
Configuration handling class for SearchEngine.
Definition: SearchEngineConfig.php:12
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:44
SearchEngineFactory\create
create( $type=null)
Create SearchEngine of the given type.
Definition: SearchEngineFactory.php:34
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
$type
$type
Definition: testCompression.php:52