parameters:
    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\Bundle\SearchBundle\Engine\Indexer
        public: true
        arguments:
            - '@oro_search.search.engine'
            - '@oro_search.mapper'
            - '@oro_search.security_provider'
            - '@oro_security.search.acl_helper'

    Oro\Bundle\SearchBundle\Engine\Indexer:
        alias: oro_search.index

    oro_search.security_provider:
        class: Oro\Bundle\SearchBundle\Security\SecurityProvider
        public: false
        arguments:
            - "@security.authorization_checker"
            - "@oro_security.entity_security_metadata_provider"

    oro_search.index_listener:
        class: Oro\Bundle\SearchBundle\EventListener\IndexListener
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_search.async.indexer'
            - '@property_accessor'
        calls:
            - [setMappingProvider,  ['@oro_search.provider.search_mapping']]
            - [setDispatcher, ['@event_dispatcher']]
        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\Bundle\SearchBundle\Twig\OroSearchExtension
        public: false
        tags:
            - { name: twig.extension }

    oro_search.mapper:
        class: Oro\Bundle\SearchBundle\Engine\ObjectMapper
        arguments:
            - '@oro_search.provider.search_mapping'
            - '@property_accessor'
            - '@oro_search.handler.type_cast.type_casting_handler_registry'
            - '@oro_entity.entity_name_resolver'
            - '@oro_entity.doctrine_helper'
            - '@event_dispatcher'
            - '@oro_ui.html_tag_helper'
            - '@oro_search.formatter.datetime_formatter'

    oro_search.text_filtered_mapper:
        class: Oro\Bundle\SearchBundle\Engine\TextFilteredObjectMapper
        parent: oro_search.mapper

    oro_search.search_result_provider:
        class: Oro\Bundle\SearchBundle\Provider\SearchResultProvider
        arguments:
            - '@oro_search.index'
            - '@oro_featuretoggle.checker.feature_checker'
            - '@oro_entity_config.config_manager'
            - '@event_dispatcher'
            - '@translator'

    oro_search.formatter.result_formatter:
        class: Oro\Bundle\SearchBundle\Formatter\ResultFormatter
        arguments:
            - '@oro_entity.doctrine_helper'

    oro_search.formatter.datetime_formatter:
        class: Oro\Bundle\SearchBundle\Formatter\DateTimeFormatter
        public: false

    oro_search.prepare_result_item.listener:
        class: Oro\Bundle\SearchBundle\EventListener\PrepareResultItemListener
        arguments:
            - '@router'
            - '@oro_search.mapper'
            - '@doctrine'
            - '@oro_entity_config.config_manager'
            - '@translator'
        tags:
            - { name: kernel.event_listener, event: oro_search.prepare_result_item, method: process }

    oro_search.extension.formatter.property.search_result_property:
        class: Oro\Bundle\SearchBundle\Datagrid\Extension\SearchResultProperty
        arguments:
            - '@twig'
        calls:
            - [setMappingProvider,  ['@oro_search.provider.search_mapping']]
        tags:
            - { name: oro_datagrid.extension.formatter.property, type: search-result }

    oro_search.extension.search_results:
        class: Oro\Bundle\SearchBundle\Datagrid\Extension\SearchResultsExtension
        arguments:
            - '@oro_search.formatter.result_formatter'
            - '@oro_search.mapper'
            - '@event_dispatcher'
        tags:
            - { name: oro_datagrid.extension }

    oro_search.event_listener.search_results_grid_listener:
        class: Oro\Bundle\SearchBundle\EventListener\SearchResultsGridListener
        arguments:
            - '@oro_search.index'
            - '@oro_featuretoggle.checker.feature_checker'
        tags:
          - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.after.search-grid, method: onBuildAfter }

    oro_search.query_factory:
        class: Oro\Bundle\SearchBundle\Query\Factory\QueryFactory
        arguments:
            - '@oro_search.index'

    oro_search.datasource.search:
        class: Oro\Bundle\SearchBundle\Datagrid\Datasource\SearchDatasource
        arguments:
            - '@oro_search.query_factory'
            - '@oro_datagrid.event.dispatcher'
        tags:
            - { name: oro_datagrid.datasource, type: search }

    oro_search.extension.pager.orm.pager:
        class: Oro\Bundle\SearchBundle\Datagrid\Extension\Pager\IndexerPager

    oro_search.extension.search_pager:
        class: Oro\Bundle\SearchBundle\Datagrid\Extension\Pager\SearchPagerExtension
        arguments:
            - '@oro_search.extension.pager.orm.pager'
        tags:
            - { name: oro_datagrid.extension }

    oro_search.extension.mass_action.iterable_result_factory:
        class: Oro\Bundle\SearchBundle\Datagrid\Extension\MassAction\IterableResultFactory
        public: false
        tags:
            - { name: oro_datagrid.extension.mass_action.iterable_result_factory }

    # services used only for ORM search engine
    oro_search.fulltext_index_manager:
        class: Oro\Bundle\SearchBundle\Engine\FulltextIndexManager
        public: true
        arguments:
            - '@doctrine.dbal.search_connection'
            - '%oro_search.drivers%'
            - 'oro_search_index_text'

    oro_search.event_listener.orm.fulltext_index_listener:
        class: Oro\Bundle\SearchBundle\EventListener\ORM\FulltextIndexListener
        arguments:
            - 'oro_search_index_text'
            - '@doctrine.dbal.search_connection'
        tags:
            - { name: doctrine.event_listener, event: loadClassMetadata, connection: search }

    oro_search.mapping_configuration.provider:
        class: Oro\Bundle\SearchBundle\Configuration\MappingConfigurationProvider
        public: false
        parent: oro.static_config_provider.abstract
        arguments:
            - '%kernel.cache_dir%/oro/search_mapping.php'
            - '%kernel.debug%'

    oro_search.cache.mapping_configuration:
        public: false
        parent: oro.data.cache
        tags:
            - { name: 'cache.pool', namespace: 'oro_search_mapping_configuration' }

    oro_search.provider.search_mapping:
        class: Oro\Bundle\SearchBundle\Provider\SearchMappingProvider
        arguments:
            - '@event_dispatcher'
            - '@oro_search.mapping_configuration.provider'
            - '@oro_search.cache.mapping_configuration'
            - 'oro_search.mapping_config'
            - "@=service('oro_search.engine.parameters').getEngineName()"
            - 'oro_search.search_mapping_collect'

    oro_search.cache.search_mapping.warmer:
        class: Oro\Bundle\SearchBundle\Cache\SearchProviderCacheWarmer
        public: false
        arguments:
            - '@oro_search.provider.search_mapping'
        tags:
            - { name: kernel.cache_warmer }

    oro_search.cache.doctrine_metadata:
        public: false
        parent: oro.data.cache.without_memory_cache
        tags:
            - { name: 'cache.pool', namespace: 'doctrine_metadata_search' }

    oro_search.cache.doctrine_query:
        public: false
        parent: oro.data.cache.without_memory_cache
        tags:
            - { name: 'cache.pool', namespace: 'doctrine_query_search' }

    oro_search.entity.repository.search_index:
        alias: Oro\Bundle\SearchBundle\Entity\Repository\SearchIndexRepository

    Oro\Bundle\SearchBundle\Entity\Repository\SearchIndexRepository:
        parent: oro_entity.abstract_repository
        arguments:
            - 'Oro\Bundle\SearchBundle\Entity\Item'
            - 'search'
        calls:
            - [setRegistry,  ['@doctrine']]
            - [setDriversClasses, ['%oro_search.drivers%']]
        lazy: true
        tags:
            - { name: doctrine.repository_service }

    oro_search.async.index_entity_processor:
        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.index_entities_by_id_processor:
        class: Oro\Bundle\SearchBundle\Async\IndexEntitiesByIdMessageProcessor
        arguments:
            - '@oro_message_queue.job.runner'
            - '@oro_entity.doctrine_helper'
            - '@oro_search.search.engine.indexer'
        calls:
            - [setLogger,  ['@monolog.logger']]
        tags:
            - { name: 'oro_message_queue.client.message_processor' }

    oro_search.async.index_entities_by_type_processor:
        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.index_entities_by_range_processor:
        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.reindex_entity_processor:
        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
        # This service marked as public (origin private) for compatibility with Symfony 4. All dependencies must be refactored after BAP-17037
        public: true
        arguments:
            - '@oro_message_queue.client.message_producer'
            - '@oro_entity.doctrine_helper'
            - '@oro_search.transformer.message'

    oro_search.extension.search_filter:
        class: Oro\Bundle\SearchBundle\Datagrid\Extension\Filter\SearchFilterExtension
        arguments:
            - '@oro_datagrid.configuration.provider.raw'
            - '@oro_search.extension.search_filter_bag'
            - '@oro_filter.provider.datagrid_filters'
            - '@oro_filter.provider.filters_metadata'
            - '@oro_filter.provider.state.filters'
            - '@oro_filter.execution_context'
            - '@translator'
        tags:
            - { name: oro_datagrid.extension }

    oro_search.extension.search_filter_bag:
        class: Oro\Bundle\FilterBundle\Filter\FilterBag
        public: true
        arguments:
            - [] # filter names
            - ~ # service locator

    oro_search.extension.search_sorter:
        class: Oro\Bundle\SearchBundle\Datagrid\Extension\Sorter\SearchSorterExtension
        parent: oro_datagrid.extension.sorter.abstract
        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 }

    oro_search.form.type.filter.search_enum:
        class: Oro\Bundle\SearchBundle\Datagrid\Form\Type\SearchEnumFilterType
        tags:
            - { name: form.type, alias: oro_search_type_enum_filter }

    oro_search.form.type.filter.search_entity:
        class: Oro\Bundle\SearchBundle\Datagrid\Form\Type\SearchEntityFilterType
        arguments:
            - '@oro_entity.entity_name_resolver'
            - '@oro_locale.helper.localization'
        tags:
            - { name: form.type, alias: oro_search_type_entity_filter }

    oro_search.form.type.filter.search_boolean:
        class: Oro\Bundle\SearchBundle\Datagrid\Form\Type\SearchBooleanFilterType
        tags:
            - { name: form.type, alias: oro_search_type_boolean_filter }

    oro_search.event_listener.reindexation_options_command_listener:
        class: Oro\Bundle\SearchBundle\EventListener\Command\ReindexationOptionsCommandListener
        tags:
            - { name: kernel.event_listener, event: console.command, method: onConsoleCommand, priority: 255 }

    oro_search.event_listener.install_command:
        class: Oro\Bundle\SearchBundle\EventListener\Command\InstallCommandListener
        arguments:
            - '@request_stack'
            - 'oro:search:reindex'
        tags:
            - { name: kernel.event_listener, event: installer.database_preparation.after, method: onAfterDatabasePreparation }

    oro_search.event_listener.platform_update_command:
        class: Oro\Bundle\SearchBundle\EventListener\Command\PlatformUpdateCommandListener
        arguments:
            - 'oro:search:reindex'
        tags:
            - { name: kernel.event_listener, event: installer.database_preparation.after, method: onAfterDatabasePreparation }

    oro_search.migration.demo_data_fixtures_listener.reindex:
        parent: oro_platform.event_listener.data_fixtures_listener.abstract
        calls:
            # this listener is disabled to prevent a lot of reindex messages
            - [disableListener, ['oro_search.index_listener']]
        tags:
            - { name: kernel.event_listener, event: oro_migration.data_fixtures.pre_load, method: onPreLoad }
            - { name: kernel.event_listener, event: oro_migration.data_fixtures.post_load, method: onPostLoad }

    oro_search.utils.search_all_text:
       class: Oro\Bundle\SearchBundle\Utils\SearchAllText
       public: true
       arguments:
            - '@translator'

    oro_search.transformer.message:
        class: Oro\Bundle\SearchBundle\Transformer\MessageTransformer
        arguments:
            - '@oro_entity.doctrine_helper'
        public: false

    oro_search.event_listener.limit_results:
        class: Oro\Bundle\SearchBundle\EventListener\LimitResultsListener
        tags:
            - { name: kernel.event_listener, event: oro_search.before_search, method: onBeforeSearch, priority: -255 }

    oro_search.event_listener.search_mapping_listener:
        class: Oro\Bundle\SearchBundle\EventListener\SearchMappingListener
        public: false
        arguments:
            - '@oro_search.provider.search_mapping'
        tags:
            - { name: kernel.event_listener, event: oro.entity_extend.entity.schema.update, method: invalidateCache }

    oro_search.handler.type_cast.type_casting_handler_registry:
        class: Oro\Bundle\SearchBundle\Handler\TypeCast\TypeCastingHandlerRegistry
        arguments:
            - !tagged_iterator { tag: 'oro_search.type_cast_handler', default_index_method: 'getType' }

    Oro\Bundle\SearchBundle\Handler\TypeCast\TypeCastingHandlerRegistry:
        alias: oro_search.handler.type_cast.type_casting_handler_registry

    Oro\Bundle\SearchBundle\Handler\TypeCast\TextTypeCast:
        tags:
            - { name: 'oro_search.type_cast_handler'}

    Oro\Bundle\SearchBundle\Handler\TypeCast\IntegerTypeCast:
        tags:
            - { name: 'oro_search.type_cast_handler'}

    Oro\Bundle\SearchBundle\Handler\TypeCast\DecimalTypeCast:
        tags:
            - { name: 'oro_search.type_cast_handler' }

    Oro\Bundle\SearchBundle\Handler\TypeCast\DateTimeTypeCast:
        tags:
            - { name: 'oro_search.type_cast_handler' }

    oro_search.factory.filter.search:
        class: Oro\Bundle\FilterBundle\Factory\FilterFactory
        arguments:
            - '@oro_search.extension.search_filter_bag'

    oro_search.provider.datagrid_filters.search:
        class: Oro\Bundle\FilterBundle\Provider\DatagridFiltersProvider
        arguments:
            - '@oro_search.factory.filter.search'
            - !php/const Oro\Bundle\SearchBundle\Datagrid\Datasource\SearchDatasource::TYPE
        tags:
            - { name: oro_filter.provider.datagrid_filters }

    oro_search.importexport.filtered_entity.search_entity_identity_reader:
        class: Oro\Bundle\SearchBundle\Datagrid\FilteredEntityReader\SearchSourceFilteredEntityIdentityReader
        tags:
            - { name: oro_datagrid.filtered_entity_identity_reader}

    oro_search.formatter.decimal_flat_value_formatter:
        class: 'Oro\Bundle\SearchBundle\Formatter\DecimalFlatValueFormatter'
