- Issue created by @muriqui
- Status changed to Needs review
11 months ago 8:09pm 22 January 2024
Currently, SearchFactory is implemented as a class with two static methods—::search
and ::parseResult
—which are only called by SearchApiElasticsearchBackend. If it were instead implemented as a service (with its methods becoming non-static public), this would allow other modules to override the factory to customize the search logic as needed.
For example, a custom module author might want to extend SearchBuilder in order to support additional ElasticSearch features. If SearchFactory were a service (elasticsearch_connector.search_factory
) they could achieve this like so:
class MyModuleServiceProvider extends ServiceProviderBase {
public function alter(ContainerBuilder $container) {
$definition = $container->getDefinition('elasticsearch_connector.search_factory');
$definition->setClass('Drupal\my_module\MyModuleSearchFactory');
}
}
class MyModuleSearchFactory extends SearchFactory {
public function search(QueryInterface $query) {
$builder = new MyModuleSearchBuilder($query);
return $builder->build();
}
}
class MyModuleSearchBuilder extends SearchBuilder {
public function build() {
// Do cool stuff here.
}
}
Calls to SearchFactory::search
and SearchFactory::parseResult
would need to be changed to \Drupal::service('elasticsearch_connector.search_factory')->search
and \Drupal::service('elasticsearch_connector.search_factory')->parseResult
.
Needs review
7.0
Elasticsearch Connector Search API