Skip to content

Commit

Permalink
Merge pull request #34 from afoucret/feature-index_handler_refactor
Browse files Browse the repository at this point in the history
Feature index handler refactor
  • Loading branch information
afoucret committed May 20, 2016
2 parents e25f54d + 4d640c3 commit f092d51
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Framework\Search\Request\DimensionFactory;
use Magento\Store\Model\StoreManagerInterface;
use Smile\ElasticSuiteCatalog\Model\Category\Indexer\Fulltext\Action\Full;
use Magento\Framework\Indexer\SaveHandler\IndexerInterface;

/**
* Categories fulltext indexer
Expand All @@ -34,7 +35,7 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F
protected $data;

/**
* @var IndexerHandler
* @var IndexerInterface
*/
private $indexerHandler;

Expand All @@ -55,14 +56,14 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F

/**
* @param Full $fullAction The full index action
* @param IndexerHandler $indexerHandler The index handler
* @param IndexerInterface $indexerHandler The index handler
* @param StoreManagerInterface $storeManager The Store Manager
* @param DimensionFactory $dimensionFactory The dimension factory
* @param array $data The data
*/
public function __construct(
Full $fullAction,
IndexerHandler $indexerHandler,
IndexerInterface $indexerHandler,
StoreManagerInterface $storeManager,
DimensionFactory $dimensionFactory,
array $data
Expand All @@ -84,12 +85,11 @@ public function __construct(
public function execute($ids)
{
$storeIds = array_keys($this->storeManager->getStores());
/** @var IndexerHandler $saveHandler */
$saveHandler = $this->indexerHandler;

foreach ($storeIds as $storeId) {
$dimension = $this->dimensionFactory->create(['name' => 'scope', 'value' => $storeId]);
$saveHandler->deleteIndex([$dimension], new \ArrayObject($ids));
$saveHandler->saveIndex([$dimension], $this->fullAction->rebuildStoreIndex($storeId, $ids));
$this->indexerHandler->deleteIndex([$dimension], new \ArrayObject($ids));
$this->indexerHandler->saveIndex([$dimension], $this->fullAction->rebuildStoreIndex($storeId, $ids));
}
}

Expand All @@ -102,13 +102,10 @@ public function executeFull()
{
$storeIds = array_keys($this->storeManager->getStores());

/** @var IndexerHandler $saveHandler */
$saveHandler = $this->indexerHandler;

foreach ($storeIds as $storeId) {
$dimension = $this->dimensionFactory->create(['name' => 'scope', 'value' => $storeId]);
$saveHandler->cleanIndex([$dimension]);
$saveHandler->saveIndex([$dimension], $this->fullAction->rebuildStoreIndex($storeId));
$this->indexerHandler->cleanIndex([$dimension]);
$this->indexerHandler->saveIndex([$dimension], $this->fullAction->rebuildStoreIndex($storeId));
}

}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Smile\ElasticSuiteCatalog\Model\ResourceModel\Category\Indexer\Fulltext\Action;

use Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer\AbstractIndexer;
use Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer\Indexer;

/**
* ElasticSearch category full indexer resource model.
Expand All @@ -22,7 +22,7 @@
* @package Smile_ElasticSuiteCatalog
* @author Aurelien FOUCRET <[email protected]>
*/
class Full extends AbstractIndexer
class Full extends Indexer
{
/**
* Load a bulk of category data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer\Fulltext\Datasource;

use Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer\AbstractIndexer;
use Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer\Indexer;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection as AttributeCollection;

/**
Expand All @@ -23,7 +23,7 @@
* @package Smile_ElasticSuiteCatalog
* @author Romain Ruaud <[email protected]>
*/
class AbstractAttributeData extends AbstractIndexer
class AbstractAttributeData extends Indexer
{
/**
* @var array
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
* versions in the future.
*
* @category Smile
* @package Smile_ElasticSuiteCore
* @author Aurelien FOUCRET <[email protected]>
* @author Fanny DECLERCK <[email protected]>
* @copyright 2016 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer;

use Magento\Framework\App\ResourceConnection;
use Smile\ElasticSuiteCore\Model\ResourceModel\Indexer\AbstractIndexer;

/**
* This class provides a lot of util methods used by Eav indexer related resource models.
*
* @category Smile
* @package Smile_ElasticSuiteCatalog
* @author Aurelien FOUCRET <[email protected]>
* @author Fanny DECLERCK <[email protected]>
*/
class Indexer extends AbstractIndexer
{
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;

/**
* Retrieve store root category id.
*
* @param \Magento\Store\Api\Data\StoreInterface|int|string $store Store id.
*
* @return integer
*/
protected function getRootCategoryId($store)
{
if (is_numeric($store) || is_string($store)) {
$store = $this->getStore($store);
}

$storeGroupId = $store->getStoreGroupId();

return $this->storeManager->getGroup($storeGroupId)->getRootCategoryId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Smile\ElasticSuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Action;

use Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer\AbstractIndexer;
use Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer\Indexer;

/**
* ElasticSearch product full indexer resource model.
Expand All @@ -23,7 +23,7 @@
* @package Smile_ElasticSuiteCatalog
* @author Aurelien FOUCRET <[email protected]>
*/
class Full extends AbstractIndexer
class Full extends Indexer
{
/**
* Load a bulk of product data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Magento\Eav\Model\Config;
use Magento\Framework\App\ResourceConnection;
use Magento\Store\Model\StoreManagerInterface;
use Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer\AbstractIndexer;
use Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer\Indexer;

/**
* Categories data datasource resource model.
Expand All @@ -26,7 +26,7 @@
* @package Smile_ElasticSuiteCatalog
* @author Aurelien FOUCRET <[email protected]>
*/
class CategoryData extends AbstractIndexer
class CategoryData extends Indexer
{
/**
* @var array Local cache for category names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Magento\CatalogInventory\Api\StockRegistryInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Store\Model\StoreManagerInterface;
use Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer\AbstractIndexer;
use Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer\Indexer;

/**
* Catalog Inventory Data source resource model
Expand All @@ -24,7 +24,7 @@
* @package Smile_ElasticSuiteCatalog
* @author Romain Ruaud <[email protected]>
*/
class InventoryData extends AbstractIndexer
class InventoryData extends Indexer
{
/**
* @var \Magento\CatalogInventory\Api\StockRegistryInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Smile\ElasticSuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource;

use Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer\AbstractIndexer;
use Smile\ElasticSuiteCatalog\Model\ResourceModel\Eav\Indexer\Indexer;

/**
* Prices data datasource resource model.
Expand All @@ -23,7 +23,7 @@
* @package Smile_ElasticSuiteCatalog
* @author Aurelien FOUCRET <[email protected]>
*/
class PriceData extends AbstractIndexer
class PriceData extends Indexer
{
/**
* Load prices data for a list of product ids and a given store.
Expand Down
22 changes: 21 additions & 1 deletion src/module-elasticsuite-catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

<virtualType name="catalogProductSearchIndexHandler" type="\Smile\ElasticSuiteCore\Indexer\GenericIndexerHandler">
<arguments>
<argument name="indexName" xsi:type="string">catalog_product</argument>
<argument name="typeName" xsi:type="string">product</argument>
</arguments>
</virtualType>

<type name="Magento\CatalogSearch\Model\Indexer\IndexerHandlerFactory">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="elasticsuite" xsi:type="string">Smile\ElasticSuiteCatalog\Model\Product\Indexer\IndexerHandler</item>
<item name="elasticsuite" xsi:type="string">catalogProductSearchIndexHandler</item>
</argument>
</arguments>
</type>
Expand Down Expand Up @@ -107,6 +114,19 @@
<plugin name="smile_elasticsuite_catalog_reindex_products_after_price_reindex" type="\Smile\ElasticSuiteCatalog\Plugin\Indexer\Price\ReindexProductsAfterPriceUpdate"/>
</type>

<virtualType name="catalogCategorySearchIndexHandler" type="\Smile\ElasticSuiteCore\Indexer\GenericIndexerHandler">
<arguments>
<argument name="indexName" xsi:type="string">catalog_category</argument>
<argument name="typeName" xsi:type="string">category</argument>
</arguments>
</virtualType>

<type name="Smile\ElasticSuiteCatalog\Model\Category\Indexer\Fulltext">
<arguments>
<argument name="indexerHandler" xsi:type="object">catalogCategorySearchIndexHandler</argument>
</arguments>
</type>

<type name="Smile\ElasticSuiteCatalog\Model\Category\Indexer\Fulltext\Datasource\AttributeData">
<arguments>
<argument name="attributeHelper" xsi:type="object">Smile\ElasticSuiteCatalog\Helper\CategoryAttribute</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @license Open Software License ("OSL") v. 3.0
*/

namespace Smile\ElasticSuiteCatalog\Model\Eav\Indexer;
namespace Smile\ElasticSuiteCore\Indexer;

use Magento\Framework\Indexer\SaveHandler\IndexerInterface;
use Smile\ElasticSuiteCore\Api\Index\IndexOperationInterface;
Expand All @@ -24,8 +24,9 @@
* @package Smile_ElasticSuiteCatalog
* @author Aurelien FOUCRET <[email protected]>
* @author Romain Ruaud <[email protected]>
* @author Fanny DECLERCK <[email protected]>
*/
class IndexerHandler implements IndexerInterface
class GenericIndexerHandler implements IndexerInterface
{
/**
* @var \Smile\ElasticSuiteCore\Api\Index\IndexOperationInterface
Expand Down
Loading

0 comments on commit f092d51

Please sign in to comment.