Skip to content
Snippets Groups Projects
Commit 78406cd9 authored by Yuriy Gerasimov's avatar Yuriy Gerasimov Committed by Nikolay Ignatov
Browse files

Issue #3065334 by ygerasimov: Remove hardcoded IndexFactory

parent 5c2cc5f6
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,6 @@ use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory\FilterFactory;
use Drupal\elasticsearch_connector\ElasticSearch\Parameters\Factory\IndexFactory;
use Drupal\search_api\ParseMode\ParseModeInterface;
use Drupal\search_api\Query\Condition;
use Drupal\search_api\Query\ConditionGroupInterface;
......@@ -68,7 +67,9 @@ class SearchBuilder {
*/
public function build() {
// Query options.
$params = IndexFactory::index($this->index, TRUE);
$indexFactory = \Drupal::service('elasticsearch_connector.index_factory');
$params = $indexFactory->index($this->index, TRUE);
$query_options = $this->getSearchQueryOptions();
// Set the size and from parameters.
......@@ -125,7 +126,8 @@ class SearchBuilder {
$this->query->setOption('ElasticParams', $params);
// Allow other modules to alter index config before we create it.
$indexName = IndexFactory::getIndexName($this->index);
$indexFactory = \Drupal::service('elasticsearch_connector.index_factory');
$indexName = $indexFactory->getIndexName($this->index);
$dispatcher = \Drupal::service('event_dispatcher');
$buildSearchParamsEvent = new BuildSearchParamsEvent($params, $indexName);
$event = $dispatcher->dispatch(BuildSearchParamsEvent::BUILD_QUERY, $buildSearchParamsEvent);
......@@ -259,7 +261,9 @@ class SearchBuilder {
];
// Allow other modules to alter index config before we create it.
$indexName = IndexFactory::getIndexName($this->index);
$indexFactory = \Drupal::service('elasticsearch_connector.index_factory');
$indexName = $indexFactory->getIndexName($this->index);
$dispatcher = \Drupal::service('event_dispatcher');
$prepareSearchQueryEvent = new PrepareSearchQueryEvent($elasticSearchQuery, $indexName);
$event = $dispatcher->dispatch(PrepareSearchQueryEvent::PREPARE_QUERY, $prepareSearchQueryEvent);
......
......@@ -37,7 +37,7 @@ class IndexFactory {
*/
public static function index(IndexInterface $index, $with_type = FALSE) {
$params = [];
$params['index'] = IndexFactory::getIndexName($index);
$params['index'] = static::getIndexName($index);
if ($with_type) {
$params['type'] = $index->id();
......@@ -55,7 +55,7 @@ class IndexFactory {
* @return array
*/
public static function create(IndexInterface $index) {
$indexName = IndexFactory::getIndexName($index);
$indexName = static::getIndexName($index);
$indexConfig = [
'index' => $indexName,
'body' => [
......@@ -111,7 +111,7 @@ class IndexFactory {
* index.
*/
public static function bulkIndex(IndexInterface $index, array $items) {
$params = IndexFactory::index($index, TRUE);
$params = static::index($index, TRUE);
foreach ($items as $id => $item) {
$data = [
......@@ -172,7 +172,7 @@ class IndexFactory {
* Parameters required to create an index mapping.
*/
public static function mapping(IndexInterface $index) {
$params = IndexFactory::index($index, TRUE);
$params = static::index($index, TRUE);
$properties = [
'id' => [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment