Skip to content

Commit 8042eb1

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

File tree

6 files changed

+34
-15
lines changed

6 files changed

+34
-15
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: 28 additions & 9 deletions
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
{
@@ -21,10 +22,29 @@ class InstallData implements InstallDataInterface
2122

2223
/**
2324
* @param IndexerInterfaceFactory $indexerFactory
25+
* @param ProductAttributeRepositoryInterface $attributeRepository
2426
*/
25-
public function __construct(IndexerInterfaceFactory $indexerFactory)
26-
{
27+
public function __construct(
28+
IndexerInterfaceFactory $indexerFactory,
29+
ProductAttributeRepositoryInterface $attributeRepository
30+
) {
2731
$this->indexerFactory = $indexerFactory;
32+
$this->attributeRepository = $attributeRepository;
33+
}
34+
35+
/**
36+
* Installs data for a module
37+
*
38+
* @param ModuleDataSetupInterface $setup
39+
* @param ModuleContextInterface $context
40+
* @return void
41+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
42+
*/
43+
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
44+
{
45+
$this->setWeight('sku', 6);
46+
$this->setWeight('name', 5);
47+
$this->getIndexer('catalogsearch_fulltext')->reindexAll();
2848
}
2949

3050
/**
@@ -37,15 +57,14 @@ private function getIndexer($indexerId)
3757
}
3858

3959
/**
40-
* Installs data for a module
41-
*
42-
* @param ModuleDataSetupInterface $setup
43-
* @param ModuleContextInterface $context
60+
* @param string $attributeCode
61+
* @param int $weight
4462
* @return void
45-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4663
*/
47-
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
64+
private function setWeight($attributeCode, $weight)
4865
{
49-
$this->getIndexer('catalogsearch_fulltext')->reindexAll();
66+
$attribute = $this->attributeRepository->get($attributeCode);
67+
$attribute->setSearchWeight($weight);
68+
$this->attributeRepository->save($attribute);
5069
}
5170
}

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)