Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_CatalogSearch_AdvancedController
  • Mage_CatalogSearch_AjaxController
  • Mage_CatalogSearch_Block_Advanced_Form
  • Mage_CatalogSearch_Block_Advanced_Result
  • Mage_CatalogSearch_Block_Autocomplete
  • Mage_CatalogSearch_Block_Layer
  • Mage_CatalogSearch_Block_Layer_Filter_Attribute
  • Mage_CatalogSearch_Block_Result
  • Mage_CatalogSearch_Block_Term
  • Mage_CatalogSearch_Helper_Data
  • Mage_CatalogSearch_Model_Advanced
  • Mage_CatalogSearch_Model_Fulltext
  • Mage_CatalogSearch_Model_Fulltext_Observer
  • Mage_CatalogSearch_Model_Indexer_Fulltext
  • Mage_CatalogSearch_Model_Layer
  • Mage_CatalogSearch_Model_Layer_Filter_Attribute
  • Mage_CatalogSearch_Model_Mysql4_Advanced
  • Mage_CatalogSearch_Model_Mysql4_Advanced_Collection
  • Mage_CatalogSearch_Model_Mysql4_Fulltext
  • Mage_CatalogSearch_Model_Mysql4_Fulltext_Collection
  • Mage_CatalogSearch_Model_Mysql4_Fulltext_Engine
  • Mage_CatalogSearch_Model_Mysql4_Indexer_Fulltext
  • Mage_CatalogSearch_Model_Mysql4_Query
  • Mage_CatalogSearch_Model_Mysql4_Query_Collection
  • Mage_CatalogSearch_Model_Mysql4_Search_Collection
  • Mage_CatalogSearch_Model_Query
  • Mage_CatalogSearch_Model_Resource_Advanced
  • Mage_CatalogSearch_Model_Resource_Advanced_Collection
  • Mage_CatalogSearch_Model_Resource_Fulltext
  • Mage_CatalogSearch_Model_Resource_Fulltext_Collection
  • Mage_CatalogSearch_Model_Resource_Fulltext_Engine
  • Mage_CatalogSearch_Model_Resource_Indexer_Fulltext
  • Mage_CatalogSearch_Model_Resource_Query
  • Mage_CatalogSearch_Model_Resource_Query_Collection
  • Mage_CatalogSearch_Model_Resource_Search_Collection
  • Mage_CatalogSearch_Model_Session
  • Mage_Catalogsearch_Model_System_Config_Backend_Sitemap
  • Mage_CatalogSearch_ResultController
  • Mage_CatalogSearch_TermController
  • Overview
  • Package
  • Class
  • Tree
  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:  * Catalog search query collection
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_CatalogSearch
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_CatalogSearch_Model_Resource_Query_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
 36: {
 37:     /**
 38:      * Store for filter
 39:      *
 40:      * @var int
 41:      */
 42:     protected $_storeId;
 43: 
 44:     /**
 45:      * Init model for collection
 46:      *
 47:      */
 48:     protected function _construct()
 49:     {
 50:         $this->_init('catalogsearch/query');
 51:     }
 52: 
 53:     /**
 54:      * Set Store ID for filter
 55:      *
 56:      * @param mixed $store
 57:      * @return Mage_CatalogSearch_Model_Resource_Query_Collection
 58:      */
 59:     public function setStoreId($store)
 60:     {
 61:         if ($store instanceof Mage_Core_Model_Store) {
 62:             $store = $store->getId();
 63:         }
 64:         $this->_storeId = $store;
 65:         return $this;
 66:     }
 67: 
 68:     /**
 69:      * Retrieve Store ID Filter
 70:      *
 71:      * @return int|null
 72:      */
 73:     public function getStoreId()
 74:     {
 75:         return $this->_storeId;
 76:     }
 77: 
 78:     /**
 79:      * Set search query text to filter
 80:      *
 81:      * @param string $query
 82:      * @return Mage_CatalogSearch_Model_Resource_Query_Collection
 83:      */
 84:     public function setQueryFilter($query)
 85:     {
 86:         $ifSynonymFor = $this->getConnection()
 87:             ->getIfNullSql('synonym_for', 'query_text');
 88:         $this->getSelect()->reset(Zend_Db_Select::FROM)->distinct(true)
 89:             ->from(
 90:                 array('main_table' => $this->getTable('catalogsearch/search_query')),
 91:                 array('query'      => $ifSynonymFor, 'num_results')
 92:             )
 93:             ->where('num_results > 0 AND display_in_terms = 1 AND query_text LIKE ?',
 94:                 Mage::getResourceHelper('core')->addLikeEscape($query, array('position' => 'start')))
 95:             ->order('popularity ' . Varien_Db_Select::SQL_DESC);
 96:         if ($this->getStoreId()) {
 97:             $this->getSelect()
 98:                 ->where('store_id = ?', (int)$this->getStoreId());
 99:         }
100:         return $this;
101:     }
102: 
103:     /**
104:      * Set Popular Search Query Filter
105:      *
106:      * @param int|array $storeIds
107:      * @return Mage_CatalogSearch_Model_Resource_Query_Collection
108:      */
109:     public function setPopularQueryFilter($storeIds = null)
110:     {
111:         $ifSynonymFor = new Zend_Db_Expr($this->getConnection()
112:             ->getCheckSql("synonym_for IS NOT NULL AND synonym_for != ''", 'synonym_for', 'query_text'));
113: 
114:         $this->getSelect()
115:             ->reset(Zend_Db_Select::FROM)
116:             ->reset(Zend_Db_Select::COLUMNS)
117:             ->distinct(true)
118:             ->from(
119:                 array('main_table' => $this->getTable('catalogsearch/search_query')),
120:                 array('name' => $ifSynonymFor, 'num_results', 'popularity')
121:             );
122:         if ($storeIds) {
123:             $this->addStoreFilter($storeIds);
124:             $this->getSelect()->where('num_results > 0');
125:         }
126:         elseif (null === $storeIds) {
127:             $this->addStoreFilter(Mage::app()->getStore()->getId());
128:             $this->getSelect()->where('num_results > 0');
129:         }
130: 
131:         $this->getSelect()->order(array('popularity desc','name'));
132: 
133:         return $this;
134:     }
135: 
136:     /**
137:      * Set Recent Queries Order
138:      *
139:      * @return Mage_CatalogSearch_Model_Resource_Query_Collection
140:      */
141:     public function setRecentQueryFilter()
142:     {
143:         $this->setOrder('updated_at', 'desc');
144:         return $this;
145:     }
146: 
147:     /**
148:      * Filter collection by specified store ids
149:      *
150:      * @param array|int $storeIds
151:      * @return Mage_CatalogSearch_Model_Resource_Query_Collection
152:      */
153:     public function addStoreFilter($storeIds)
154:     {
155:         if (!is_array($storeIds)) {
156:             $storeIds = array($storeIds);
157:         }
158:         $this->getSelect()->where('main_table.store_id IN (?)', $storeIds);
159:         return $this;
160:     }
161: }
162: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0