Algolia_Algoliasearch_Model_Resource_Engine::rebuildSuggestions PHP Метод

rebuildSuggestions() публичный Метод

public rebuildSuggestions ( )
    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;
    }

Usage Example

 /**
  * Rebuild all index data
  */
 public function reindexAll()
 {
     if (!$this->config->getApplicationID() || !$this->config->getAPIKey() || !$this->config->getSearchOnlyAPIKey()) {
         Mage::getSingleton('adminhtml/session')->addError('Algolia reindexing failed: You need to configure your Algolia credentials in System > Configuration > Algolia Search.');
         return;
     }
     $this->engine->rebuildSuggestions();
     return $this;
 }