00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_CatalogSearch 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 00028 class Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection 00029 extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection 00030 { 00031 /** 00032 * Retrieve query model object 00033 * 00034 * @return Mage_CatalogSearch_Model_Query 00035 */ 00036 protected function _getQuery() 00037 { 00038 return Mage::helper('catalogSearch')->getQuery(); 00039 } 00040 00041 /** 00042 * Add search query filter 00043 * 00044 * @param Mage_CatalogSearch_Model_Query $query 00045 * @return Mage_CatalogSearch_Model_Mysql4_Search_Collection 00046 */ 00047 public function addSearchFilter($query) 00048 { 00049 Mage::getSingleton('catalogsearch/fulltext')->prepareResult(); 00050 00051 $this->getSelect()->joinInner( 00052 array('search_result' => $this->getTable('catalogsearch/result')), 00053 $this->getConnection()->quoteInto( 00054 'search_result.product_id=e.entity_id AND search_result.query_id=?', 00055 $this->_getQuery()->getId() 00056 ), 00057 array('relevance' => 'relevance') 00058 ); 00059 00060 return $this; 00061 } 00062 00063 /** 00064 * Set Order field 00065 * 00066 * @param string $attribute 00067 * @param string $dir 00068 * @return Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection 00069 */ 00070 public function setOrder($attribute, $dir='desc') 00071 { 00072 if ($attribute == 'relevance') { 00073 $this->getSelect()->order("relevance {$dir}"); 00074 } 00075 else { 00076 parent::setOrder($attribute, $dir); 00077 } 00078 return $this; 00079 } 00080 }