Skip to content

Commit

Permalink
Merge pull request #448 from magento-dragons/bugs
Browse files Browse the repository at this point in the history
[DRAGONS] Bugs
  • Loading branch information
Kasian,Andrii(akasian) committed Jul 11, 2015
2 parents aa2088f + ea028e9 commit 2382298
Show file tree
Hide file tree
Showing 19 changed files with 489 additions and 335 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ protected function _afterSave(AbstractModel $object)
parent::_afterSave($object);
/** @var StockItemInterface $object */
if ($this->processIndexEvents) {
$this->stockIndexerProcessor->markIndexerAsInvalid();
$this->stockIndexerProcessor->reindexRow($object->getProductId());
}
return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ public function __construct(

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function process(FilterInterface $filter, $isNegation, $query, QueryContainer $queryContainer)
{
return $resultQuery = $this->processQueryWithField($filter, $isNegation, $query, $queryContainer);
return $this->processQueryWithField($filter, $isNegation, $query, $queryContainer);
}

/**
Expand Down
71 changes: 58 additions & 13 deletions app/code/Magento/CatalogSearch/Model/Search/IndexBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
use Magento\Framework\DB\Select;
use Magento\Framework\Search\Adapter\Mysql\ConditionManager;
use Magento\Framework\Search\Adapter\Mysql\IndexBuilderInterface;
use Magento\Framework\Search\Adapter\Mysql\ScoreBuilder;
use Magento\Framework\Search\Request\Dimension;
use Magento\Framework\Search\Request\Query\Bool;
use Magento\Framework\Search\Request\QueryInterface;
use Magento\Framework\Search\Request\QueryInterface as RequestQueryInterface;
use Magento\Framework\Search\RequestInterface;
use Magento\Search\Model\ScopeResolver\IndexScopeResolver;
use Magento\Store\Model\ScopeInterface;
Expand Down Expand Up @@ -82,22 +84,26 @@ public function build(RequestInterface $request)
['search_index' => $searchIndexTable],
['entity_id' => 'entity_id']
)
->joinLeft(
['category_index' => $this->resource->getTableName('catalog_category_product_index')],
'search_index.entity_id = category_index.product_id',
[]
)
->joinLeft(
['cea' => $this->resource->getTableName('catalog_eav_attribute')],
'search_index.attribute_id = cea.attribute_id',
[ScoreBuilder::WEIGHT_FIELD]
)
->joinLeft(
['cpie' => $this->resource->getTableName('catalog_product_index_eav')],
'search_index.entity_id = cpie.entity_id AND search_index.attribute_id = cpie.attribute_id',
[]
);

if ($this->isNeedToAddFilters($request)) {
$select
->joinLeft(
['category_index' => $this->resource->getTableName('catalog_category_product_index')],
'search_index.entity_id = category_index.product_id',
[]
)
->joinLeft(
['cpie' => $this->resource->getTableName('catalog_product_index_eav')],
'search_index.entity_id = cpie.entity_id AND search_index.attribute_id = cpie.attribute_id',
[]
);
}

$select = $this->processDimensions($request, $select);

$isShowOutOfStock = $this->config->isSetFlag(
Expand All @@ -113,8 +119,8 @@ public function build(RequestInterface $request)
$this->storeManager->getWebsite()->getId()
),
[]
)
->where('stock_index.stock_status = ?', 1);
);
$select->where('stock_index.stock_status = ?', 1);
}

return $select;
Expand Down Expand Up @@ -179,4 +185,43 @@ private function getSelect()
{
return $this->getReadConnection()->select();
}

/**
* @param RequestInterface $request
* @return bool
*/
private function isNeedToAddFilters(RequestInterface $request)
{
return $this->hasFilters($request->getQuery());
}

/**
* @param QueryInterface $query
* @return bool
*/
private function hasFilters(QueryInterface $query)
{
$hasFilters = false;
switch ($query->getType()) {
case RequestQueryInterface::TYPE_BOOL:
/** @var \Magento\Framework\Search\Request\Query\Bool $query */
foreach ($query->getMust() as $subQuery) {
$hasFilters |= $this->hasFilters($subQuery);
}
foreach ($query->getShould() as $subQuery) {
$hasFilters |= $this->hasFilters($subQuery);
}
foreach ($query->getMustNot() as $subQuery) {
$hasFilters |= $this->hasFilters($subQuery);
}
break;
case RequestQueryInterface::TYPE_FILTER:
$hasFilters |= true;
break;
default:
$hasFilters |= false;
break;
}
return $hasFilters;
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogSearch/Model/Source/Weight.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Weight
*
* @var int[]
*/
protected $_weights = [1, 2, 3, 4, 5];
protected $_weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

/**
* Retrieve search weights as options array
Expand Down
37 changes: 28 additions & 9 deletions app/code/Magento/CatalogSearch/Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Indexer\Model\IndexerInterfaceFactory;
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;

class InstallData implements InstallDataInterface
{
Expand All @@ -21,10 +22,29 @@ class InstallData implements InstallDataInterface

/**
* @param IndexerInterfaceFactory $indexerFactory
* @param ProductAttributeRepositoryInterface $attributeRepository
*/
public function __construct(IndexerInterfaceFactory $indexerFactory)
{
public function __construct(
IndexerInterfaceFactory $indexerFactory,
ProductAttributeRepositoryInterface $attributeRepository
) {
$this->indexerFactory = $indexerFactory;
$this->attributeRepository = $attributeRepository;
}

/**
* Installs data for a module
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$this->setWeight('sku', 6);
$this->setWeight('name', 5);
$this->getIndexer('catalogsearch_fulltext')->reindexAll();
}

/**
Expand All @@ -37,15 +57,14 @@ private function getIndexer($indexerId)
}

/**
* Installs data for a module
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
* @param string $attributeCode
* @param int $weight
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
private function setWeight($attributeCode, $weight)
{
$this->getIndexer('catalogsearch_fulltext')->reindexAll();
$attribute = $this->attributeRepository->get($attributeCode);
$attribute->setSearchWeight($weight);
$this->attributeRepository->save($attribute);
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogSearch/Setup/InstallSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_FLOAT,
'unsigned' => true,
'nullable' => false,
'default' => '3',
'default' => '1',
'comment' => 'Search Weight'
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ protected function setUp()

$this->request = $this->getMockBuilder('\Magento\Framework\Search\RequestInterface')
->disableOriginalConstructor()
->setMethods(['getIndex', 'getDimensions'])
->setMethods(['getIndex', 'getDimensions', 'getQuery'])
->getMockForAbstractClass();
$this->request->expects($this->once())
->method('getQuery')
->willReturn(
$this->getMockBuilder('Magento\Framework\Search\Request\QueryInterface')->getMockForAbstractClass()
);

$this->config = $this->getMockBuilder('\Magento\Framework\App\Config\ScopeConfigInterface')
->disableOriginalConstructor()
Expand Down Expand Up @@ -157,7 +162,7 @@ public function testBuildWithoutOutOfStock()
->method('getDimensions')
->willReturn($dimensions);

$this->mockBuild($index, $tableSuffix);
$this->mockBuild($index, $tableSuffix, false);

$this->config->expects($this->once())
->method('isSetFlag')
Expand All @@ -168,11 +173,11 @@ public function testBuildWithoutOutOfStock()
$website = $this->getMockBuilder('Magento\Store\Model\Website')->disableOriginalConstructor()->getMock();
$website->expects($this->once())->method('getId')->willReturn(1);
$this->storeManager->expects($this->once())->method('getWebsite')->willReturn($website);
$this->select->expects($this->at(4))
$this->select->expects($this->at(2))
->method('where')
->with('(someName=someValue)')
->willReturnSelf();
$this->select->expects($this->at(5))
$this->select->expects($this->at(3))
->method('joinLeft')
->with(
['stock_index' => 'cataloginventory_stock_status'],
Expand All @@ -181,7 +186,7 @@ public function testBuildWithoutOutOfStock()
[]
)
->willReturnSelf();
$this->select->expects($this->at(6))
$this->select->expects($this->at(4))
->method('where')
->with('stock_index.stock_status = ?', 1)
->will($this->returnSelf());
Expand All @@ -190,7 +195,7 @@ public function testBuildWithoutOutOfStock()
$this->assertSame($this->select, $result);
}

protected function mockBuild($index, $tableSuffix)
protected function mockBuild($index, $tableSuffix, $hasFilters = false)
{
$this->request->expects($this->atLeastOnce())
->method('getIndex')
Expand Down Expand Up @@ -220,7 +225,7 @@ function ($index, $dimensions) {
)
);

$this->select->expects($this->once())
$this->select->expects($this->at(0))
->method('from')
->with(
['search_index' => $index . '_' . $tableSuffix],
Expand All @@ -229,30 +234,31 @@ function ($index, $dimensions) {
->will($this->returnSelf());

$this->select->expects($this->at(1))
->method('joinLeft')
->with(
['category_index' => 'catalog_category_product_index'],
'search_index.entity_id = category_index.product_id',
[]
)
->will($this->returnSelf());

$this->select->expects($this->at(2))
->method('joinLeft')
->with(
['cea' => 'catalog_eav_attribute'],
'search_index.attribute_id = cea.attribute_id',
['search_weight']
)
->will($this->returnSelf());
$this->select->expects($this->at(3))
->method('joinLeft')
->with(
['cpie' => $this->resource->getTableName('catalog_product_index_eav')],
'search_index.entity_id = cpie.entity_id AND search_index.attribute_id = cpie.attribute_id',
[]
)
->willReturnSelf();
->will($this->returnSelf());
if ($hasFilters) {
$this->select->expects($this->at(2))
->method('joinLeft')
->with(
['category_index' => 'catalog_category_product_index'],
'search_index.entity_id = category_index.product_id',
[]
)
->will($this->returnSelf());
$this->select->expects($this->at(3))
->method('joinLeft')
->with(
['cpie' => $this->resource->getTableName('catalog_product_index_eav')],
'search_index.entity_id = cpie.entity_id AND search_index.attribute_id = cpie.attribute_id',
[]
)
->willReturnSelf();
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Indexer/etc/crontab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Cron/etc/crontab.xsd">
<group id="default">
<group id="index">
<job name="indexer_reindex_all_invalid" instance="Magento\Indexer\Model\Processor" method="reindexAllInvalid">
<schedule>* * * * *</schedule>
</job>
Expand Down
Loading

0 comments on commit 2382298

Please sign in to comment.