Skip to content

Commit b0fa8b7

Browse files
author
Kasian,Andrii(akasian)
committed
Merge pull request #346 from magento-dragons/develop
[DRAGONS] Sprint 68
2 parents 10d303f + a8077af commit b0fa8b7

File tree

51 files changed

+1692
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1692
-253
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Front.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ protected function _prepareForm()
224224
)
225225
);
226226

227+
$this->setForm($form);
227228
$form->setValues($attributeObject->getData());
228229
$this->propertyLocker->lock($form);
229-
$this->setForm($form);
230230
return parent::_prepareForm();
231231
}
232232
}

app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Field/Resolver.php

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,63 @@
55
*/
66
namespace Magento\CatalogSearch\Model\Adapter\Mysql\Field;
77

8+
use Magento\Catalog\Model\Resource\Product\Attribute\Collection as AttributeCollection;
9+
use Magento\Framework\Search\Adapter\Mysql\Field\FieldFactory;
10+
use Magento\Framework\Search\Adapter\Mysql\Field\FieldInterface;
811
use Magento\Framework\Search\Adapter\Mysql\Field\ResolverInterface;
912

1013
class Resolver implements ResolverInterface
1114
{
15+
/**
16+
* @var AttributeCollection
17+
*/
18+
private $attributeCollection;
19+
/**
20+
* @var FieldFactory
21+
*/
22+
private $fieldFactory;
23+
24+
/**
25+
* @param AttributeCollection $attributeCollection
26+
* @param FieldFactory $fieldFactory
27+
*/
28+
public function __construct(
29+
AttributeCollection $attributeCollection,
30+
FieldFactory $fieldFactory
31+
) {
32+
$this->attributeCollection = $attributeCollection;
33+
$this->fieldFactory = $fieldFactory;
34+
}
35+
1236
/**
1337
* {@inheritdoc}
1438
*/
15-
public function resolve($fields)
39+
public function resolve(array $fields)
1640
{
17-
return 'data_index';
41+
$resolvedFields = [];
42+
foreach ($fields as $field) {
43+
if ('*' === $field) {
44+
$resolvedFields = [
45+
$this->fieldFactory->create(
46+
[
47+
'attributeId' => null,
48+
'column' => 'data_index',
49+
'type' => FieldInterface::TYPE_FULLTEXT
50+
]
51+
)
52+
];
53+
break;
54+
}
55+
$attribute = $this->attributeCollection->getItemByColumnValue('attribute_code', $field);
56+
$attributeId = $attribute ? $attribute->getId() : 0;
57+
$resolvedFields[$field] = $this->fieldFactory->create(
58+
[
59+
'attributeId' => $attributeId,
60+
'column' => 'data_index',
61+
'type' => FieldInterface::TYPE_FULLTEXT
62+
]
63+
);
64+
}
65+
return $resolvedFields;
1866
}
1967
}

app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\DB\Adapter\AdapterInterface;
1212
use Magento\Framework\Search\Adapter\Mysql\ConditionManager;
1313
use Magento\Framework\Search\Adapter\Mysql\Filter\PreprocessorInterface;
14+
use Magento\Framework\Search\Adapter\Mysql\Query\QueryContainer;
1415
use Magento\Framework\Search\Request\FilterInterface;
1516

1617
class Preprocessor implements PreprocessorInterface
@@ -65,24 +66,24 @@ public function __construct(
6566
* {@inheritdoc}
6667
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
6768
*/
68-
public function process(FilterInterface $filter, $isNegation, $query)
69+
public function process(FilterInterface $filter, $isNegation, $query, QueryContainer $queryContainer)
6970
{
70-
return $resultQuery = $this->processQueryWithField($filter, $isNegation, $query);
71+
return $resultQuery = $this->processQueryWithField($filter, $isNegation, $query, $queryContainer);
7172
}
7273

7374
/**
7475
* @param FilterInterface $filter
7576
* @param bool $isNegation
7677
* @param string $query
78+
* @param QueryContainer $queryContainer
7779
* @return string
78-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
7980
*/
80-
private function processQueryWithField(FilterInterface $filter, $isNegation, $query)
81+
private function processQueryWithField(FilterInterface $filter, $isNegation, $query, QueryContainer $queryContainer)
8182
{
8283
$currentStoreId = $this->scopeResolver->getScope()->getId();
8384

8485
$attribute = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $filter->getField());
85-
$select = $this->getSelect();
86+
$select = $this->getConnection()->select();
8687
$table = $attribute->getBackendTable();
8788
if ($filter->getField() == 'price') {
8889
$query = str_replace('price', 'min_price', $query);
@@ -96,17 +97,23 @@ private function processQueryWithField(FilterInterface $filter, $isNegation, $qu
9697
->where($query);
9798
} else {
9899
if ($filter->getType() == FilterInterface::TYPE_TERM) {
99-
$field = $filter->getField();
100-
$mapper = function ($value) use ($field, $isNegation) {
101-
return ($isNegation ? '-' : '') . $this->attributePrefix . $field . '_' . $value;
102-
};
103100
if (is_array($filter->getValue())) {
104-
$value = implode(' ', array_map($mapper, $filter->getValue()));
101+
$value = sprintf(
102+
'%s IN (%s)',
103+
($isNegation ? 'NOT' : ''),
104+
implode(',', $filter->getValue())
105+
);
105106
} else {
106-
$value = $mapper($filter->getValue());
107+
$value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
107108
}
108-
109-
return 'MATCH (data_index) AGAINST (' . $this->getConnection()->quote($value) . ' IN BOOLEAN MODE)';
109+
$filterQuery = sprintf(
110+
'cpie.store_id = %d AND cpie.attribute_id = %d AND cpie.value %s',
111+
$this->scopeResolver->getScope()->getId(),
112+
$attribute->getId(),
113+
$value
114+
);
115+
$queryContainer->addFilter($filterQuery);
116+
return '';
110117
}
111118
$ifNullCondition = $this->getConnection()->getIfNullSql('current_store.value', 'main_table.value');
112119

@@ -139,12 +146,4 @@ private function getConnection()
139146
{
140147
return $this->resource->getConnection(Resource::DEFAULT_READ_RESOURCE);
141148
}
142-
143-
/**
144-
* @return \Magento\Framework\DB\Select
145-
*/
146-
private function getSelect()
147-
{
148-
return $this->getConnection()->select();
149-
}
150149
}

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/Full.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -651,15 +651,20 @@ protected function prepareProductIndex($indexData, $productData, $storeId)
651651
$attributeCode = $attribute->getAttributeCode();
652652

653653
if (isset($productData[$attributeCode])) {
654+
655+
if ('store_id' === $attributeCode) {
656+
continue;
657+
}
658+
654659
$value = $this->getAttributeValue($attribute->getId(), $productData[$attributeCode], $storeId);
655660
if ($value) {
656-
if (isset($index[$attributeCode])) {
657-
if (!is_array($index[$attributeCode])) {
658-
$index[$attributeCode] = [$index[$attributeCode]];
661+
if (isset($index[$attribute->getId()])) {
662+
if (!is_array($index[$attribute->getId()])) {
663+
$index[$attribute->getId()] = [$index[$attribute->getId()]];
659664
}
660-
$index[$attributeCode][] = $value;
665+
$index[$attribute->getId()][] = $value;
661666
} else {
662-
$index[$attributeCode] = $value;
667+
$index[$attribute->getId()] = $value;
663668
}
664669
}
665670
}
@@ -669,12 +674,10 @@ protected function prepareProductIndex($indexData, $productData, $storeId)
669674
foreach ($attributeData as $attributeId => $attributeValue) {
670675
$value = $this->getAttributeValue($attributeId, $attributeValue, $storeId);
671676
if (!empty($value)) {
672-
$attributeCode = $this->getSearchableAttribute($attributeId)->getAttributeCode();
673-
674-
if (isset($index[$attributeCode])) {
675-
$index[$attributeCode][$entityId] = $value;
677+
if (isset($index[$attributeId])) {
678+
$index[$attributeId][$entityId] = $value;
676679
} else {
677-
$index[$attributeCode] = [$entityId => $value];
680+
$index[$attributeId] = [$entityId => $value];
678681
}
679682
}
680683
}

app/code/Magento/CatalogSearch/Model/Resource/Engine.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function __construct(
6666
*/
6767
protected function _construct()
6868
{
69-
$this->_init('catalogsearch_fulltext', 'product_id');
69+
$this->_init('catalogsearch_fulltext_index_default', 'product_id');
7070
}
7171

7272
/**
@@ -102,9 +102,15 @@ public function saveEntityIndex($entityId, $storeId, $index, $entity = 'product'
102102
public function saveEntityIndexes($storeId, $entityIndexes, $entity = 'product')
103103
{
104104
$data = [];
105-
$storeId = (int)$storeId;
106-
foreach ($entityIndexes as $entityId => $index) {
107-
$data[] = ['product_id' => (int)$entityId, 'store_id' => $storeId, 'data_index' => $index];
105+
foreach ($entityIndexes as $entityId => $productAttributes) {
106+
foreach ($productAttributes as $attributeId => $indexValue) {
107+
$data[] = [
108+
'product_id' => (int)$entityId,
109+
'attribute_id' =>(int)$attributeId,
110+
'store_id' => (int)$storeId,
111+
'data_index' => $indexValue
112+
];
113+
}
108114
}
109115

110116
if ($data) {
@@ -187,10 +193,6 @@ public function cleanIndex($storeId = null, $entityId = null, $entity = 'product
187193
{
188194
$where = [];
189195

190-
if ($storeId !== null) {
191-
$where[] = $this->_getWriteAdapter()
192-
->quoteInto('store_id=?', $storeId);
193-
}
194196
if ($entityId !== null) {
195197
$where[] = $this->_getWriteAdapter()
196198
->quoteInto('product_id IN (?)', $entityId);

app/code/Magento/CatalogSearch/Model/Search/IndexBuilder.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\App\Resource;
1111
use Magento\Framework\DB\Select;
1212
use Magento\Framework\Search\Adapter\Mysql\IndexBuilderInterface;
13+
use Magento\Framework\Search\Adapter\Mysql\ScoreBuilder;
1314
use Magento\Framework\Search\RequestInterface;
1415
use Magento\Store\Model\ScopeInterface;
1516
use Magento\Store\Model\StoreManagerInterface;
@@ -54,16 +55,27 @@ public function __construct(Resource $resource, ScopeConfigInterface $config, St
5455
*/
5556
public function build(RequestInterface $request)
5657
{
58+
$tableName = [$request->getIndex(), 'index_default'];
5759
$select = $this->getSelect()
5860
->from(
59-
['search_index' => $this->resource->getTableName($request->getIndex())],
60-
['entity_id' => 'search_index.product_id']
61+
['search_index' => $this->resource->getTableName($tableName)],
62+
['entity_id' => 'product_id']
6163
)
6264
->joinLeft(
6365
['category_index' => $this->resource->getTableName('catalog_category_product_index')],
6466
'search_index.product_id = category_index.product_id'
6567
. ' AND search_index.store_id = category_index.store_id',
6668
[]
69+
)
70+
->joinLeft(
71+
['cea' => $this->resource->getTableName('catalog_eav_attribute')],
72+
'search_index.attribute_id = cea.attribute_id',
73+
[ScoreBuilder::WEIGHT_FIELD]
74+
)
75+
->joinLeft(
76+
['cpie' => $this->resource->getTableName('catalog_product_index_eav')],
77+
'search_index.product_id = cpie.entity_id AND search_index.attribute_id = cpie.attribute_id',
78+
[]
6779
);
6880

6981
$isShowOutOfStock = $this->config->isSetFlag(
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogSearch\Setup;
8+
9+
10+
use Magento\Framework\DB\Adapter\AdapterInterface;
11+
use Magento\Framework\DB\Ddl\Table;
12+
use Magento\Framework\Setup\UpgradeSchemaInterface;
13+
use Magento\Framework\Setup\ModuleContextInterface;
14+
use Magento\Framework\Setup\SchemaSetupInterface;
15+
16+
/**
17+
* @codeCoverageIgnore
18+
*/
19+
class UpgradeSchema implements UpgradeSchemaInterface
20+
{
21+
/**
22+
* {@inheritdoc}
23+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
24+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
25+
* @SuppressWarnings(PHPMD.NPathComplexity)
26+
*/
27+
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
28+
{
29+
$installer = $setup;
30+
$connection = $installer->getConnection();
31+
if (version_compare($context->getVersion(), '2.0.1') < 0) {
32+
$connection->dropTable($installer->getTable('catalogsearch_fulltext'));
33+
$table = $connection->newTable($installer->getTable('catalogsearch_fulltext_index_default'))
34+
->addColumn(
35+
'FTS_DOC_ID',
36+
Table::TYPE_BIGINT,
37+
null,
38+
['unsigned' => true, 'nullable' => false, 'auto_increment' => true, 'primary' => true],
39+
'Entity ID'
40+
)->addColumn(
41+
'product_id',
42+
Table::TYPE_INTEGER,
43+
10,
44+
['unsigned' => true, 'nullable' => false],
45+
'Product ID'
46+
)->addColumn(
47+
'attribute_id',
48+
Table::TYPE_INTEGER,
49+
10,
50+
['unsigned' => true, 'nullable' => false]
51+
)->addColumn(
52+
'store_id',
53+
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
54+
null,
55+
['unsigned' => true, 'nullable' => false],
56+
'Store ID'
57+
)->addColumn(
58+
'data_index',
59+
Table::TYPE_TEXT,
60+
'4g',
61+
['nullable' => true],
62+
'Data index'
63+
)->addIndex(
64+
'FTI_CATALOGSEARCH_FULLTEXT_DATA_INDEX',
65+
['data_index'],
66+
['type' => AdapterInterface::INDEX_TYPE_FULLTEXT]
67+
);
68+
$connection->createTable($table);
69+
}
70+
}
71+
}

app/code/Magento/CatalogSearch/Test/Unit/Helper/DataTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ public function prepareIndexdataDataProvider()
109109
{
110110
return [
111111
[
112-
null,
112+
[],
113113
[
114114
'index' => [],
115115
'separator' => '--'
116116
],
117117
],
118118
[
119-
'element1--element2--element3--element4',
119+
['element1','element2','element3--element4'],
120120
[
121121
'index' => [
122122
'element1',

0 commit comments

Comments
 (0)