Example #1
0
 /**
  * Invalidate indexer on attribute save (searchable flag change)
  *
  * @param \Magento\Catalog\Model\Resource\Attribute $subject
  * @param \Closure $proceed
  * @param \Magento\Framework\Model\AbstractModel $attribute
  *
  * @return \Magento\Catalog\Model\Resource\Attribute
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundSave(\Magento\Catalog\Model\Resource\Attribute $subject, \Closure $proceed, \Magento\Framework\Model\AbstractModel $attribute)
 {
     $isNew = $attribute->isObjectNew();
     $needInvalidation = ($attribute->dataHasChangedFor('is_searchable') || $attribute->dataHasChangedFor('is_filterable') || $attribute->dataHasChangedFor('is_visible_in_advanced_search')) && !$isNew;
     $result = $proceed($attribute);
     if ($needInvalidation) {
         $this->indexerRegistry->get(Fulltext::INDEXER_ID)->invalidate();
     }
     if ($isNew || $needInvalidation) {
         $this->config->reset();
     }
     return $result;
 }
Example #2
0
 /**
  * Execute full indexation
  *
  * @return void
  */
 public function executeFull()
 {
     $storeIds = array_keys($this->storeManager->getStores());
     /** @var IndexerHandler $saveHandler */
     $saveHandler = $this->indexerHandlerFactory->create(['data' => $this->data]);
     foreach ($storeIds as $storeId) {
         $dimension = $this->dimensionFactory->create(['name' => 'scope', 'value' => $storeId]);
         $saveHandler->cleanIndex([$dimension]);
         $saveHandler->saveIndex([$dimension], $this->fullAction->rebuildStoreIndex($storeId));
     }
     $this->fulltextResource->resetSearchResults();
     $this->searchRequestConfig->reset();
 }
Example #3
0
 /**
  * Regenerate search index for store(s)
  *
  * @param int|array|null $productIds
  * @return void
  */
 protected function rebuildIndex($productIds = null)
 {
     $storeIds = array_keys($this->storeManager->getStores());
     foreach ($storeIds as $storeId) {
         $this->rebuildStoreIndex($storeId, $productIds);
     }
     $this->searchRequestConfig->reset();
 }
Example #4
0
 /**
  * Regenerate search index for all stores
  *
  * @param int|array|null $productIds
  * @return void
  */
 protected function rebuildIndex($productIds = null)
 {
     $storeIds = array_keys($this->storeManager->getStores());
     foreach ($storeIds as $storeId) {
         $dimension = $this->dimensionFactory->create(['name' => self::SCOPE_FIELD_NAME, 'value' => $storeId]);
         $this->indexHandler->deleteIndex([$dimension], $this->getIterator($productIds));
         $this->indexHandler->saveIndex([$dimension], $this->rebuildStoreIndex($storeId, $productIds));
     }
     $this->fulltextResource->resetSearchResults();
     $this->searchRequestConfig->reset();
 }
Example #5
0
 /**
  * Rebuild whole fulltext index for all stores
  *
  * @return void
  */
 public function reindexAll()
 {
     $storeIds = array_keys($this->storeManager->getStores());
     foreach ($storeIds as $storeId) {
         $this->cleanIndex($storeId);
         $this->rebuildStoreIndex($storeId);
     }
     $this->searchRequestConfig->reset();
 }