parameters:
    oro_search.index.class:                               Oro\Bundle\SearchBundle\Engine\Indexer
    oro_search.security_provider.class:                   Oro\Bundle\SearchBundle\Security\SecurityProvider
    oro_search.index_listener.class:                      Oro\Bundle\SearchBundle\EventListener\IndexListener
    oro_search.twig_extension.class:                      Oro\Bundle\SearchBundle\Twig\OroSearchExtension
    oro_search.mapper.class:                              Oro\Bundle\SearchBundle\Engine\ObjectMapper
    oro_search.provider.result_statistics_provider.class: Oro\Bundle\SearchBundle\Provider\ResultStatisticsProvider
    oro_search.formatter.result_formatter.class:          Oro\Bundle\SearchBundle\Formatter\ResultFormatter
    oro_search.prepare_result_item.listener.class:        Oro\Bundle\SearchBundle\EventListener\PrepareResultItemListener

    oro_search.entity.item.class: Oro\Bundle\SearchBundle\Entity\Item
    oro_search.entity.repository.search_index.class: Oro\Bundle\SearchBundle\Entity\Repository\SearchIndexRepository

    oro_search.extension.formatter.property.search_result_property.class: Oro\Bundle\SearchBundle\Datagrid\Extension\SearchResultProperty
    oro_search.extension.search_results.class:                            Oro\Bundle\SearchBundle\Datagrid\Extension\SearchResultsExtension
    oro_search.extension.search_filter.class:                             Oro\Bundle\SearchBundle\Datagrid\Extension\Filter\SearchFilterExtension

    oro_search.event_listener.search_results_grid_listener.class: Oro\Bundle\SearchBundle\EventListener\SearchResultsGridListener
    oro_search.event_listener.demo_data_listener.class:           Oro\Bundle\SearchBundle\EventListener\DemoDataMigrationListener
    oro_search.datasource.search.class:                           Oro\Bundle\SearchBundle\Datagrid\Datasource\SearchDatasource
    oro_search.query_factory.class:                               Oro\Bundle\SearchBundle\Query\Factory\QueryFactory

    oro_search.extension.orm_pager.class:          Oro\Bundle\SearchBundle\Datagrid\Extension\Pager\SearchPagerExtension
    oro_search.extension.pager.search.pager.class: Oro\Bundle\SearchBundle\Datagrid\Extension\Pager\IndexerPager

    oro_search.provider.search_mapping.class: Oro\Bundle\SearchBundle\Provider\SearchMappingProvider

    oro_search.cache.search_mapping_cache.class: Oro\Bundle\SearchBundle\Cache\SearchMappingCache

    # services used only for ORM search engine
    oro_search.fulltext_index_manager.class:                      Oro\Bundle\SearchBundle\Engine\FulltextIndexManager
    oro_search.event_listener.orm.fulltext_index_listener.class:  Oro\Bundle\SearchBundle\EventListener\ORM\FulltextIndexListener

    # search sorter
    oro_search.extension.search_sorter.class: Oro\Bundle\SearchBundle\Datagrid\Extension\Sorter\SearchSorterExtension

    oro_search.drivers:
        pdo_mysql: Oro\Bundle\SearchBundle\Engine\Orm\PdoMysql
        pdo_pgsql: Oro\Bundle\SearchBundle\Engine\Orm\PdoPgsql

services:
    oro_search.index:
        class:                        %oro_search.index.class%
        arguments:
            - '@doctrine.orm.entity_manager'
            - '@oro_search.search.engine'
            - '@oro_search.mapper'
            - '@oro_search.security_provider'
            - '@oro_security.search.acl_helper'
            - '@event_dispatcher'

    oro_search.security_provider:
        class:                        %oro_search.security_provider.class%
        public:                       false
        arguments:
            - "@oro_security.security_facade"
            - "@oro_security.entity_security_metadata_provider"

    oro_search.index_listener:
        class:                        %oro_search.index_listener.class%
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_search.async.indexer'
        calls:
            - [setEntitiesConfig, [%oro_search.entities_config%]]
            - [setMappingProvider,  ['@oro_search.provider.search_mapping']]
        tags:
            - { name: doctrine.event_listener, event: onFlush }
            - { name: doctrine.event_listener, event: postFlush }
            - { name: doctrine.event_listener, event: onClear }

    oro_search.twig.search_extension:
        class:                        %oro_search.twig_extension.class%
        tags:
            - { name: twig.extension }

    oro_search.mapper:
        class:                        %oro_search.mapper.class%
        arguments:                    ['@event_dispatcher', %oro_search.entities_config%]
        calls:
            - [setMappingProvider,  ['@oro_search.provider.search_mapping']]

    oro_search.provider.result_statistics_provider:
        class:                        %oro_search.provider.result_statistics_provider.class%
        arguments:
            - '@oro_search.index'
            - '@oro_entity_config.config_manager'
            - '@translator'
        lazy: true

    oro_search.formatter.result_formatter:
        class:                        %oro_search.formatter.result_formatter.class%
        arguments:                    ["@doctrine.orm.entity_manager"]

    oro_search.prepare_result_item.listener:
        class:                        %oro_search.prepare_result_item.listener.class%
        arguments:
            - '@router'
            - '@oro_search.mapper'
            - '@doctrine.orm.entity_manager'
            - '@oro_search.resolver.entity_title'
        tags:
            - { name: kernel.event_listener, event: oro_search.prepare_result_item, method: process }

    oro_search.extension.formatter.property.search_result_property:
        class: %oro_search.extension.formatter.property.search_result_property.class%
        arguments:
            - '@twig'
            - %oro_search.entities_config%
        calls:
            - [setMappingProvider,  ['@oro_search.provider.search_mapping']]
        tags:
            - { name:  oro_datagrid.extension.formatter.property, type: search-result }

    oro_search.extension.search_results:
        class: %oro_search.extension.search_results.class%
        arguments:
            - '@oro_search.formatter.result_formatter'
            - '@doctrine.orm.entity_manager'
            - '@oro_search.mapper'
            - '@event_dispatcher'
        tags:
            - { name: oro_datagrid.extension }

    oro_search.event_listener.search_results_grid_listener:
        class: %oro_search.event_listener.search_results_grid_listener.class%
        tags:
          - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.after.search-grid, method: onBuildAfter }

    oro_search.query_factory:
        class: %oro_search.query_factory.class%
        arguments:
            - '@oro_search.index'

    oro_search.datasource.search:
        class: %oro_search.datasource.search.class%
        arguments:
            - '@oro_search.query_factory'
            - '@oro_datagrid.event.dispatcher'
        tags:
            - { name: oro_datagrid.datasource, type: search }

    oro_search.extension.pager.orm.pager:
        class: %oro_search.extension.pager.search.pager.class%

    oro_search.extension.search_pager:
        class: %oro_search.extension.orm_pager.class%
        arguments:
            - '@oro_search.extension.pager.orm.pager'
        tags:
            - { name: oro_datagrid.extension }

    # services used only for ORM search engine
    oro_search.fulltext_index_manager:
        class: %oro_search.fulltext_index_manager.class%
        arguments:
            - '@doctrine.dbal.default_connection'
            - %oro_search.drivers%

    oro_search.event_listener.demo_data_listener:
        class: %oro_search.event_listener.demo_data_listener.class%
        arguments:
            - '@oro_search.async.indexer'
            - '@oro_search.index_listener'
        tags:
            - { name: kernel.event_listener, event: console.command, method: onConsoleCommand }
            - { name: kernel.event_listener, event: console.terminate, method: onConsoleTerminate }
            - { name: kernel.event_listener, event: console.exception, method: onConsoleException }

    oro_search.event_listener.orm.fulltext_index_listener:
        class: %oro_search.event_listener.orm.fulltext_index_listener.class%
        arguments:
            - %database_driver%
        tags:
            - { name: doctrine.event_listener, event: loadClassMetadata, connection: search }

    oro_search.provider.search_mapping:
        class: %oro_search.provider.search_mapping.class%
        arguments:
            - '@event_dispatcher'
            - '@doctrine.orm.default_metadata_cache'
        calls:
            - [setMappingConfig, [%oro_search.entities_config%]]

    oro_search.cache.doctrine_metadata:
        parent: oro.cache.abstract
        calls:
            - [ setNamespace, [ 'doctrine_metadata_search' ] ]

    oro_search.entity.repository.search_index:
        class: %oro_search.entity.repository.search_index.class%
        factory: ["@doctrine", getRepository]
        arguments:
            - %oro_search.entity.item.class%
            - 'search'
        calls:
            - [setRegistry,  ['@doctrine']]
        lazy: true

    oro_search.cache.search_mapping_cache:
        class: %oro_search.cache.search_mapping_cache.class%
        arguments:
            - '@oro_search.provider.search_mapping'
        tags:
            - { name: kernel.cache_warmer }

    oro_search.async.message_processor.index_entity:
        class: 'Oro\Bundle\SearchBundle\Async\IndexEntityMessageProcessor'
        arguments:
            - '@oro_search.search.engine.indexer'
            - '@doctrine'
            - '@monolog.logger'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_search.async.message_processor.index_entities_by_id:
        class: 'Oro\Bundle\SearchBundle\Async\IndexEntitiesByIdMessageProcessor'
        arguments:
            - '@oro_message_queue.client.message_producer'
            - '@monolog.logger'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_search.async.message_processor.index_entities_by_type:
        class: 'Oro\Bundle\SearchBundle\Async\IndexEntitiesByTypeMessageProcessor'
        arguments:
            - '@doctrine'
            - '@oro_message_queue.job.runner'
            - '@oro_message_queue.client.message_producer'
            - '@monolog.logger'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_search.async.message_processor.index_entities_by_range:
        class: 'Oro\Bundle\SearchBundle\Async\IndexEntitiesByRangeMessageProcessor'
        arguments:
            - '@doctrine'
            - '@oro_search.search.engine.indexer'
            - '@oro_message_queue.job.runner'
            - '@monolog.logger'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_search.async.message_processor.reindex_entity:
        class: 'Oro\Bundle\SearchBundle\Async\ReindexEntityMessageProcessor'
        arguments:
            - '@oro_search.search.engine.indexer'
            - '@oro_message_queue.job.runner'
            - '@oro_message_queue.client.message_producer'
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_search.async.indexer:
        class: 'Oro\Bundle\SearchBundle\Async\Indexer'
        arguments:
            - '@oro_message_queue.client.message_producer'
            - '@oro_entity.doctrine_helper'

    oro_search.resolver.entity_title.title_fields:
        public: false
        class: Oro\Bundle\SearchBundle\Resolver\EntityFieldsTitleResolver
        arguments:
            - '@oro_search.mapper'

    oro_search.resolver.entity_title:
        class: Oro\Bundle\SearchBundle\Resolver\EntityToStringTitleResolver
        arguments:
            - '@oro_search.resolver.entity_title.title_fields'

    oro_search.extension.search_filter:
        class: %oro_search.extension.search_filter.class%
        arguments:
            - '@oro_datagrid.configuration.provider'
            - '@translator'
        tags:
            - { name: oro_datagrid.extension }

    oro_search.extension.search_sorter:
        class: %oro_search.extension.search_sorter.class%
        tags:
            - { name: oro_datagrid.extension }

    oro_search.form.type.filter.search_string:
        class: Oro\Bundle\SearchBundle\Datagrid\Form\Type\SearchStringFilterType
        arguments: ["@translator"]
        tags:
            - { name: form.type, alias: oro_search_type_string_filter }
