1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_CatalogSearch
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Catalog advanced search model
29: *
30: * @method Mage_CatalogSearch_Model_Resource_Fulltext _getResource()
31: * @method Mage_CatalogSearch_Model_Resource_Fulltext getResource()
32: * @method int getProductId()
33: * @method Mage_CatalogSearch_Model_Fulltext setProductId(int $value)
34: * @method int getStoreId()
35: * @method Mage_CatalogSearch_Model_Fulltext setStoreId(int $value)
36: * @method string getDataIndex()
37: * @method Mage_CatalogSearch_Model_Fulltext setDataIndex(string $value)
38: *
39: * @category Mage
40: * @package Mage_CatalogSearch
41: * @author Magento Core Team <core@magentocommerce.com>
42: */
43: class Mage_CatalogSearch_Model_Fulltext extends Mage_Core_Model_Abstract
44: {
45: const SEARCH_TYPE_LIKE = 1;
46: const SEARCH_TYPE_FULLTEXT = 2;
47: const SEARCH_TYPE_COMBINE = 3;
48: const XML_PATH_CATALOG_SEARCH_TYPE = 'catalog/search/search_type';
49:
50: /**
51: * Whether table changes are allowed
52: *
53: * @deprecated after 1.6.1.0
54: * @var bool
55: */
56: protected $_allowTableChanges = true;
57:
58: protected function _construct()
59: {
60: $this->_init('catalogsearch/fulltext');
61: }
62:
63: /**
64: * Regenerate all Stores index
65: *
66: * Examples:
67: * (null, null) => Regenerate index for all stores
68: * (1, null) => Regenerate index for store Id=1
69: * (1, 2) => Regenerate index for product Id=2 and its store view Id=1
70: * (null, 2) => Regenerate index for all store views of product Id=2
71: *
72: * @param int|null $storeId Store View Id
73: * @param int|array|null $productIds Product Entity Id
74: *
75: * @return Mage_CatalogSearch_Model_Fulltext
76: */
77: public function rebuildIndex($storeId = null, $productIds = null)
78: {
79: Mage::dispatchEvent('catalogsearch_index_process_start', array(
80: 'store_id' => $storeId,
81: 'product_ids' => $productIds
82: ));
83:
84: $this->getResource()->rebuildIndex($storeId, $productIds);
85:
86: Mage::dispatchEvent('catalogsearch_index_process_complete', array());
87:
88: return $this;
89: }
90:
91: /**
92: * Delete index data
93: *
94: * Examples:
95: * (null, null) => Clean index of all stores
96: * (1, null) => Clean index of store Id=1
97: * (1, 2) => Clean index of product Id=2 and its store view Id=1
98: * (null, 2) => Clean index of all store views of product Id=2
99: *
100: * @param int $storeId Store View Id
101: * @param int $productId Product Entity Id
102: * @return Mage_CatalogSearch_Model_Fulltext
103: */
104: public function cleanIndex($storeId = null, $productId = null)
105: {
106: $this->getResource()->cleanIndex($storeId, $productId);
107: return $this;
108: }
109:
110: /**
111: * Reset search results cache
112: *
113: * @return Mage_CatalogSearch_Model_Fulltext
114: */
115: public function resetSearchResults()
116: {
117: $this->getResource()->resetSearchResults();
118: return $this;
119: }
120:
121: /**
122: * Prepare results for query
123: *
124: * @param Mage_CatalogSearch_Model_Query $query
125: * @return Mage_CatalogSearch_Model_Fulltext
126: */
127: public function prepareResult($query = null)
128: {
129: if (!$query instanceof Mage_CatalogSearch_Model_Query) {
130: $query = Mage::helper('catalogsearch')->getQuery();
131: }
132: $queryText = Mage::helper('catalogsearch')->getQueryText();
133: if ($query->getSynonymFor()) {
134: $queryText = $query->getSynonymFor();
135: }
136: $this->getResource()->prepareResult($this, $queryText, $query);
137: return $this;
138: }
139:
140: /**
141: * Retrieve search type
142: *
143: * @param int $storeId
144: * @return int
145: */
146: public function getSearchType($storeId = null)
147: {
148: return Mage::getStoreConfig(self::XML_PATH_CATALOG_SEARCH_TYPE, $storeId);
149: }
150:
151:
152:
153:
154:
155: // Deprecated methods
156:
157: /**
158: * Set whether table changes are allowed
159: *
160: * @deprecated after 1.6.1.0
161: *
162: * @param bool $value
163: * @return Mage_CatalogSearch_Model_Fulltext
164: */
165: public function setAllowTableChanges($value = true)
166: {
167: $this->_allowTableChanges = $value;
168: return $this;
169: }
170:
171: /**
172: * Update category products indexes
173: *
174: * @deprecated after 1.6.2.0
175: *
176: * @param array $productIds
177: * @param array $categoryIds
178: *
179: * @return Mage_CatalogSearch_Model_Fulltext
180: */
181: public function updateCategoryIndex($productIds, $categoryIds)
182: {
183: $this->getResource()->updateCategoryIndex($productIds, $categoryIds);
184: return $this;
185: }
186: }
187: