Version Notes
More optimized search
Download this release
Release Info
| Developer | magecoders |
| Extension | enhanced_defaultsearch |
| Version | 1.0.1 |
| Comparing to | |
| See all releases | |
Code changes from version 1.0.0 to 1.0.1
app/code/community/MageCoders/DefaultSearch/Model/Resource/Fulltext.php
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class MageCoders_DefaultSearch_Model_Resource_Fulltext extends Mage_CatalogSearch_Model_Resource_Fulltext
|
| 4 |
+
{
|
| 5 |
+
/**
|
| 6 |
+
* Prepare results for query
|
| 7 |
+
*
|
| 8 |
+
* @param Mage_CatalogSearch_Model_Fulltext $object
|
| 9 |
+
* @param string $queryText
|
| 10 |
+
* @param Mage_CatalogSearch_Model_Query $query
|
| 11 |
+
* @return Mage_CatalogSearch_Model_Resource_Fulltext
|
| 12 |
+
*/
|
| 13 |
+
public function prepareResult($object, $queryText, $query)
|
| 14 |
+
{
|
| 15 |
+
$adapter = $this->_getWriteAdapter();
|
| 16 |
+
if (!$query->getIsProcessed()) {
|
| 17 |
+
$searchType = $object->getSearchType($query->getStoreId());
|
| 18 |
+
|
| 19 |
+
$preparedTerms = Mage::getResourceHelper('catalogsearch')
|
| 20 |
+
->prepareTerms($queryText, $query->getMaxQueryWords());
|
| 21 |
+
|
| 22 |
+
$bind = array();
|
| 23 |
+
$like = array();
|
| 24 |
+
$likeCond = '';
|
| 25 |
+
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE
|
| 26 |
+
|| $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE
|
| 27 |
+
) {
|
| 28 |
+
$helper = Mage::getResourceHelper('core');
|
| 29 |
+
$words = Mage::helper('core/string')->splitWords($queryText, true, $query->getMaxQueryWords());
|
| 30 |
+
foreach ($words as $word) {
|
| 31 |
+
$like[] = $helper->getCILike('s.data_index', $word, array('position' => 'any'));
|
| 32 |
+
}
|
| 33 |
+
if ($like) {
|
| 34 |
+
$likeCond = '(' . join(' AND ', $like) . ')';
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
$mainTableAlias = 's';
|
| 38 |
+
$fields = array(
|
| 39 |
+
'query_id' => new Zend_Db_Expr($query->getId()),
|
| 40 |
+
'product_id',
|
| 41 |
+
);
|
| 42 |
+
$select = $adapter->select()
|
| 43 |
+
->from(array($mainTableAlias => $this->getMainTable()), $fields)
|
| 44 |
+
->joinInner(array('e' => $this->getTable('catalog/product')),
|
| 45 |
+
'e.entity_id = s.product_id',
|
| 46 |
+
array())
|
| 47 |
+
->where($mainTableAlias.'.store_id = ?', (int)$query->getStoreId());
|
| 48 |
+
|
| 49 |
+
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT
|
| 50 |
+
|| $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE
|
| 51 |
+
) {
|
| 52 |
+
|
| 53 |
+
$queryText = '"'.$queryText.'"';
|
| 54 |
+
$bind[':query'] = "'".trim($queryText)."'";
|
| 55 |
+
|
| 56 |
+
$where = Mage::getResourceHelper('catalogsearch')
|
| 57 |
+
->chooseFulltext($this->getMainTable(), $mainTableAlias, $select);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
if ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
|
| 61 |
+
$where .= ($where ? ' OR ' : '') . $likeCond;
|
| 62 |
+
} elseif ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE) {
|
| 63 |
+
$select->columns(array('relevance' => new Zend_Db_Expr(0)));
|
| 64 |
+
$where = $likeCond;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
if ($where != '') {
|
| 69 |
+
$select->where($where);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT){
|
| 73 |
+
$selectSql = $select->__toString();
|
| 74 |
+
$result = $adapter->query($selectSql,$bind);
|
| 75 |
+
$resultCount = $result->rowCount();
|
| 76 |
+
if($resultCount==0){
|
| 77 |
+
$terms = (array)$preparedTerms[1];
|
| 78 |
+
$str = array();
|
| 79 |
+
$i = 0;
|
| 80 |
+
foreach($terms as $term){
|
| 81 |
+
$str[] = '+'.$term;
|
| 82 |
+
$i++;
|
| 83 |
+
}
|
| 84 |
+
$queryText = "'".implode(' ',$str)."'";
|
| 85 |
+
$bind[':query'] = $queryText;
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
$sql = $adapter->insertFromSelect($select,
|
| 91 |
+
$this->getTable('catalogsearch/result'),
|
| 92 |
+
array(),
|
| 93 |
+
Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE);
|
| 94 |
+
|
| 95 |
+
$adapter->query($sql, $bind);
|
| 96 |
+
|
| 97 |
+
$query->setIsProcessed(1);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
return $this;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
}
|
package.xml
CHANGED
|
@@ -1,20 +1,23 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>enhanced_defaultsearch</name>
|
| 4 |
-
<version>1.0.
|
| 5 |
<stability>stable</stability>
|
| 6 |
-
<license>OSL</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
-
<summary>Enhanced Default Search for Magento
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
<
|
| 17 |
-
<
|
|
|
|
|
|
|
|
|
|
| 18 |
<compatible/>
|
| 19 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
| 20 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>enhanced_defaultsearch</name>
|
| 4 |
+
<version>1.0.1</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
+
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
+
<summary>Enhanced Default Search for Magento. It helps to improve your magento store search results and return more relevant result againt your search query.</summary>
|
| 10 |
+
<description>Enhanced Default Search for Magento. It helps to improve your magento store search results and return more relevant result againt your search query.
|
| 11 |
+
This will help to fix following issue :
|
| 12 |
+
- Magento Default Search Issue
|
| 13 |
+
- Default Search Magento
|
| 14 |
+
- Improve Magento Search
|
| 15 |
+
- Enhance default search magento</description>
|
| 16 |
+
<notes>More optimized search </notes>
|
| 17 |
+
<authors><author><name>magecoders</name><user>magecoders</user><email>rahil28288@gmail.com</email></author></authors>
|
| 18 |
+
<date>2013-05-20</date>
|
| 19 |
+
<time>10:23:02</time>
|
| 20 |
+
<contents><target name="mageetc"><dir name="modules"><file name="MageCoders_DefaultSearch.xml" hash="1e7f12fb79d2b3bf949d123a69f73785"/></dir></target><target name="magecommunity"><dir name="MageCoders"><dir name="DefaultSearch"><dir name="Helper"><file name="Data.php" hash="4c387cd383da2202e54ed0cdf592d169"/></dir><dir name="Model"><dir name="Mysql4"><file name="Fulltext.php" hash="fece2ded01899b039e350779b9637b6b"/></dir><dir name="Resource"><file name="Fulltext.php" hash="55fc992ac7bd1bb6c13f85cd96fa9160"/></dir></dir><dir name="etc"><file name="config.xml" hash="9e1ff61355facc8b968e218b0956d860"/></dir></dir></dir></target></contents>
|
| 21 |
<compatible/>
|
| 22 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
| 23 |
</package>
|
