Magento: improving default search engine -


so, changed default magento search engine slightly, , works close how want it. (i.e. or term search and). however, there 1 more thing i'd implement. when person searches series of terms, green apple a, i'd product green apple show first. right now, and operator, results in order pulled db. so, green apple might show in anywhere.

here function prepares results.. bit complicated me, , i'm wondering if there's easy way "append" search result looks specific sequence of inputted terms , concatenates results, giving priority, shows first.

(sorry long code. typically don't posting large amount of code)

from fulltext.php in /stores/my_website/app/code/local/mage/catalogsearch/model/resource

public function prepareresult($object, $querytext, $query) {      $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 $word) {                 $like[] = $helper->getcilike('s.data_index', $word, array('position' => 'any'));             }             if ($like) {                 $likecond = '(' . join(' , ', $like) . ')';             }         }         $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 ? ' , ' : '') . $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; } 

i think can try free extension default search

http://www.magentocommerce.com/magento-connect/catalog/product/view/id/12202/s/enhanced-default-search-9697


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -