I just created a module for overriding magento's default search;
But it not working properly. Please help me
See my code below
app/etc/modules/
<?xml version="1.0"?>
<config>
<modules>
<Sid_Newsearch>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
<depends>
<Mage_CatalogSearch />
</depends>
</Sid_Newsearch>
</modules>
</config>
Sid/Newsearch/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Sid_Newsearch>
<version>0.1.0</version>
</Sid_Newsearch>
</modules>
<global>
<helpers>
<newsearch>
<class>Sid_Newsearch_Helper</class>
</newsearch>
</helpers>
<models>
<newsearch>
<class>Sid_Newsearch_Model</class>
<resourceModel>newsearch_mysql4</resourceModel>
</newsearch>
<catalogsearch_resource>
<rewrite>
<fulltext>Sid_Newsearch_Model_CatalogSearch_Resource_Fulltext</fulltext>
</rewrite>
</catalogsearch_resource>
</models>
</global>
</config>
Sid/Newsearch/Model/CatalogSearch/Resource/Fulltext.php
<?php
class Sid_Newsearch_Model_CatalogSearch_Resource_Fulltext extends Mage_CatalogSearch_Model_Resource_Fulltext
{
public function prepareResult($object, $queryText, $query)
{
echo '123';
exit();
$adapter = $this->_getWriteAdapter();
if (!$query->getIsProcessed()) {
$searchType = $object->getSearchType($query->getStoreId());
$preparedTerms = Mage::getResourceHelper('catalogsearch')
->prepareTerms($queryText, $query->getMaxQueryWords());
$bind = array();
$like = array();
$likeCond = '';
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE
|| $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE
) {
$helper = Mage::getResourceHelper('core');
$words = Mage::helper('core/string')->splitWords($queryText, true, $query->getMaxQueryWords());
foreach ($words as $word) {
$like[] = $helper->getCILike('s.data_index', $word, array('position' => 'any'));
}
if ($like) {
$likeCond = '(' . join(' AND ', $like) . ')';
//echo ;
}
}
$mainTableAlias = 's';
$fields = array(
'query_id' => new Zend_Db_Expr($query->getId()),
'product_id',
);
$select = $adapter->select()
->from(array($mainTableAlias => $this->getMainTable()), $fields)
->joinInner(array('e' => $this->getTable('catalog/product')),
'e.entity_id = s.product_id',
array())
->where($mainTableAlias.'.store_id = ?', (int)$query->getStoreId());
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT
|| $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE
) {
$bind[':query'] = implode(' ', $preparedTerms[0]);
$where = Mage::getResourceHelper('catalogsearch')
->chooseFulltext($this->getMainTable(), $mainTableAlias, $select);
}
if ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
$where .= ($where ? ' OR ' : '') . $likeCond;
} elseif ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE) {
$select->columns(array('relevance' => new Zend_Db_Expr(0)));
$where = $likeCond;
}
if ($where != '') {
$select->where($where);
}
$sql = $adapter->insertFromSelect($select,
$this->getTable('catalogsearch/result'),
array(),
Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE);
$adapter->query($sql, $bind);
$query->setIsProcessed(1);
}
return $this;
}
}
?>
Here in the function prepareResult i just added exit() but it is not working;
Please help me , Thanks in advance