Skip to content

Commit

Permalink
make fulltext search separator (OR/AND) configurable from backend (#1852
Browse files Browse the repository at this point in the history
)

* Change fulltext search separator (OR/AND) from backend

* Added doc

* Updated README.md
  • Loading branch information
sreichel authored Dec 22, 2021
1 parent 904baed commit 758dc6c
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

class Mage_Adminhtml_Model_System_Config_Backend_Catalog_Search_Separator extends Mage_Core_Model_Config_Data
{
/**
* After change Catalog Search Type process
*
* @return $this
*/
protected function _afterSave()
{
$newValue = $this->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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

class Mage_Adminhtml_Model_System_Config_Source_Catalog_Search_Separator
{
/**
* @return array
*/
public function toOptionArray()
{
$types = [
' OR ' => 'OR (default)',
' AND ' => 'AND'
];
$options = [];
foreach ($types as $k => $v) {
$options[] = [
'value' => $k,
'label' => $v
];
}
return $options;
}
}
5 changes: 1 addition & 4 deletions app/code/core/Mage/Catalog/Block/Product/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions app/code/core/Mage/CatalogSearch/Model/Fulltext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) . ')';
}
}

Expand Down
1 change: 1 addition & 0 deletions app/code/core/Mage/CatalogSearch/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<max_query_length>128</max_query_length>
<max_query_words>10</max_query_words>
<search_type>1</search_type>
<search_separator> OR </search_separator>
<use_layered_navigation_count>2000</use_layered_navigation_count>
<show_autocomplete_results_count>1</show_autocomplete_results_count>
</search>
Expand Down
10 changes: 10 additions & 0 deletions app/code/core/Mage/CatalogSearch/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</search_type>
<search_separator translate="label">
<label>Fulltext Separator</label>
<frontend_type>select</frontend_type>
<backend_model>adminhtml/system_config_backend_catalog_search_separator</backend_model>
<source_model>adminhtml/system_config_source_catalog_search_separator</source_model>
<sort_order>22</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</search_separator>
<use_layered_navigation_count translate="label comment">
<label>Apply Layered Navigation if Search Results are Less Than</label>
<frontend_type>text</frontend_type>
Expand Down

0 comments on commit 758dc6c

Please sign in to comment.