Inheritance: extends Algolia_Algoliasearch_Helper_Entity_Helper
コード例 #1
0
 public function rebuildStoreSuggestionIndexPage($storeId, $collectionDefault, $page, $pageSize)
 {
     if ($this->config->isEnabledBackend($storeId) === false) {
         $this->logger->log('INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($storeId));
         return;
     }
     $collection = clone $collectionDefault;
     $collection->setCurPage($page)->setPageSize($pageSize);
     $collection->load();
     $index_name = $this->suggestion_helper->getIndexName($storeId) . '_tmp';
     if ($page == 1) {
         $this->algolia_helper->setSettings($index_name, $this->suggestion_helper->getIndexSettings($storeId));
     }
     $indexData = array();
     /** @var Mage_CatalogSearch_Model_Query $suggestion */
     foreach ($collection as $suggestion) {
         $suggestion->setStoreId($storeId);
         $suggestion_obj = $this->suggestion_helper->getObject($suggestion);
         if (strlen($suggestion_obj['query']) >= 3) {
             array_push($indexData, $suggestion_obj);
         }
     }
     if (count($indexData) > 0) {
         $this->algolia_helper->addObjects($indexData, $index_name);
     }
     unset($indexData);
     $collection->walk('clearInstance');
     $collection->clear();
     unset($collection);
 }
コード例 #2
0
 public function rebuildSuggestions()
 {
     /** @var Mage_Core_Model_Store $store */
     foreach (Mage::app()->getStores() as $store) {
         if ($this->config->isEnabledBackend($store->getId()) === false) {
             if (php_sapi_name() === 'cli') {
                 echo '[ALGOLIA] INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($store->getId()) . "\n";
             }
             /** @var Mage_Adminhtml_Model_Session $session */
             $session = Mage::getSingleton('adminhtml/session');
             $session->addWarning('[ALGOLIA] INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($store->getId()));
             $this->logger->log('INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($store->getId()));
             continue;
         }
         $size = $this->suggestion_helper->getSuggestionCollectionQuery($store->getId())->getSize();
         $by_page = $this->config->getNumberOfElementByPage();
         $nb_page = ceil($size / $by_page);
         for ($i = 1; $i <= $nb_page; $i++) {
             $data = array('store_id' => $store->getId(), 'page_size' => $by_page, 'page' => $i);
             $this->addToQueue('algoliasearch/observer', 'rebuildSuggestionIndex', $data, 1);
         }
         $this->addToQueue('algoliasearch/observer', 'moveStoreSuggestionIndex', array('store_id' => $store->getId()), 1);
     }
     return $this;
 }
コード例 #3
0
 public function rebuildSuggestionIndex(Varien_Object $event)
 {
     $storeId = $event->getStoreId();
     $page = $event->getPage();
     $pageSize = $event->getPageSize();
     if (is_null($storeId) && !empty($categoryIds)) {
         foreach (Mage::app()->getStores() as $storeId => $store) {
             if (!$store->getIsActive()) {
                 continue;
             }
             $this->helper->rebuildStoreSuggestionIndex($storeId);
         }
     } else {
         if (!empty($page) && !empty($pageSize)) {
             $this->helper->rebuildStoreSuggestionIndexPage($storeId, $this->suggestion_helper->getSuggestionCollectionQuery($storeId), $page, $pageSize);
         } else {
             $this->helper->rebuildStoreSuggestionIndex($storeId);
         }
     }
     return $this;
 }