/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Engine.php

https://bitbucket.org/acidel/buykoala · PHP · 189 lines · 75 code · 17 blank · 97 comment · 3 complexity · b6392897e4a818e87f5bd79c068a71c5 MD5 · raw file

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