Skip to content

Commit 758dc6c

Browse files
authored
make fulltext search separator (OR/AND) configurable from backend (#1852)
* Change fulltext search separator (OR/AND) from backend * Added doc * Updated README.md
1 parent 904baed commit 758dc6c

File tree

8 files changed

+63
-5
lines changed

8 files changed

+63
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Most important changes will be listed here, all other changes since `19.4.0` can
8181
- `admin/design/use_legacy_theme`
8282
- `admin/emails/admin_notification_email_template`
8383
- `catalog/product_image/progressive_threshold`
84+
- `catalog/search/search_separator`
8485

8586
### New Events
8687
- `adminhtml_block_widget_form_init_form_values_after`
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
class Mage_Adminhtml_Model_System_Config_Backend_Catalog_Search_Separator extends Mage_Core_Model_Config_Data
4+
{
5+
/**
6+
* After change Catalog Search Type process
7+
*
8+
* @return $this
9+
*/
10+
protected function _afterSave()
11+
{
12+
$newValue = $this->getValue();
13+
$oldValue = Mage::getConfig()->getNode(
14+
Mage_CatalogSearch_Model_Fulltext::XML_PATH_CATALOG_SEARCH_SEPARATOR,
15+
$this->getScope(),
16+
$this->getScopeId()
17+
);
18+
if ($newValue != $oldValue) {
19+
Mage::getSingleton('catalogsearch/fulltext')->resetSearchResults();
20+
}
21+
22+
return $this;
23+
}
24+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
class Mage_Adminhtml_Model_System_Config_Source_Catalog_Search_Separator
4+
{
5+
/**
6+
* @return array
7+
*/
8+
public function toOptionArray()
9+
{
10+
$types = [
11+
' OR ' => 'OR (default)',
12+
' AND ' => 'AND'
13+
];
14+
$options = [];
15+
foreach ($types as $k => $v) {
16+
$options[] = [
17+
'value' => $k,
18+
'label' => $v
19+
];
20+
}
21+
return $options;
22+
}
23+
}

app/code/core/Mage/Catalog/Block/Product/Abstract.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,12 @@ public function getTierPriceHtml($product = null, $parent = null)
383383
->callParentToHtml();
384384
}
385385

386-
/*
386+
/**
387387
* Calls the object's to Html method.
388388
* This method exists to make the code more testable.
389389
* By having a protected wrapper for the final method toHtml, we can 'mock' out this method
390390
* when unit testing
391391
*
392-
* @return string
393-
*/
394-
/**
395392
* @return string
396393
*/
397394
protected function callParentToHtml()

app/code/core/Mage/CatalogSearch/Model/Fulltext.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Mage_CatalogSearch_Model_Fulltext extends Mage_Core_Model_Abstract
4848
const SEARCH_TYPE_FULLTEXT = 2;
4949
const SEARCH_TYPE_COMBINE = 3;
5050
const XML_PATH_CATALOG_SEARCH_TYPE = 'catalog/search/search_type';
51+
const XML_PATH_CATALOG_SEARCH_SEPARATOR = 'catalog/search/search_separator';
5152

5253
/**
5354
* Whether table changes are allowed

app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ public function prepareResult($object, $queryText, $query)
355355
}
356356

357357
if ($like) {
358-
$likeCond = '(' . implode(' OR ', $like) . ')';
358+
$separator = Mage::getStoreConfig(Mage_CatalogSearch_Model_Fulltext::XML_PATH_CATALOG_SEARCH_SEPARATOR);
359+
$likeCond = '(' . implode($separator, $like) . ')';
359360
}
360361
}
361362

app/code/core/Mage/CatalogSearch/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
<max_query_length>128</max_query_length>
138138
<max_query_words>10</max_query_words>
139139
<search_type>1</search_type>
140+
<search_separator> OR </search_separator>
140141
<use_layered_navigation_count>2000</use_layered_navigation_count>
141142
<show_autocomplete_results_count>1</show_autocomplete_results_count>
142143
</search>

app/code/core/Mage/CatalogSearch/etc/system.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@
9898
<show_in_website>1</show_in_website>
9999
<show_in_store>1</show_in_store>
100100
</search_type>
101+
<search_separator translate="label">
102+
<label>Fulltext Separator</label>
103+
<frontend_type>select</frontend_type>
104+
<backend_model>adminhtml/system_config_backend_catalog_search_separator</backend_model>
105+
<source_model>adminhtml/system_config_source_catalog_search_separator</source_model>
106+
<sort_order>22</sort_order>
107+
<show_in_default>1</show_in_default>
108+
<show_in_website>1</show_in_website>
109+
<show_in_store>1</show_in_store>
110+
</search_separator>
101111
<use_layered_navigation_count translate="label comment">
102112
<label>Apply Layered Navigation if Search Results are Less Than</label>
103113
<frontend_type>text</frontend_type>

0 commit comments

Comments
 (0)