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:  * Catalog search helper
 29:  *
 30:  * @author      Magento Core Team <core@magentocommerce.com>
 31:  */
 32: class Mage_CatalogSearch_Helper_Data extends Mage_Core_Helper_Abstract
 33: {
 34:     const QUERY_VAR_NAME = 'q';
 35:     const MAX_QUERY_LEN  = 200;
 36: 
 37:     /**
 38:      * Query object
 39:      *
 40:      * @var Mage_CatalogSearch_Model_Query
 41:      */
 42:     protected $_query;
 43: 
 44:     /**
 45:      * Query string
 46:      *
 47:      * @var string
 48:      */
 49:     protected $_queryText;
 50: 
 51:     /**
 52:      * Note messages
 53:      *
 54:      * @var array
 55:      */
 56:     protected $_messages = array();
 57: 
 58:     /**
 59:      * Is a maximum length cut
 60:      *
 61:      * @var bool
 62:      */
 63:     protected $_isMaxLength = false;
 64: 
 65:     /**
 66:      * Search engine model
 67:      *
 68:      * @var Mage_CatalogSearch_Model_Resource_Fulltext_Engine
 69:      */
 70:     protected $_engine;
 71: 
 72:     /**
 73:      * Retrieve search query parameter name
 74:      *
 75:      * @return string
 76:      */
 77:     public function getQueryParamName()
 78:     {
 79:         return self::QUERY_VAR_NAME;
 80:     }
 81: 
 82:     /**
 83:      * Retrieve query model object
 84:      *
 85:      * @return Mage_CatalogSearch_Model_Query
 86:      */
 87:     public function getQuery()
 88:     {
 89:         if (!$this->_query) {
 90:             $this->_query = Mage::getModel('catalogsearch/query')
 91:                 ->loadByQuery($this->getQueryText());
 92:             if (!$this->_query->getId()) {
 93:                 $this->_query->setQueryText($this->getQueryText());
 94:             }
 95:         }
 96:         return $this->_query;
 97:     }
 98: 
 99:     /**
100:      * Is a minimum query length
101:      *
102:      * @return bool
103:      */
104:     public function isMinQueryLength()
105:     {
106:         $minQueryLength = $this->getMinQueryLength();
107:         $thisQueryLength = Mage::helper('core/string')->strlen($this->getQueryText());
108:         return !$thisQueryLength || $minQueryLength !== '' && $thisQueryLength < $minQueryLength;
109:     }
110: 
111:     /**
112:      * Retrieve search query text
113:      *
114:      * @return string
115:      */
116:     public function getQueryText()
117:     {
118:         if (!isset($this->_queryText)) {
119:             $this->_queryText = $this->_getRequest()->getParam($this->getQueryParamName());
120:             if ($this->_queryText === null) {
121:                 $this->_queryText = '';
122:             } else {
123:                 /* @var $stringHelper Mage_Core_Helper_String */
124:                 $stringHelper = Mage::helper('core/string');
125:                 $this->_queryText = is_array($this->_queryText) ? ''
126:                     : $stringHelper->cleanString(trim($this->_queryText));
127: 
128:                 $maxQueryLength = $this->getMaxQueryLength();
129:                 if ($maxQueryLength !== '' && $stringHelper->strlen($this->_queryText) > $maxQueryLength) {
130:                     $this->_queryText = $stringHelper->substr($this->_queryText, 0, $maxQueryLength);
131:                     $this->_isMaxLength = true;
132:                 }
133:             }
134:         }
135:         return $this->_queryText;
136:     }
137: 
138:     /**
139:      * Retrieve HTML escaped search query
140:      *
141:      * @return string
142:      */
143:     public function getEscapedQueryText()
144:     {
145:         return $this->escapeHtml($this->getQueryText());
146:     }
147: 
148:     /**
149:      * Retrieve suggest collection for query
150:      *
151:      * @return Mage_CatalogSearch_Model_Resource_Query_Collection
152:      */
153:     public function getSuggestCollection()
154:     {
155:         return $this->getQuery()->getSuggestCollection();
156:     }
157: 
158:     /**
159:      * Retrieve result page url and set "secure" param to avoid confirm
160:      * message when we submit form from secure page to unsecure
161:      *
162:      * @param   string $query
163:      * @return  string
164:      */
165:     public function getResultUrl($query = null)
166:     {
167:         return $this->_getUrl('catalogsearch/result', array(
168:             '_query' => array(self::QUERY_VAR_NAME => $query),
169:             '_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()
170:         ));
171:     }
172: 
173:     /**
174:      * Retrieve suggest url
175:      *
176:      * @return string
177:      */
178:     public function getSuggestUrl()
179:     {
180:         return $this->_getUrl('catalogsearch/ajax/suggest', array(
181:             '_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()
182:         ));
183:     }
184: 
185:     /**
186:      * Retrieve search term url
187:      *
188:      * @return string
189:      */
190:     public function getSearchTermUrl()
191:     {
192:         return $this->_getUrl('catalogsearch/term/popular');
193:     }
194: 
195:     /**
196:      * Retrieve advanced search URL
197:      *
198:      * @return string
199:      */
200:     public function getAdvancedSearchUrl()
201:     {
202:         return $this->_getUrl('catalogsearch/advanced');
203:     }
204: 
205:     /**
206:      * Retrieve minimum query length
207:      *
208:      * @param mixed $store
209:      * @return int|string
210:      */
211:     public function getMinQueryLength($store = null)
212:     {
213:         return Mage::getStoreConfig(Mage_CatalogSearch_Model_Query::XML_PATH_MIN_QUERY_LENGTH, $store);
214:     }
215: 
216:     /**
217:      * Retrieve maximum query length
218:      *
219:      * @param mixed $store
220:      * @return int|string
221:      */
222:     public function getMaxQueryLength($store = null)
223:     {
224:         return Mage::getStoreConfig(Mage_CatalogSearch_Model_Query::XML_PATH_MAX_QUERY_LENGTH, $store);
225:     }
226: 
227:     /**
228:      * Retrieve maximum query words count for like search
229:      *
230:      * @param mixed $store
231:      * @return int
232:      */
233:     public function getMaxQueryWords($store = null)
234:     {
235:         return Mage::getStoreConfig(Mage_CatalogSearch_Model_Query::XML_PATH_MAX_QUERY_WORDS, $store);
236:     }
237: 
238:     /**
239:      * Add Note message
240:      *
241:      * @param string $message
242:      * @return Mage_CatalogSearch_Helper_Data
243:      */
244:     public function addNoteMessage($message)
245:     {
246:         $this->_messages[] = $message;
247:         return $this;
248:     }
249: 
250:     /**
251:      * Set Note messages
252:      *
253:      * @param array $messages
254:      * @return Mage_CatalogSearch_Helper_Data
255:      */
256:     public function setNoteMessages(array $messages)
257:     {
258:         $this->_messages = $messages;
259:         return $this;
260:     }
261: 
262:     /**
263:      * Retrieve Current Note messages
264:      *
265:      * @return array
266:      */
267:     public function getNoteMessages()
268:     {
269:         return $this->_messages;
270:     }
271: 
272:     /**
273:      * Check query of a warnings
274:      *
275:      * @param mixed $store
276:      * @return Mage_CatalogSearch_Helper_Data
277:      */
278:     public function checkNotes($store = null)
279:     {
280:         if ($this->_isMaxLength) {
281:             $this->addNoteMessage($this->__('Maximum Search query length is %s. Your query was cut.', $this->getMaxQueryLength()));
282:         }
283: 
284:         /* @var $stringHelper Mage_Core_Helper_String */
285:         $stringHelper = Mage::helper('core/string');
286: 
287:         $searchType = Mage::getStoreConfig(Mage_CatalogSearch_Model_Fulltext::XML_PATH_CATALOG_SEARCH_TYPE);
288:         if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE
289:             || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE
290:         ) {
291:             $wordsFull = $stringHelper->splitWords($this->getQueryText(), true);
292:             $wordsLike = $stringHelper->splitWords($this->getQueryText(), true, $this->getMaxQueryWords());
293:             if (count($wordsFull) > count($wordsLike)) {
294:                 $wordsCut = array_map(array($this, 'escapeHtml'), array_diff($wordsFull, $wordsLike));
295:                 $this->addNoteMessage(
296:                     $this->__('Maximum words count is %1$s. In your search query was cut next part: %2$s.', $this->getMaxQueryWords(), join(' ', $wordsCut))
297:                 );
298:             }
299:         }
300:     }
301: 
302:     /**
303:      * Join index array to string by separator
304:      * Support 2 level array gluing
305:      *
306:      * @param array $index
307:      * @param string $separator
308:      * @return string
309:      */
310:     public function prepareIndexdata($index, $separator = ' ')
311:     {
312:         $_index = array();
313:         foreach ($index as $value) {
314:             if (!is_array($value)) {
315:                 $_index[] = $value;
316:             }
317:             else {
318:                 $_index = array_merge($_index, $value);
319:             }
320:         }
321:         return join($separator, $_index);
322:     }
323: 
324:     /**
325:      * Get current search engine resource model
326:      *
327:      * @return object
328:      */
329:     public function getEngine()
330:     {
331:         if (!$this->_engine) {
332:             $engine = Mage::getStoreConfig('catalog/search/engine');
333: 
334:             /**
335:              * This needed if there already was saved in configuration some none-default engine
336:              * and module of that engine was disabled after that.
337:              * Problem is in this engine in database configuration still set.
338:              */
339:             if ($engine && Mage::getConfig()->getResourceModelClassName($engine)) {
340:                 $model = Mage::getResourceSingleton($engine);
341:                 if ($model && $model->test()) {
342:                     $this->_engine = $model;
343:                 }
344:             }
345:             if (!$this->_engine) {
346:                 $this->_engine = Mage::getResourceSingleton('catalogsearch/fulltext_engine');
347:             }
348:         }
349: 
350:         return $this->_engine;
351:     }
352: }
353: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0