<?xml version="1.0"?>
<!--
/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Elastic Search Base for Magento 2
 */-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="amasty_elastic" translate="label" type="text" sortOrder="51219" showInDefault="1" showInWebsite="1" showInStore="1">
            <resource>Amasty_ElasticSearch::config</resource>
            <class>separator-top</class>
            <label>Elastic Search</label>
            <tab>amasty</tab>
            <group id="connection" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Connection</label>
                <field id="engine" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Search Engine</label>
                    <source_model>Magento\Search\Model\Adminhtml\System\Config\Source\Engine</source_model>
                    <tooltip><![CDATA[<img src="Amasty_ElasticSearch::images/scheme.png">]]></tooltip>
                </field>
                <field id="server_hostname" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Elasticsearch Server Hostname</label>
                    <depends>
                        <field id="engine" separator=",">amasty_elastic,amasty_elastic_8,amasty_elastic_opensearch</field>
                    </depends>
                </field>
                <field id="server_port" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Elasticsearch Server Port</label>
                    <validate>validate-greater-than-zero</validate>
                    <depends>
                        <field id="engine" separator=",">amasty_elastic,amasty_elastic_8,amasty_elastic_opensearch</field>
                    </depends>
                </field>
                <field id="index_prefix" translate="label" type="text" sortOrder="63" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Elasticsearch Index Prefix</label>
                    <depends>
                        <field id="engine" separator=",">amasty_elastic,amasty_elastic_8,amasty_elastic_opensearch</field>
                    </depends>
                </field>
                <field id="enable_auth" translate="label" type="select" sortOrder="64" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Enable Elasticsearch HTTP Auth</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <depends>
                        <field id="engine" separator=",">amasty_elastic,amasty_elastic_8,amasty_elastic_opensearch</field>
                    </depends>
                </field>
                <field id="username" translate="label" type="text" sortOrder="65" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Elasticsearch HTTP Username</label>
                    <depends>
                        <field id="engine" separator=",">amasty_elastic,amasty_elastic_8,amasty_elastic_opensearch</field>
                        <field id="enable_auth">1</field>
                    </depends>
                </field>
                <field id="password" translate="label" type="password" sortOrder="66" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Elasticsearch HTTP Password</label>
                    <depends>
                        <field id="engine" separator=",">amasty_elastic,amasty_elastic_8,amasty_elastic_opensearch</field>
                        <field id="enable_auth">1</field>
                    </depends>
                </field>
                <field id="server_timeout" translate="label" type="text" sortOrder="67" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Elasticsearch Server Timeout</label>
                    <validate>validate-greater-than-zero</validate>
                    <depends>
                        <field id="engine" separator=",">amasty_elastic,amasty_elastic_8,amasty_elastic_opensearch</field>
                    </depends>
                </field>
                <field id="custom_analyzer" translate="label" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Custom Analyzer</label>
                    <source_model>Amasty\ElasticSearch\Model\Source\CustomAnalyzer</source_model>
                    <depends>
                        <field id="engine" separator=",">amasty_elastic,amasty_elastic_8,amasty_elastic_opensearch</field>
                    </depends>
                </field>
                <field id="tokenizer" translate="label comment" type="select" sortOrder="75"
                       showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Elasticsearch Tokenizers</label>
                    <comment><![CDATA[You can find more tokenizer reference information
                        <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-tokenizers.html#_word_oriented_tokenizers" target="_blank">here</a>.]]></comment>
                    <source_model>Amasty\ElasticSearch\Model\Source\Tokenizer</source_model>
                    <frontend_model>Amasty\ElasticSearch\Block\Adminhtml\System\Config\Tokenizer</frontend_model>
                    <depends>
                        <field id="engine" separator=",">amasty_elastic,amasty_elastic_8,amasty_elastic_opensearch</field>
                        <field id="custom_analyzer">disabled</field>
                    </depends>
                </field>
                <field id="test_connect" translate="button_label" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label/>
                    <button_label>Test Connection</button_label>
                    <frontend_model>Amasty\ElasticSearch\Block\Adminhtml\System\Config\ConnectionChecker</frontend_model>
                    <depends>
                        <field id="engine" separator=",">amasty_elastic,amasty_elastic_8,amasty_elastic_opensearch</field>
                    </depends>
                </field>
            </group>
            <group id="catalog" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" >
                <label>Catalog</label>
                <depends>
                    <field id="*/connection/engine" separator=",">amasty_elastic,amasty_elastic_8,amasty_elastic_opensearch</field>
                </depends>
                <frontend_model>Amasty\ElasticSearch\Block\Adminhtml\System\Config\CatalogGroup</frontend_model>
                <field id="wildcard_mode" translate="label,comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Wildcard Type</label>
                    <comment>Specify the type of the autocomplete suggestion - the part of a word which will be auto-completed. Shoppers can input a half-finished word and get a relevant result.</comment>
                    <source_model>Amasty\ElasticSearch\Model\Source\WildcardMode</source_model>
                    <depends>
                        <field id="*/connection/custom_analyzer">disabled</field>
                    </depends>
                </field>
                <field id="wildcard_symbols" translate="label,comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Enable Wildcard After</label>
                    <validate>validate-greater-than-zero</validate>
                    <comment>Specify a number of symbols to apply autocomplete suggestion after.</comment>
                    <depends>
                        <field id="*/connection/custom_analyzer">disabled</field>
                    </depends>
                </field>
                <field id="spellcorrection_symbols" translate="label,comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Enable Spell Correction After</label>
                    <validate>validate-greater-than-zero</validate>
                    <comment>Specify a number of symbols to apply spell correction after.</comment>
                    <depends>
                        <field id="*/connection/custom_analyzer">disabled</field>
                    </depends>
                </field>
                <field id="long_tail" translate="label" type="select" sortOrder="1000" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Allow Special Characters</label>
                    <comment>Useful when customer uses a highly specific search phrase and words that contain slashes, hyphens, dashes or any other non-alphabetic symbols.</comment>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <backend_model>Amasty\ElasticSearch\Model\Adminhtml\System\Config\Backend\LongTail</backend_model>
                    <depends>
                        <field id="*/connection/custom_analyzer">disabled</field>
                    </depends>
                </field>
                <field id="allow_further_query" translate="label comment" type="select" sortOrder="1005"
                       showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Allow to Search Within Results (Desktop)</label>
                    <comment>Additional search field will be added to the search results page.</comment>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="synonym_case_sensitive" translate="label comment" type="select" sortOrder="1007"
                       showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Case Sensitivity of Synonyms</label>
                    <comment>Set to 'Yes' if you want all synonyms to be case sensitive.</comment>
                    <source_model>Amasty\ElasticSearch\Model\Source\SynonymCaseSensitive</source_model>
                    <backend_model>Amasty\ElasticSearch\Model\Config\Backend\InvalidateCatalogSearchIndex</backend_model>
                </field>
                <field id="stop_word_case_sensitive" translate="label comment" type="select" sortOrder="1008"
                       showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Case Sensitivity of Stop Words</label>
                    <comment>Set to 'Yes' if you want all stop words to be case sensitive.</comment>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <backend_model>Amasty\ElasticSearch\Model\Config\Backend\InvalidateCatalogSearchIndex</backend_model>
                </field>
                <field id="query_settings" translate="label,comment" sortOrder="1010" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Search Query Settings</label>
                    <frontend_model>Amasty\ElasticSearch\Block\Adminhtml\Form\Field\QuerySettings</frontend_model>
                    <backend_model>Amasty\ElasticSearch\Model\Config\QuerySettings</backend_model>
                    <comment><![CDATA[Specify the search type preferences for each product attribute. Please consult the <a href="https://amasty.com/docs/doku.php?id=magento_2:elastic_search#advanced_query_settings">user guide</a>.]]></comment>
                    <tooltip><![CDATA[<b>Wildcard</b> allows shoppers to input a half-finished word and get a relevant result.<br/>
                        <b>Spell Correction</b> enables automatic spelling correction.<br/>
                        Please note that enabling this function may affect the synonyms operation and they may not work correctly.<br/>
                        <b>Match Mode</b> is about how the words are combined in a search query.<br/>
                        Please note that Wildcard and Spell Correction are not able to work at the same time.<br/>]]></tooltip>

                </field>
            </group>
            <group id="index" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                <depends>
                    <field id="*/connection/engine" separator=",">amasty_elastic,amasty_elastic_8,amasty_elastic_opensearch</field>
                    <field id="*/connection/custom_analyzer" separator=",">disabled,kuromoji,nori</field>
                </depends>
                <label>Indexation Settings</label>
                <field id="char_mapping" translate="label tooltip" type="textarea" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Char Mapping</label>
                    <comment><![CDATA[Mappings are used to convert a specified string of characters to specified value.]]></comment>
                    <tooltip><![CDATA[<div>The format of mapping: {key} => {value}</div><div>Enter one mapping per line. Note: the longest match is of higher priority.</div>E.g.:<ul style="margin-left: 5px; list-style-type: none;"><li>& => and</li><li>é => eh</li><li>oé => oe</li></ul>(in this case Chloé and Dolce & Gabbana search queries will be replaced with Chloe and Dolce and Gabbana upon searching).]]></tooltip>
                    <depends>
                        <field id="*/connection/custom_analyzer" separator=",">disabled</field>
                    </depends>
                    <validate>amasty-validate-char-mapping</validate>
                </field>
                <field id="use_language_stopwords" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Use Inbox Stopwords</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <depends>
                        <field id="*/connection/custom_analyzer" separator=",">disabled,kuromoji</field>
                    </depends>
                </field>
                <field id="stopwords_language" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Language</label>
                    <source_model>Amasty\ElasticSearch\Model\Source\ElasticLanguage</source_model>
                    <depends>
                        <field id="use_language_stopwords">1</field>
                        <field id="*/connection/custom_analyzer">disabled</field>
                    </depends>
                </field>
                <field id="use_language_stemmed_words" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Use Inbox Stemming</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <depends>
                        <field id="*/connection/custom_analyzer" separator=",">disabled,kuromoji</field>
                    </depends>
                </field>
                <field id="stemmed_words_language" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Language</label>
                    <source_model>Amasty\ElasticSearch\Model\Source\ElasticLanguage</source_model>
                    <depends>
                        <field id="use_language_stemmed_words">1</field>
                        <field id="*/connection/custom_analyzer">disabled</field>
                    </depends>
                </field>
                <field id="kuromoji_token_mode" translate="label,comment" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Indexation Mode</label>
                    <comment>Setting determines how engine handles compound and unknown words under indexation</comment>
                    <source_model>Amasty\ElasticSearch\Model\Source\KuromojiTokenMode</source_model>
                    <depends>
                        <field id="*/connection/custom_analyzer">kuromoji</field>
                    </depends>
                </field>
                <field id="use_kuromoji_reading_form" translate="label,comment" type="select" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Use Reading Form</label>
                    <comment>Setting replaces words with its reading form in either katakana or romaji</comment>
                    <source_model>Amasty\ElasticSearch\Model\Source\KuromojiReadingForm</source_model>
                    <depends>
                        <field id="*/connection/custom_analyzer">kuromoji</field>
                    </depends>
                </field>
                <field id="nori_token_mode" translate="label,comment" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Indexation Mode</label>
                    <comment>Setting determines how engine handles compound and unknown words under indexation</comment>
                    <source_model>Amasty\ElasticSearch\Model\Source\NoriTokenMode</source_model>
                    <depends>
                        <field id="*/connection/custom_analyzer">nori</field>
                    </depends>
                </field>
                <field id="use_nori_reading_form" translate="label,comment" type="select" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Use Reading Form</label>
                    <comment>Setting rewrites words written in Hanja to their Hangul form</comment>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <depends>
                        <field id="*/connection/custom_analyzer">nori</field>
                    </depends>
                </field>
            </group>
            <group id="debug" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="0"
                   showInStore="0">
                <depends>
                    <field id="*/connection/engine" separator=",">amasty_elastic,amasty_elastic_8,amasty_elastic_opensearch</field>
                </depends>
                <label>Debug Settings</label>
                <comment><![CDATA[Due to its decreasing relevance and our efforts to optimize the module, the "Debug Settings" configuration will be removed in upcoming releases.]]></comment>
                <field id="use_debug" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Is Debug Active</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <backend_model>Amasty\ElasticSearch\Model\Config\Backend\Debug</backend_model>
                </field>
                <field id="log_buckets_alert_requests" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Log Requests for Bucket Alerts</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <depends>
                        <field id="use_debug">1</field>
                    </depends>
                </field>
                <field id="log_request_object" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Log Request Object</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <depends>
                        <field id="use_debug">1</field>
                    </depends>
                </field>
                <field id="log_raw_request" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Log Raw Request</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <depends>
                        <field id="use_debug">1</field>
                    </depends>
                </field>
                <field id="log_raw_response" translate="label" type="select" sortOrder="50" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Log Raw Response</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <depends>
                        <field id="use_debug">1</field>
                    </depends>
                </field>
                <field id="log_response_object" translate="label" type="select" sortOrder="60" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Log Response Object</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <depends>
                        <field id="use_debug">1</field>
                    </depends>
                </field>
            </group>
        </section>
    </system>
</config>
