Skip to content

Commit cadb4a9

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-38817' into bugs
Conflicts: app/code/Magento/CatalogSearch/Setup/InstallData.php
2 parents 6a9ff88 + 89fb35b commit cadb4a9

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,10 @@ public function __construct(
6464

6565
/**
6666
* {@inheritdoc}
67-
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
6867
*/
6968
public function process(FilterInterface $filter, $isNegation, $query, QueryContainer $queryContainer)
7069
{
71-
return $resultQuery = $this->processQueryWithField($filter, $isNegation, $query, $queryContainer);
70+
return $this->processQueryWithField($filter, $isNegation, $query, $queryContainer);
7271
}
7372

7473
/**

app/code/Magento/CatalogSearch/Model/Source/Weight.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Weight
1515
*
1616
* @var int[]
1717
*/
18-
protected $_weights = [1, 2, 3, 4, 5];
18+
protected $_weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
1919

2020
/**
2121
* Retrieve search weights as options array

app/code/Magento/CatalogSearch/Setup/InstallData.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\Setup\ModuleContextInterface;
1212
use Magento\Framework\Setup\ModuleDataSetupInterface;
1313
use Magento\Indexer\Model\IndexerInterfaceFactory;
14+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
1415

1516
class InstallData implements InstallDataInterface
1617
{
@@ -22,9 +23,11 @@ class InstallData implements InstallDataInterface
2223
/**
2324
* @param IndexerInterfaceFactory $indexerFactory
2425
*/
25-
public function __construct(IndexerInterfaceFactory $indexerFactory)
26+
public function __construct(IndexerInterfaceFactory $indexerFactory,
27+
ProductAttributeRepositoryInterface $attributeRepository)
2628
{
2729
$this->indexerFactory = $indexerFactory;
30+
$this->attributeRepository = $attributeRepository;
2831
}
2932

3033
/**
@@ -46,6 +49,20 @@ private function getIndexer($indexerId)
4649
*/
4750
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
4851
{
52+
$this->setWeight('sku', 6);
53+
$this->setWeight('name', 5);
4954
$this->getIndexer('catalogsearch_fulltext')->reindexAll();
5055
}
56+
57+
/**
58+
* @param string $attributeCode
59+
* @param int $weight
60+
* @internal param AdapterInterface $connection
61+
*/
62+
private function setWeight($attributeCode, $weight)
63+
{
64+
$attribute = $this->attributeRepository->get($attributeCode);
65+
$attribute->setSearchWeight($weight);
66+
$this->attributeRepository->save($attribute);
67+
}
5168
}

app/code/Magento/CatalogSearch/Setup/InstallSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
9090
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_FLOAT,
9191
'unsigned' => true,
9292
'nullable' => false,
93-
'default' => '3',
93+
'default' => '1',
9494
'comment' => 'Search Weight'
9595
]
9696
);

lib/internal/Magento/Framework/Search/Adapter/Mysql/ScoreBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function endQuery($boost)
7979
public function addCondition($score)
8080
{
8181
$this->addPlus();
82-
$this->scoreCondition .= "{$score} * " . self::WEIGHT_FIELD;
82+
$this->scoreCondition .= "{$score} * POW(2, " . self::WEIGHT_FIELD . ')';
8383
}
8484

8585
/**

lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/ScoreBuilderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ public function testBuild()
4545

4646
$result = $builder->build();
4747

48+
$weightExpression = 'POW(2, ' . ScoreBuilder::WEIGHT_FIELD . ')';
4849
$expected = '((someCondition1 * %1$s + (someCondition2 * %1$s + someCondition3 * %1$s + ' .
4950
'(someCondition4 * %1$s + someCondition5 * %1$s) * 10.1 + (someCondition6 * %1$s + ' .
5051
'someCondition7 * %1$s) * 10.2) * 10.3) * 10.4 + (0)) AS ' . $builder->getScoreAlias();
51-
$expected = sprintf($expected, ScoreBuilder::WEIGHT_FIELD);
52+
$expected = sprintf($expected, $weightExpression);
5253
$this->assertEquals($expected, $result);
5354
}
5455
}

0 commit comments

Comments
 (0)