parameters:
    oro_website_search.index_text_table_name: oro_website_search_text
    oro_website_search.search_history.keep_days: 30

services:
    oro_website_search.resolver.query_placeholder:
        class: 'Oro\Bundle\WebsiteSearchBundle\Resolver\QueryPlaceholderResolver'
        public: false
        arguments:
            - '@oro_website_search.placeholder_decorator'

    oro_website_search.search.engine:
        abstract: true
        arguments:
            - '@event_dispatcher'
            - '@oro_website_search.resolver.query_placeholder'
            - '@oro_website_search.provider.search_mapping'

    oro_website_search.search.indexer:
        abstract: true
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_website_search.provider.search_mapping'
            - '@oro_website_search.engine.entity_dependencies_resolver'
            - '@oro_website_search.engine.text_filtered_index_data'
            - '@oro_website_search.placeholder_decorator'
            - '@oro_website_search.indexer.input_validator'
            - '@event_dispatcher'
            - '@oro_website_search.regex_placeholder_decorator'

    oro_website_search.placeholder.registry:
        class: 'Oro\Bundle\WebsiteSearchBundle\Placeholder\PlaceholderRegistry'
        public: false

    oro_website_search.website_id.placeholder:
        class: 'Oro\Bundle\WebsiteSearchBundle\Placeholder\WebsiteIdPlaceholder'
        public: false
        arguments:
            - '@oro_website.manager'
        tags:
            - { name: website_search.placeholder }

    oro_website_search.localization_id.placeholder:
        class: 'Oro\Bundle\WebsiteSearchBundle\Placeholder\LocalizationIdPlaceholder'
        public: false
        arguments:
            - '@oro_locale.provider.current_localization'
            - '@oro_locale.manager.localization'
        tags:
            - { name: website_search.placeholder }

    oro_website_search.enum_id.placeholder:
        class: 'Oro\Bundle\WebsiteSearchBundle\Placeholder\EnumIdPlaceholder'
        public: false
        tags:
            - { name: website_search.placeholder }

    oro_website_search.mapping_configuration.provider:
        class: 'Oro\Bundle\WebsiteSearchBundle\Configuration\MappingConfigurationProvider'
        parent: oro.static_config_provider.abstract
        arguments:
            - '%kernel.cache_dir%/oro/website_search_mapping.php'
            - '%kernel.debug%'

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

    oro_website_search.engine.mapper:
        class: 'Oro\Bundle\WebsiteSearchBundle\Engine\Mapper'
        arguments:
            - '@oro_search.formatter.datetime_formatter'
        public: false

    oro_website_search.cache.mapping_configuration:
        parent: oro.data.cache
        tags:
            - { name: 'cache.pool', namespace: 'oro_website_search_mapping_configuration' }

    oro_website_search.provider.search_mapping:
        class: Oro\Bundle\SearchBundle\Provider\SearchMappingProvider
        public: false
        arguments:
            - '@event_dispatcher'
            - '@oro_website_search.mapping_configuration.provider'
            - '@oro_website_search.cache.mapping_configuration'
            - 'oro_website_search.mapping_config:'
            - "@=service('oro_website_search.engine.parameters').getEngineName()"
            - 'oro_website_search.event.website_search_mapping.configuration'

    oro_website_search.cache.website_search_mapping.warmer:
        class: Oro\Bundle\WebsiteSearchBundle\Cache\WebsiteSearchProviderCacheWarmer
        arguments:
            - '@oro_website_search.provider.search_mapping'
        tags:
            - { name: kernel.cache_warmer }

    oro_website_search.query_factory:
        class: 'Oro\Bundle\WebsiteSearchBundle\Query\Factory\WebsiteQueryFactory'
        public: true
        arguments:
            - '@oro_website_search.engine'

    oro_website_search.query_factory.composite:
        decorates: oro_search.query_factory
        class: 'Oro\Bundle\WebsiteSearchBundle\Query\Factory\CompositeQueryFactory'
        public: false
        arguments:
            - '@.inner'
            - '@oro_website_search.query_factory'

    oro_website_search.website_reindexation_on_create_delete_listener:
        class: 'Oro\Bundle\WebsiteSearchBundle\EventListener\WebsiteReindexationOnCreateDeleteListener'
        arguments:
            - '@event_dispatcher'
        tags:
            - { name: doctrine.orm.entity_listener, entity: 'Oro\Bundle\WebsiteBundle\Entity\Website', event: postPersist }
            - { name: doctrine.orm.entity_listener, entity: 'Oro\Bundle\WebsiteBundle\Entity\Website', event: preRemove }

    oro_website_search.fulltext_index_manager:
        class: 'Oro\Bundle\SearchBundle\Engine\FulltextIndexManager'
        public: true
        arguments:
            - '@doctrine.dbal.search_connection'
            - '%oro_search.drivers%'
            - '%oro_website_search.index_text_table_name%'
            - '%oro_website_search.index_text_table_name%_v_idx'

    oro_website_search.engine.entity_dependencies_resolver:
        class: 'Oro\Bundle\WebsiteSearchBundle\Resolver\EntityDependenciesResolver'
        arguments:
            - '@event_dispatcher'
            - '@oro_website_search.provider.search_mapping'

    oro_website_search.engine.index_data:
        class: 'Oro\Bundle\WebsiteSearchBundle\Engine\IndexDataProvider'
        arguments:
            - '@event_dispatcher'
            - '@oro_entity.entity_alias_resolver'
            - '@oro_website_search.placeholder_decorator'
            - '@oro_ui.html_tag_helper'
            - '@oro_website_search.helper.placeholder_helper'

    oro_website_search.engine.text_filtered_index_data:
        parent: oro_website_search.engine.index_data
        class: 'Oro\Bundle\WebsiteSearchBundle\Engine\TextFilteredIndexDataProvider'

    oro_website_search.helper.placeholder_helper:
        class: 'Oro\Bundle\WebsiteSearchBundle\Helper\PlaceholderHelper'
        arguments:
            - '@oro_website_search.placeholder.registry'
            - '@oro_website_search.provider.search_mapping'

    oro_website_search.placeholder_decorator:
        class: 'Oro\Bundle\WebsiteSearchBundle\Placeholder\PlaceholderDecorator'
        arguments:
            - '@oro_website_search.placeholder.registry'

    oro_website_search.regex_placeholder_decorator:
        class: 'Oro\Bundle\WebsiteSearchBundle\Placeholder\RegexPlaceholderDecorator'
        parent: oro_website_search.placeholder_decorator

    oro_website_search.indexer.input_validator:
        class: 'Oro\Bundle\WebsiteSearchBundle\Engine\IndexerInputValidator'
        arguments:
            - '@oro_website.website.provider'
            - '@oro_website_search.provider.search_mapping'
            - '@doctrine'
            - '@oro_website_search.reindexation_website_provider'
            - '@oro_security.token_accessor'

    oro_website_search.async.indexer.message_granularizer.reindex:
        class: 'Oro\Bundle\WebsiteSearchBundle\Engine\AsyncMessaging\ReindexMessageGranularizer'
        arguments:
            - '@oro_website_search.entity_identifier_repository'
        public: false

    oro_website_search.async.indexer:
        class: Oro\Bundle\WebsiteSearchBundle\Engine\AsyncIndexer
        arguments:
            - '@oro_website_search.indexer'
            - '@oro_message_queue.client.message_producer'
            - '@oro_website_search.indexer.input_validator'

    oro_website_search.reindex_request.listener:
        class: 'Oro\Bundle\WebsiteSearchBundle\EventListener\ReindexRequestListener'
        arguments:
            - '@oro_website_search.indexer'
            - '@oro_website_search.async.indexer'
        calls:
            - [setReindexMessageGranularizer, ['@oro_website_search.async.indexer.message_granularizer.reindex']]
        tags:
            - { name: kernel.event_listener, event: oro_website_search.reindexation_request, method: process }

    oro_website.indexation_entities_container:
        class: 'Oro\Bundle\SearchBundle\Utils\IndexationEntitiesContainer'
        public: false

    oro_website.indexation_request_listener:
        class: 'Oro\Bundle\WebsiteSearchBundle\EventListener\IndexationRequestListener'
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_website_search.provider.search_mapping'
            - '@event_dispatcher'
            - '@oro_website.indexation_entities_container'
        tags:
            - { name: doctrine.event_listener, event: onFlush }
            - { name: kernel.event_listener, event: oro.form.update_handler.before_entity_flush, method: beforeEntityFlush }
            - { name: doctrine.event_listener, event: postFlush }
            - { name: doctrine.event_listener, event: onClear }

    oro_website_search.repository.abstract:
        abstract: true
        class: 'Oro\Bundle\WebsiteSearchBundle\Query\WebsiteSearchRepository'
        arguments:
            - '@oro_website_search.query_factory'
            - '@oro_website_search.provider.search_mapping'

    oro_website_search.event_listener.website_localization_config:
        class: Oro\Bundle\WebsiteSearchBundle\EventListener\WebsiteLocalizationConfigListener
        arguments:
            - '@event_dispatcher'
        tags:
            - { name: kernel.event_listener, event: oro_config.update_after, method: onLocalizationSettingsChange }

    oro_website_search.event_listener.install_command:
        class: Oro\Bundle\SearchBundle\EventListener\Command\InstallCommandListener
        arguments:
            - '@request_stack'
            - 'oro:website-search:reindex'
        tags:
            # do reindexation of website index after reindexation of search index
            - { name: kernel.event_listener, event: installer.database_preparation.after, method: onAfterDatabasePreparation, priority: -10 }

    oro_website_search.event_listener.platform_update_command:
        class: Oro\Bundle\SearchBundle\EventListener\Command\PlatformUpdateCommandListener
        arguments:
            - 'oro:website-search:reindex'
        tags:
            # do reindexation of website index after reindexation of search index
            - { name: kernel.event_listener, event: installer.database_preparation.after, method: onAfterDatabasePreparation, priority: -10 }

    oro_website_search.migration.demo_data_fixtures_listener.reindex:
        parent: oro_platform.event_listener.data_fixtures_listener.abstract
        calls:
            - [disableListener, ['oro_website_search.reindex_request.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_website_search.reindexation_website_provider:
        class: Oro\Bundle\WebsiteSearchBundle\Provider\ReindexationWebsiteProvider
        arguments:
            - '@doctrine'

    oro_website_search.provider.placeholder_provider:
        class: Oro\Bundle\WebsiteSearchBundle\Provider\PlaceholderProvider
        arguments:
            - '@oro_website_search.placeholder_decorator'
            - '@oro_website_search.provider.search_mapping'

    oro_website_search.manager.website_context_manager:
        class: Oro\Bundle\WebsiteSearchBundle\Manager\WebsiteContextManager
        arguments:
            - '@doctrine'

    oro_website_search.placeholder.assign_id_placeholder:
        class:  Oro\Bundle\WebsiteSearchBundle\Placeholder\AssignIdPlaceholder
        public: false
        tags:
            - { name: website_search.placeholder }

    oro_website_search.placeholder.assign_type_placeholder:
        class:  Oro\Bundle\WebsiteSearchBundle\Placeholder\AssignTypePlaceholder
        public: false
        tags:
            - { name: website_search.placeholder }

    oro_website_search.multi_enum_filter:
        class: 'Oro\Bundle\WebsiteSearchBundle\Datagrid\Filter\SearchMultiEnumFilter'
        public: false
        arguments:
            - '@form.factory'
            - '@oro_filter.filter_utility'
            - '@oro_entity.manager.dictionary.api'
        tags:
            - { name: oro_search.extension.search_filter.filter, type: multi-enum }

    oro_website_search.entity_identifier_repository:
        class: Oro\Bundle\WebsiteSearchBundle\Entity\Repository\EntityIdentifierRepository
        arguments:
            - '@oro_entity.doctrine_helper'
        public: false

    oro_website_search.event_listener.entity_config:
        class: Oro\Bundle\WebsiteSearchBundle\EventListener\EntityConfigListener
        arguments:
            - '@oro_website_search.provider.search_mapping'
        tags:
            - { name: kernel.event_listener, event: oro.entity_config.post_flush, method: clearMappingCache, priority: -255 }

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

    oro_website_search.extension.no_data_messages:
        class: Oro\Bundle\WebsiteSearchBundle\Datagrid\Extension\NoDataMessagesExtension
        decorates: oro_datagrid.extension.no_data_messages
        arguments:
            - '@.inner'
            - '@oro_frontend.request.frontend_helper'
            - '@oro_website_search.provider.search_mapping'

    oro_website_search.async.message_filter.reindex:
        class: 'Oro\Bundle\WebsiteSearchBundle\Async\MessageFilter\ReindexMessageFilter'
        arguments:
            - !php/const Oro\Bundle\WebsiteSearchBundle\Async\Topic\WebsiteSearchReindexTopic::NAME
        tags:
            - { name: oro_message_queue.message_filter, topic: !php/const Oro\Bundle\WebsiteSearchBundle\Async\Topic\WebsiteSearchReindexTopic::NAME }

    oro_website_search.form.extension.remove_search_boost_attribute:
        class: 'Oro\Bundle\WebsiteSearchBundle\Form\Extension\RemoveSearchBoostAttributeExtension'
        arguments:
            - "@=service('oro_website_search.engine.parameters').getEngineName()"
            - '@oro_entity_config.provider.attribute'
            - '@oro_entity_config.registry.attribute_type'
        tags:
            - { name: form.type_extension, alias: oro_entity_config_type, extended_type: Oro\Bundle\EntityConfigBundle\Form\Type\ConfigType }

    oro_website_search.attribute.searchable_information_provider:
        class: 'Oro\Bundle\WebsiteSearchBundle\Attribute\SearchableInformationProvider'
        arguments:
            - '@oro_entity_config.config_manager'

    Oro\Bundle\WebsiteSearchBundle\EntityConfig\AttributeFieldConfiguration:
        tags:
            - oro_entity_config.validation.entity_config

    oro_website_search.event_listener.search_processing_engine_exception_listener:
        class: 'Oro\Bundle\WebsiteSearchBundle\EventListener\SearchProcessingEngineExceptionListener'
        tags:
            - { name: kernel.event_listener, event: oro_website_search.processing_engine_exception, method: process }

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

    oro_website_search.search_result_history.manager:
        class: Oro\Bundle\WebsiteSearchBundle\Manager\SearchResultHistoryManager
        arguments:
            - '@Oro\Bundle\WebsiteSearchBundle\SearchResult\Entity\Repository\SearchResultHistoryRepository'
            - '@Oro\Bundle\WebsiteSearchBundle\SearchResult\Entity\Repository\SearchTermReportRepository'
            - '@security.token_storage'
            - '@oro_website.manager'
            - '@oro_locale.helper.localization'
            - '@oro_config.manager'
        calls:
            - ['setKeepDays', ['%oro_website_search.search_history.keep_days%']]
            - ['setLogger', ['@logger']]
        tags:
            - {name: monolog.logger, channel: oro_website_search}

    oro_website_search.event_listener.search_listener:
        class: Oro\Bundle\WebsiteSearchBundle\EventListener\SearchHistoryEventListener
        abstract: true
        arguments:
            - '@oro_website_search.search_result_history.manager'
        tags:
            - { name: oro_featuretogle.feature, feature: oro_website_search_history_tracking }
