Skip to content

Commit e59b738

Browse files
committed
MAGETWO-36045: Default weight SPIKE
MAGETWO-38817: Document default field weights - Change default weights by spike results
1 parent f7ad6f5 commit e59b738

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

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
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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\Setup\ModuleContextInterface;
12+
use Magento\Framework\Setup\ModuleDataSetupInterface;
13+
14+
class InstallData implements \Magento\Framework\Setup\InstallDataInterface
15+
{
16+
/**
17+
* @param ModuleDataSetupInterface $setup
18+
* @param ModuleContextInterface $context
19+
*/
20+
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
21+
{
22+
$connection = $setup->getConnection();
23+
$this->setWeight('sku', 6, $connection);
24+
$this->setWeight('name', 5, $connection);
25+
}
26+
27+
28+
/**
29+
* @param string $attributeCode
30+
* @param int $weight
31+
* @param AdapterInterface $connection
32+
* @internal param $oldWeight
33+
*/
34+
private function setWeight($attributeCode, $weight, AdapterInterface $connection)
35+
{
36+
$updateQuery = 'UPDATE catalog_eav_attribute SET search_weight = ?'
37+
. ' WHERE attribute_id ='
38+
. ' (SELECT eav_attribute.attribute_id FROM eav_attribute'
39+
. ' LEFT JOIN eav_entity_type ON eav_attribute.entity_type_id = eav_entity_type.entity_type_id'
40+
. ' WHERE eav_entity_type.entity_type_code = ?'
41+
. ' AND eav_attribute.attribute_code = ?)';
42+
$bindings = [$weight, 'catalog_product', $attributeCode];
43+
44+
$connection->query($updateQuery, $bindings);
45+
}
46+
}

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
/**

0 commit comments

Comments
 (0)