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 * Catalog advanced search model 00029 * 00030 * @category Mage 00031 * @package Mage_CatalogSearch 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 class Mage_CatalogSearch_Model_Fulltext extends Mage_Core_Model_Abstract 00035 { 00036 const SEARCH_TYPE_LIKE = 1; 00037 const SEARCH_TYPE_FULLTEXT = 2; 00038 const SEARCH_TYPE_COMBINE = 3; 00039 const XML_PATH_CATALOG_SEARCH_TYPE = 'catalog/search/search_type'; 00040 00041 protected function _construct() 00042 { 00043 $this->_init('catalogsearch/fulltext'); 00044 } 00045 00046 /** 00047 * Regenerate all Stores index 00048 * 00049 * Examples: 00050 * (null, null) => Regenerate index for all stores 00051 * (1, null) => Regenerate index for store Id=1 00052 * (1, 2) => Regenerate index for product Id=2 and its store view Id=1 00053 * (null, 2) => Regenerate index for all store views of product Id=2 00054 * 00055 * @param int $storeId Store View Id 00056 * @param int $productId Product Entity Id 00057 * @return Mage_CatalogSearch_Model_Fulltext 00058 */ 00059 public function rebuildIndex($storeId = null, $productId = null) 00060 { 00061 $this->getResource()->rebuildIndex($storeId, $productId); 00062 return $this; 00063 } 00064 00065 /** 00066 * Delete index data 00067 * 00068 * Examples: 00069 * (null, null) => Clean index of all stores 00070 * (1, null) => Clean index of store Id=1 00071 * (1, 2) => Clean index of product Id=2 and its store view Id=1 00072 * (null, 2) => Clean index of all store views of product Id=2 00073 * 00074 * @param int $storeId Store View Id 00075 * @param int $productId Product Entity Id 00076 * @return Mage_CatalogSearch_Model_Fulltext 00077 */ 00078 public function cleanIndex($storeId = null, $productId = null) 00079 { 00080 $this->getResource()->cleanIndex($storeId, $productId); 00081 return $this; 00082 } 00083 00084 /** 00085 * Reset search results cache 00086 * 00087 * @return Mage_CatalogSearch_Model_Fulltext 00088 */ 00089 public function resetSearchResults() 00090 { 00091 $this->getResource()->resetSearchResults(); 00092 return $this; 00093 } 00094 00095 /** 00096 * Prepare results for query 00097 * 00098 * @param Mage_CatalogSearch_Model_Query $query 00099 * @return Mage_CatalogSearch_Model_Fulltext 00100 */ 00101 public function prepareResult($query = null) 00102 { 00103 if (!$query instanceof Mage_CatalogSearch_Model_Query) { 00104 $query = Mage::helper('catalogSearch')->getQuery(); 00105 } 00106 $queryText = Mage::helper('catalogSearch')->getQueryText(); 00107 if ($query->getSynonimFor()) { 00108 $queryText = $query->getSynonimFor(); 00109 } 00110 $this->getResource()->prepareResult($this, $queryText, $query); 00111 return $this; 00112 } 00113 00114 /** 00115 * Retrieve search type 00116 * 00117 * @param int $storeId 00118 * @return int 00119 */ 00120 public function getSearchType($storeId = null) 00121 { 00122 return Mage::getStoreConfig(self::XML_PATH_CATALOG_SEARCH_TYPE, $storeId); 00123 } 00124 }