From 758dc6cd3c78702560abae42596fde05ae7bbdc3 Mon Sep 17 00:00:00 2001 From: sv3n Date: Wed, 22 Dec 2021 22:52:36 +0100 Subject: [PATCH] make fulltext search separator (OR/AND) configurable from backend (#1852) * Change fulltext search separator (OR/AND) from backend * Added doc * Updated README.md --- README.md | 1 + .../Backend/Catalog/Search/Separator.php | 24 +++++++++++++++++++ .../Source/Catalog/Search/Separator.php | 23 ++++++++++++++++++ .../Mage/Catalog/Block/Product/Abstract.php | 5 +--- .../Mage/CatalogSearch/Model/Fulltext.php | 1 + .../CatalogSearch/Model/Resource/Fulltext.php | 3 ++- .../core/Mage/CatalogSearch/etc/config.xml | 1 + .../core/Mage/CatalogSearch/etc/system.xml | 10 ++++++++ 8 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Catalog/Search/Separator.php create mode 100644 app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/Search/Separator.php diff --git a/README.md b/README.md index b5fccbfcfe0..b5df5529d0c 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ Most important changes will be listed here, all other changes since `19.4.0` can - `admin/design/use_legacy_theme` - `admin/emails/admin_notification_email_template` - `catalog/product_image/progressive_threshold` +- `catalog/search/search_separator` ### New Events - `adminhtml_block_widget_form_init_form_values_after` diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Catalog/Search/Separator.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Catalog/Search/Separator.php new file mode 100644 index 00000000000..269892b396e --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Catalog/Search/Separator.php @@ -0,0 +1,24 @@ +getValue(); + $oldValue = Mage::getConfig()->getNode( + Mage_CatalogSearch_Model_Fulltext::XML_PATH_CATALOG_SEARCH_SEPARATOR, + $this->getScope(), + $this->getScopeId() + ); + if ($newValue != $oldValue) { + Mage::getSingleton('catalogsearch/fulltext')->resetSearchResults(); + } + + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/Search/Separator.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/Search/Separator.php new file mode 100644 index 00000000000..0617da3cdd1 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/Search/Separator.php @@ -0,0 +1,23 @@ + 'OR (default)', + ' AND ' => 'AND' + ]; + $options = []; + foreach ($types as $k => $v) { + $options[] = [ + 'value' => $k, + 'label' => $v + ]; + } + return $options; + } +} diff --git a/app/code/core/Mage/Catalog/Block/Product/Abstract.php b/app/code/core/Mage/Catalog/Block/Product/Abstract.php index 9aa165eb0c3..e2028b9d2a1 100644 --- a/app/code/core/Mage/Catalog/Block/Product/Abstract.php +++ b/app/code/core/Mage/Catalog/Block/Product/Abstract.php @@ -383,15 +383,12 @@ public function getTierPriceHtml($product = null, $parent = null) ->callParentToHtml(); } - /* + /** * Calls the object's to Html method. * This method exists to make the code more testable. * By having a protected wrapper for the final method toHtml, we can 'mock' out this method * when unit testing * - * @return string - */ - /** * @return string */ protected function callParentToHtml() diff --git a/app/code/core/Mage/CatalogSearch/Model/Fulltext.php b/app/code/core/Mage/CatalogSearch/Model/Fulltext.php index a1bebe26b30..886e8a3f22f 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Fulltext.php +++ b/app/code/core/Mage/CatalogSearch/Model/Fulltext.php @@ -48,6 +48,7 @@ class Mage_CatalogSearch_Model_Fulltext extends Mage_Core_Model_Abstract const SEARCH_TYPE_FULLTEXT = 2; const SEARCH_TYPE_COMBINE = 3; const XML_PATH_CATALOG_SEARCH_TYPE = 'catalog/search/search_type'; + const XML_PATH_CATALOG_SEARCH_SEPARATOR = 'catalog/search/search_separator'; /** * Whether table changes are allowed diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php index c2e4c3bd5ea..56159ca66ba 100644 --- a/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php +++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php @@ -355,7 +355,8 @@ public function prepareResult($object, $queryText, $query) } if ($like) { - $likeCond = '(' . implode(' OR ', $like) . ')'; + $separator = Mage::getStoreConfig(Mage_CatalogSearch_Model_Fulltext::XML_PATH_CATALOG_SEARCH_SEPARATOR); + $likeCond = '(' . implode($separator, $like) . ')'; } } diff --git a/app/code/core/Mage/CatalogSearch/etc/config.xml b/app/code/core/Mage/CatalogSearch/etc/config.xml index 1b9d82a4393..b8d7943fba6 100644 --- a/app/code/core/Mage/CatalogSearch/etc/config.xml +++ b/app/code/core/Mage/CatalogSearch/etc/config.xml @@ -137,6 +137,7 @@ 128 10 1 + OR 2000 1 diff --git a/app/code/core/Mage/CatalogSearch/etc/system.xml b/app/code/core/Mage/CatalogSearch/etc/system.xml index 32f8fda4deb..0c93c89ad8d 100644 --- a/app/code/core/Mage/CatalogSearch/etc/system.xml +++ b/app/code/core/Mage/CatalogSearch/etc/system.xml @@ -98,6 +98,16 @@ 1 1 + + + select + adminhtml/system_config_backend_catalog_search_separator + adminhtml/system_config_source_catalog_search_separator + 22 + 1 + 1 + 1 + text