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: /**
29: * CatalogSearch Fulltext Index Engine resource model
30: *
31: * @category Mage
32: * @package Mage_CatalogSearch
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_CatalogSearch_Model_Resource_Fulltext_Engine extends Mage_Core_Model_Resource_Db_Abstract
36: {
37: /**
38: * Init resource model
39: *
40: */
41: protected function _construct()
42: {
43: $this->_init('catalogsearch/fulltext', 'product_id');
44: }
45:
46: /**
47: * Add entity data to fulltext search table
48: *
49: * @param int $entityId
50: * @param int $storeId
51: * @param array $index
52: * @param string $entity 'product'|'cms'
53: * @return Mage_CatalogSearch_Model_Resource_Fulltext_Engine
54: */
55: public function saveEntityIndex($entityId, $storeId, $index, $entity = 'product')
56: {
57: $this->_getWriteAdapter()->insert($this->getMainTable(), array(
58: 'product_id' => $entityId,
59: 'store_id' => $storeId,
60: 'data_index' => $index
61: ));
62: return $this;
63: }
64:
65: /**
66: * Multi add entities data to fulltext search table
67: *
68: * @param int $storeId
69: * @param array $entityIndexes
70: * @param string $entity 'product'|'cms'
71: * @return Mage_CatalogSearch_Model_Resource_Fulltext_Engine
72: */
73: public function saveEntityIndexes($storeId, $entityIndexes, $entity = 'product')
74: {
75: $data = array();
76: $storeId = (int)$storeId;
77: foreach ($entityIndexes as $entityId => $index) {
78: $data[] = array(
79: 'product_id' => (int)$entityId,
80: 'store_id' => $storeId,
81: 'data_index' => $index
82: );
83: }
84:
85: if ($data) {
86: Mage::getResourceHelper('catalogsearch')
87: ->insertOnDuplicate($this->getMainTable(), $data, array('data_index'));
88: }
89:
90: return $this;
91: }
92:
93: /**
94: * Retrieve allowed visibility values for current engine
95: *
96: * @return array
97: */
98: public function getAllowedVisibility()
99: {
100: return Mage::getSingleton('catalog/product_visibility')->getVisibleInSearchIds();
101: }
102:
103: /**
104: * Define if current search engine supports advanced index
105: *
106: * @return bool
107: */
108: public function allowAdvancedIndex()
109: {
110: return false;
111: }
112:
113: /**
114: * Remove entity data from fulltext search table
115: *
116: * @param int $storeId
117: * @param int $entityId
118: * @param string $entity 'product'|'cms'
119: * @return Mage_CatalogSearch_Model_Resource_Fulltext_Engine
120: */
121: public function cleanIndex($storeId = null, $entityId = null, $entity = 'product')
122: {
123: $where = array();
124:
125: if (!is_null($storeId)) {
126: $where[] = $this->_getWriteAdapter()->quoteInto('store_id=?', $storeId);
127: }
128: if (!is_null($entityId)) {
129: $where[] = $this->_getWriteAdapter()->quoteInto('product_id IN (?)', $entityId);
130: }
131:
132: $this->_getWriteAdapter()->delete($this->getMainTable(), $where);
133:
134: return $this;
135: }
136:
137: /**
138: * Prepare index array as a string glued by separator
139: *
140: * @param array $index
141: * @param string $separator
142: * @return string
143: */
144: public function prepareEntityIndex($index, $separator = ' ')
145: {
146: return Mage::helper('catalogsearch')->prepareIndexdata($index, $separator);
147: }
148:
149: /**
150: * Stub method for compatibility with other search engines
151: *
152: * @return null
153: */
154: public function getResourceName()
155: {
156: return null;
157: }
158:
159: /**
160: * Retrieve fulltext search result data collection
161: *
162: * @return Mage_CatalogSearch_Model_Resource_Fulltext_Collection
163: */
164: public function getResultCollection()
165: {
166: return Mage::getResourceModel('catalogsearch/fulltext_collection');
167: }
168:
169: /**
170: * Retrieve advanced search result data collection
171: *
172: * @return Mage_CatalogSearch_Model_Resource_Advanced_Collection
173: */
174: public function getAdvancedResultCollection()
175: {
176: return Mage::getResourceModel('catalogsearch/advanced_collection');
177: }
178:
179: /**
180: * Define if Layered Navigation is allowed
181: *
182: * @return bool
183: */
184: public function isLeyeredNavigationAllowed()
185: {
186: return true;
187: }
188:
189: /**
190: * Define if engine is avaliable
191: *
192: * @return bool
193: */
194: public function test()
195: {
196: return true;
197: }
198: }
199: