diff --git a/app/code/Magento/CatalogInventory/Model/Resource/Stock/Item.php b/app/code/Magento/CatalogInventory/Model/Resource/Stock/Item.php index ee653da735804..b182d738370fc 100644 --- a/app/code/Magento/CatalogInventory/Model/Resource/Stock/Item.php +++ b/app/code/Magento/CatalogInventory/Model/Resource/Stock/Item.php @@ -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; diff --git a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php index 355db184ea7f0..f01880e61acaa 100644 --- a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php +++ b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php @@ -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); } /** diff --git a/app/code/Magento/CatalogSearch/Model/Search/IndexBuilder.php b/app/code/Magento/CatalogSearch/Model/Search/IndexBuilder.php index 4d1c3e49200fc..4e6648b6f5c08 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/IndexBuilder.php +++ b/app/code/Magento/CatalogSearch/Model/Search/IndexBuilder.php @@ -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; @@ -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( @@ -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; @@ -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; + } } diff --git a/app/code/Magento/CatalogSearch/Model/Source/Weight.php b/app/code/Magento/CatalogSearch/Model/Source/Weight.php index 0525c11be74cc..fdb6be230a4e0 100644 --- a/app/code/Magento/CatalogSearch/Model/Source/Weight.php +++ b/app/code/Magento/CatalogSearch/Model/Source/Weight.php @@ -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 diff --git a/app/code/Magento/CatalogSearch/Setup/InstallData.php b/app/code/Magento/CatalogSearch/Setup/InstallData.php index 23cfc00610045..8c758d2535440 100644 --- a/app/code/Magento/CatalogSearch/Setup/InstallData.php +++ b/app/code/Magento/CatalogSearch/Setup/InstallData.php @@ -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 { @@ -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(); } /** @@ -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); } } diff --git a/app/code/Magento/CatalogSearch/Setup/InstallSchema.php b/app/code/Magento/CatalogSearch/Setup/InstallSchema.php index 7c676b36f39ca..e5e2bf8f91ca5 100644 --- a/app/code/Magento/CatalogSearch/Setup/InstallSchema.php +++ b/app/code/Magento/CatalogSearch/Setup/InstallSchema.php @@ -29,7 +29,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' ] ); diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/IndexBuilderTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/IndexBuilderTest.php index 17e17f76c0cf3..33ca04f2b95d2 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/IndexBuilderTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/IndexBuilderTest.php @@ -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() @@ -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') @@ -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'], @@ -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()); @@ -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') @@ -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], @@ -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(); + } } /** diff --git a/app/code/Magento/Indexer/etc/crontab.xml b/app/code/Magento/Indexer/etc/crontab.xml index 2dd222c0e0166..33e6a27040f93 100644 --- a/app/code/Magento/Indexer/etc/crontab.xml +++ b/app/code/Magento/Indexer/etc/crontab.xml @@ -6,7 +6,7 @@ */ --> - + * * * * * diff --git a/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Stock/ItemTest.php b/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Stock/ItemTest.php index ca4260d5c0376..6acd799855c98 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Stock/ItemTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Stock/ItemTest.php @@ -5,8 +5,6 @@ */ namespace Magento\CatalogInventory\Model\Stock; -use Magento\Indexer\Model\Indexer\State; - class ItemTest extends \PHPUnit_Framework_TestCase { /** @@ -23,7 +21,6 @@ protected function setUp() /** * @magentoDataFixture Magento/Catalog/_files/products.php - * @magentoAppIsolation enabled */ public function testSaveWithNullQty() { @@ -34,11 +31,11 @@ public function testSaveWithNullQty() $product->load(1); /** @var \Magento\CatalogInventory\Model\Stock\StockItemRepository $stockItemRepository */ - $stockItemRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + $stockItemRepository = $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->create('Magento\CatalogInventory\Model\Stock\StockItemRepository'); /** @var \Magento\CatalogInventory\Api\StockItemCriteriaInterface $stockItemCriteria */ - $stockItemCriteria = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + $stockItemCriteria = $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->create('Magento\CatalogInventory\Api\StockItemCriteriaInterface'); $savedStockItem = current($stockItemRepository->getList($stockItemCriteria)->getItems()); @@ -63,49 +60,15 @@ public function testSaveWithNullQty() /** * @magentoDataFixture Magento/Catalog/_files/products.php - * @magentoAppIsolation enabled - */ - public function testIndexerInvalidation() - { - /** @var \Magento\CatalogInventory\Model\Stock\StockItemRepository $stockItemRepository */ - $stockItemRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\CatalogInventory\Model\Stock\StockItemRepository'); - - /** @var \Magento\CatalogInventory\Api\StockItemCriteriaInterface $stockItemCriteria */ - $stockItemCriteria = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\CatalogInventory\Api\StockItemCriteriaInterface'); - /** @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor $indexerProcessor */ - $indexerProcessor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\CatalogInventory\Model\Indexer\Stock\Processor'); - $indexer = $indexerProcessor->getIndexer(); - $indexer->setScheduled(true); - $indexer->getState()->setStatus(State::STATUS_VALID)->save(); - - /** @var \Magento\CatalogInventory\Api\Data\StockItemInterface $savedStockItem */ - $savedStockItem = current($stockItemRepository->getList($stockItemCriteria)->getItems()); - $savedStockItem->setQty(1); - $savedStockItem->setIsInStock(false); - $savedStockItem->save(); - - - $this->assertEquals('invalid', $indexerProcessor->getIndexer()->getStatus()); - - $indexer->setScheduled(false); - $indexer->getState()->setStatus(State::STATUS_VALID)->save(); - } - - /** - * @magentoDataFixture Magento/Catalog/_files/products.php - * @magentoAppIsolation enabled */ public function testStockStatusChangedAuto() { /** @var \Magento\CatalogInventory\Model\Stock\StockItemRepository $stockItemRepository */ - $stockItemRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + $stockItemRepository = $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->create('Magento\CatalogInventory\Model\Stock\StockItemRepository'); /** @var \Magento\CatalogInventory\Api\StockItemCriteriaInterface $stockItemCriteria */ - $stockItemCriteria = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + $stockItemCriteria = $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->create('Magento\CatalogInventory\Api\StockItemCriteriaInterface'); $savedStockItem = current($stockItemRepository->getList($stockItemCriteria)->getItems()); diff --git a/dev/tests/integration/testsuite/Magento/Framework/Search/Adapter/Mysql/Builder/Query/MatchTest.php b/dev/tests/integration/testsuite/Magento/Framework/Search/Adapter/Mysql/Builder/Query/MatchTest.php index f3c867a6986a4..bc60599080b91 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Search/Adapter/Mysql/Builder/Query/MatchTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Search/Adapter/Mysql/Builder/Query/MatchTest.php @@ -29,7 +29,7 @@ protected function setUp() */ public function testBuildQuery($conditionType, $expectedSuffix) { - $conditionPattern = "(MATCH (data_index) AGAINST ('%ssomeValue*' IN BOOLEAN MODE) * %s) AS score"; + $conditionPattern = "(MATCH (data_index) AGAINST ('%ssomeValue*' IN BOOLEAN MODE) * POW(2, %s)) AS score"; $expectedScoreCondition = sprintf($conditionPattern, $expectedSuffix, ScoreBuilder::WEIGHT_FIELD); $expectedSql = "SELECT `someTable`.* FROM `someTable` WHERE (MATCH (data_index) " . "AGAINST ('{$expectedSuffix}someValue*' IN BOOLEAN MODE))"; diff --git a/lib/internal/Magento/Framework/Search/Adapter/Mysql/Mapper.php b/lib/internal/Magento/Framework/Search/Adapter/Mysql/Mapper.php index 14432d3a6afad..fe2da6d2a4d2a 100644 --- a/lib/internal/Magento/Framework/Search/Adapter/Mysql/Mapper.php +++ b/lib/internal/Magento/Framework/Search/Adapter/Mysql/Mapper.php @@ -8,6 +8,8 @@ use Magento\Framework\App\Resource; use Magento\Framework\DB\Select; use Magento\Framework\Search\Adapter\Mysql\Filter\Builder; +use Magento\Framework\Search\Adapter\Mysql\Query\Builder\Match; +use Magento\Framework\Search\Adapter\Mysql\Query\MatchContainer; use Magento\Framework\Search\Adapter\Mysql\Query\QueryContainer; use Magento\Framework\Search\Adapter\Mysql\Query\QueryContainerFactory; use Magento\Framework\Search\EntityMetadata; @@ -57,6 +59,10 @@ class Mapper * @var QueryContainerFactory */ private $queryContainerFactory; + /** + * @var Query\Builder\Match + */ + private $matchBuilder; /** * @param ScoreBuilderFactory $scoreBuilderFactory @@ -65,6 +71,7 @@ class Mapper * @param Resource|Resource $resource * @param EntityMetadata $entityMetadata * @param QueryContainerFactory $queryContainerFactory + * @param Query\Builder\Match $matchBuilder * @param IndexBuilderInterface[] $indexProviders */ public function __construct( @@ -74,6 +81,7 @@ public function __construct( Resource $resource, EntityMetadata $entityMetadata, QueryContainerFactory $queryContainerFactory, + Match $matchBuilder, array $indexProviders ) { $this->scoreBuilderFactory = $scoreBuilderFactory; @@ -83,6 +91,7 @@ public function __construct( $this->entityMetadata = $entityMetadata; $this->indexProviders = $indexProviders; $this->queryContainerFactory = $queryContainerFactory; + $this->matchBuilder = $matchBuilder; } /** @@ -116,7 +125,6 @@ public function buildQuery(RequestInterface $request) BoolQuery::QUERY_CONDITION_MUST, $queryContainer ); - $select->columns($scoreBuilder->build()); $filtersCount = $queryContainer->getFiltersCount(); if ($filtersCount > 1) { @@ -124,34 +132,13 @@ public function buildQuery(RequestInterface $request) $select->having('COUNT(DISTINCT search_index.attribute_id) = ' . $filtersCount); } - $select = $this->createAroundSelect($select, $scoreBuilder); - - $matchQueries = $queryContainer->getDerivedQueries(); - - if ($matchQueries) { - $subSelect = $select; - $select = $this->resource->getConnection(Resource::DEFAULT_READ_RESOURCE)->select(); - $tables = array_merge($queryContainer->getDerivedQueryNames(), ['main_select.relevance']); - $relevance = implode('.relevance + ', $tables); - $select - ->from( - ['main_select' => $subSelect], - [ - $this->entityMetadata->getEntityId() => 'entity_id', - 'relevance' => sprintf('(%s)', $relevance), - ] - ); - - foreach ($matchQueries as $matchName => $matchSelect) { - $select->join( - [$matchName => $this->createAroundSelect($matchSelect, $scoreBuilder)], - $matchName . '.entity_id = main_select.entity_id', - [] - ); - } - } - - $select->limit($request->getSize()); + $select = $this->addMatchQueries( + $request, + $queryContainer->getDerivedQueries(), + $scoreBuilder, + $select, + $indexBuilder + ); $select->limit($request->getSize()); $select->order('relevance ' . Select::SQL_DESC); @@ -334,4 +321,69 @@ private function processFilterQuery( $scoreBuilder->endQuery($query->getBoost()); return $select; } + + /** + * @param RequestInterface $request + * @param MatchContainer[] $matchQueries + * @param ScoreBuilder $scoreBuilder + * @param Select $select + * @param IndexBuilderInterface $indexBuilder + * @return Select + * @internal param QueryContainer $queryContainer + */ + private function addMatchQueries( + RequestInterface $request, + array $matchQueries, + ScoreBuilder $scoreBuilder, + Select $select, + IndexBuilderInterface $indexBuilder + ) { + if (!$matchQueries) { + $select->columns($scoreBuilder->build()); + $select = $this->createAroundSelect($select, $scoreBuilder); + } elseif (count($matchQueries) === 1) { + $matchContainer = reset($matchQueries); + $this->matchBuilder->build( + $scoreBuilder, + $select, + $matchContainer->getRequest(), + $matchContainer->getConditionType() + ); + $select->columns($scoreBuilder->build()); + $select = $this->createAroundSelect($select, $scoreBuilder); + } elseif (count($matchQueries) > 1) { + $select->columns($scoreBuilder->build()); + $select = $this->createAroundSelect($select, $scoreBuilder); + $subSelect = $select; + $select = $this->resource->getConnection(Resource::DEFAULT_READ_RESOURCE)->select(); + $tables = array_merge(array_keys($matchQueries), ['main_select.relevance']); + $relevance = implode('.relevance + ', $tables); + $select + ->from( + ['main_select' => $subSelect], + [ + $this->entityMetadata->getEntityId() => 'entity_id', + 'relevance' => sprintf('(%s)', $relevance), + ] + ); + + foreach ($matchQueries as $matchName => $matchContainer) { + $matchSelect = $indexBuilder->build($request); + $matchScoreBuilder = $this->scoreBuilderFactory->create(); + $matchSelect = $this->matchBuilder->build( + $matchScoreBuilder, + $matchSelect, + $matchContainer->getRequest(), + $matchContainer->getConditionType() + ); + $matchSelect->columns($matchScoreBuilder->build()); + $select->join( + [$matchName => $this->createAroundSelect($matchSelect, $scoreBuilder)], + $matchName . '.entity_id = main_select.entity_id', + [] + ); + } + } + return $select; + } } diff --git a/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/MatchContainer.php b/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/MatchContainer.php new file mode 100644 index 0000000000000..083c23dd59f27 --- /dev/null +++ b/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/MatchContainer.php @@ -0,0 +1,51 @@ +request = $request; + $this->conditionType = $conditionType; + } + + /** + * @return QueryInterface + */ + public function getRequest() + { + return $this->request; + } + + /** + * @return string + */ + public function getConditionType() + { + return $this->conditionType; + } +} diff --git a/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/MatchContainerFactory.php b/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/MatchContainerFactory.php new file mode 100644 index 0000000000000..dacbb6a3db19d --- /dev/null +++ b/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/MatchContainerFactory.php @@ -0,0 +1,51 @@ +objectManager = $objectManager; + $this->instanceName = $instanceName; + } + + /** + * Create class instance with specified parameters + * + * @param array $data + * @return \Magento\Framework\Search\Adapter\Mysql\Query\QueryContainer + */ + public function create(array $data = []) + { + return $this->objectManager->create($this->instanceName, $data); + } +} diff --git a/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/QueryContainer.php b/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/QueryContainer.php index 0dad0badf6cb5..57407b14a8170 100644 --- a/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/QueryContainer.php +++ b/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/QueryContainer.php @@ -7,36 +7,15 @@ namespace Magento\Framework\Search\Adapter\Mysql\Query; use Magento\Framework\DB\Select; -use Magento\Framework\Search\Adapter\Mysql\IndexBuilderInterface; -use Magento\Framework\Search\Adapter\Mysql\Query\Builder\Match; -use Magento\Framework\Search\Adapter\Mysql\ScoreBuilder; -use Magento\Framework\Search\Adapter\Mysql\ScoreBuilderFactory; use Magento\Framework\Search\Request\QueryInterface as RequestQueryInterface; -use Magento\Framework\Search\RequestInterface; class QueryContainer { const DERIVED_QUERY_PREFIX = 'derived_'; /** - * @var array [[$select, $scoreBuilder], [$select, $scoreBuilder]] + * @var array */ private $queries = []; - /** - * @var ScoreBuilderFactory - */ - private $scoreBuilderFactory; - /** - * @var Match - */ - private $matchBuilder; - /** - * @var IndexBuilderInterface - */ - private $indexBuilder; - /** - * @var RequestInterface - */ - private $request; /** * @var string[] @@ -47,23 +26,17 @@ class QueryContainer * @var int */ private $filtersCount = 0; + /** + * @var \Magento\Framework\Search\Adapter\Mysql\Query\MatchContainerFactory + */ + private $matchContainerFactory; /** - * @param ScoreBuilderFactory $scoreBuilderFactory - * @param Match $matchBuilder - * @param IndexBuilderInterface $indexBuilder - * @param RequestInterface $request + * @param MatchContainerFactory $matchContainerFactory */ - public function __construct( - ScoreBuilderFactory $scoreBuilderFactory, - Match $matchBuilder, - IndexBuilderInterface $indexBuilder, - RequestInterface $request - ) { - $this->scoreBuilderFactory = $scoreBuilderFactory; - $this->matchBuilder = $matchBuilder; - $this->indexBuilder = $indexBuilder; - $this->request = $request; + public function __construct(MatchContainerFactory $matchContainerFactory) + { + $this->matchContainerFactory = $matchContainerFactory; } /** @@ -77,12 +50,14 @@ public function addMatchQuery( RequestQueryInterface $query, $conditionType ) { - $subSelect = $this->createSelect(); - $subScoreBuilder = $this->scoreBuilderFactory->create(); - $this->buildMatchQuery($subScoreBuilder, $subSelect, $query, $conditionType); - $subSelect->columns($subScoreBuilder->build()); - $this->addDerivedQuery($subSelect); - + $container = $this->matchContainerFactory->create( + [ + 'request' => $query, + 'conditionType' => $conditionType, + ] + ); + $name = self::DERIVED_QUERY_PREFIX . count($this->queries); + $this->queries[$name] = $container; return $select; } @@ -121,53 +96,10 @@ public function getFiltersCount() } /** - * @return Select[] + * @return MatchContainer[] */ public function getDerivedQueries() { return $this->queries; } - - /** - * @return array - */ - public function getDerivedQueryNames() - { - return array_keys($this->getDerivedQueries()); - } - - /** - * @param Select $select - * @return void - */ - private function addDerivedQuery(Select $select) - { - $name = self::DERIVED_QUERY_PREFIX . count($this->queries); - $this->queries[$name] = $select; - } - - /** - * @return Select - */ - private function createSelect() - { - return $this->indexBuilder->build($this->request); - } - - /** - * @param ScoreBuilder $scoreBuilder - * @param Select $select - * @param RequestQueryInterface $query - * @param string $conditionType - * @return Select - */ - private function buildMatchQuery( - ScoreBuilder $scoreBuilder, - Select $select, - RequestQueryInterface $query, - $conditionType - ) { - $select = $this->matchBuilder->build($scoreBuilder, $select, $query, $conditionType); - return $select; - } } diff --git a/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/QueryContainerFactory.php b/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/QueryContainerFactory.php index 15591bab26cbf..24783f9646a56 100644 --- a/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/QueryContainerFactory.php +++ b/lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/QueryContainerFactory.php @@ -15,14 +15,14 @@ class QueryContainerFactory * * @var \Magento\Framework\ObjectManagerInterface */ - protected $_objectManager = null; + protected $objectManager = null; /** * Instance name to create * * @var string */ - protected $_instanceName = null; + protected $instanceName = null; /** * Factory constructor @@ -34,8 +34,8 @@ public function __construct( \Magento\Framework\ObjectManagerInterface $objectManager, $instanceName = 'Magento\Framework\Search\Adapter\Mysql\Query\QueryContainer' ) { - $this->_objectManager = $objectManager; - $this->_instanceName = $instanceName; + $this->objectManager = $objectManager; + $this->instanceName = $instanceName; } /** @@ -46,6 +46,6 @@ public function __construct( */ public function create(array $data = []) { - return $this->_objectManager->create($this->_instanceName, $data); + return $this->objectManager->create($this->instanceName, $data); } } diff --git a/lib/internal/Magento/Framework/Search/Adapter/Mysql/ScoreBuilder.php b/lib/internal/Magento/Framework/Search/Adapter/Mysql/ScoreBuilder.php index 19c8f261d9947..1b9774996b5e1 100644 --- a/lib/internal/Magento/Framework/Search/Adapter/Mysql/ScoreBuilder.php +++ b/lib/internal/Magento/Framework/Search/Adapter/Mysql/ScoreBuilder.php @@ -79,7 +79,7 @@ public function endQuery($boost) public function addCondition($score) { $this->addPlus(); - $this->scoreCondition .= "{$score} * " . self::WEIGHT_FIELD; + $this->scoreCondition .= "{$score} * POW(2, " . self::WEIGHT_FIELD . ')'; } /** diff --git a/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/MapperTest.php b/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/MapperTest.php index 36f6a73955d68..167a16c22ea2d 100644 --- a/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/MapperTest.php +++ b/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/MapperTest.php @@ -20,6 +20,7 @@ class MapperTest extends \PHPUnit_Framework_TestCase { const INDEX_NAME = 'test_index_fulltext'; + private $matchBuilder; /** * @var \Magento\Framework\Search\RequestInterface|MockObject @@ -56,11 +57,6 @@ class MapperTest extends \PHPUnit_Framework_TestCase */ private $filterBuilder; - /** - * @var \Magento\Framework\Search\Request\FilterInterface|MockObject - */ - private $filter; - /** * @var Mapper */ @@ -71,7 +67,7 @@ protected function setUp() $helper = new ObjectManager($this); $this->select = $this->getMockBuilder('Magento\Framework\DB\Select') - ->setMethods(['group', 'limit', 'where', 'columns', 'from']) + ->setMethods(['group', 'limit', 'where', 'columns', 'from', 'join']) ->disableOriginalConstructor() ->getMock(); $this->select->expects($this->any()) @@ -108,7 +104,7 @@ protected function setUp() ->getMockForAbstractClass(); $this->queryContainer = $this->getMockBuilder('Magento\Framework\Search\Adapter\Mysql\Query\QueryContainer') - ->setMethods(['addMatchQuery']) + ->setMethods(['addMatchQuery', 'getDerivedQueries']) ->disableOriginalConstructor() ->getMock(); $this->queryContainer->expects($this->any()) @@ -124,14 +120,18 @@ protected function setUp() ->method('create') ->willReturn($this->queryContainer); - $this->filter = $this->getMockBuilder('Magento\Framework\Search\Request\FilterInterface') + $this->filterBuilder = $this->getMockBuilder('Magento\Framework\Search\Adapter\Mysql\Filter\Builder') + ->setMethods(['build']) ->disableOriginalConstructor() - ->getMockForAbstractClass(); + ->getMock(); - $this->filterBuilder = $this->getMockBuilder('Magento\Framework\Search\Adapter\Mysql\Filter\Builder') + $this->matchBuilder = $this->getMockBuilder('\Magento\Framework\Search\Adapter\Mysql\Query\Builder\Match') ->setMethods(['build']) ->disableOriginalConstructor() ->getMock(); + $this->matchBuilder->expects($this->any()) + ->method('build') + ->willReturnArgument(1); /** @var MockObject|\Magento\Framework\Search\Adapter\Mysql\IndexBuilderInterface $indexBuilder */ $indexBuilder = $this->getMockBuilder('\Magento\Framework\Search\Adapter\Mysql\IndexBuilderInterface') @@ -154,7 +154,8 @@ protected function setUp() 'scoreBuilderFactory' => $this->scoreBuilderFactory, 'queryContainerFactory' => $queryContainerFactory, 'filterBuilder' => $this->filterBuilder, - 'indexProviders' => [$index => $indexBuilder] + 'matchBuilder' => $this->matchBuilder, + 'indexProviders' => [$index => $indexBuilder], ] ); } @@ -163,6 +164,10 @@ public function testBuildMatchQuery() { $query = $this->createMatchQuery(); + $this->queryContainer->expects($this->once()) + ->method('getDerivedQueries') + ->willReturn([]); + $this->queryContainer->expects($this->any())->method('addMatchQuery') ->with( $this->equalTo($this->select), @@ -173,7 +178,7 @@ public function testBuildMatchQuery() $this->request->expects($this->once())->method('getQuery')->will($this->returnValue($query)); - $this->select->expects($this->once())->method('columns')->will($this->returnValue($this->select)); + $this->select->expects($this->any())->method('columns')->will($this->returnValue($this->select)); $response = $this->mapper->buildQuery($this->request); @@ -182,11 +187,13 @@ public function testBuildMatchQuery() public function testBuildFilterQuery() { - $query = $this->createFilterQuery(); - $query->expects($this->once())->method('getReferenceType')->will($this->returnValue(Filter::REFERENCE_FILTER)); - $query->expects($this->once())->method('getReference')->will($this->returnValue($this->filter)); + $query = $this->createFilterQuery(Filter::REFERENCE_FILTER, $this->createFilter()); + + $this->queryContainer->expects($this->once()) + ->method('getDerivedQueries') + ->willReturn([]); - $this->select->expects($this->once())->method('columns')->will($this->returnValue($this->select)); + $this->select->expects($this->any())->method('columns')->will($this->returnValue($this->select)); $this->request->expects($this->once())->method('getQuery')->will($this->returnValue($query)); @@ -197,64 +204,84 @@ public function testBuildFilterQuery() $this->assertEquals($this->select, $response); } - public function testBuildBoolQuery() + /** + * @param $query + * @throws \Exception + * @dataProvider buildQueryDataProvider + */ + public function testBuildQuery($query, $derivedQueries = []) { - $query = $this->createBoolQuery(); - $this->request->expects($this->once())->method('getQuery')->will($this->returnValue($query)); + $this->filterBuilder->expects($this->any())->method('build')->will($this->returnValue('(1)')); - $matchQuery = $this->createMatchQuery(); - $filterMatchQuery = $this->createFilterQuery(); - $filterMatchQuery->expects($this->once())->method('getReferenceType') - ->will($this->returnValue(Filter::REFERENCE_QUERY)); - $filterMatchQuery->expects($this->once())->method('getReference')->will($this->returnValue($matchQuery)); + $this->queryContainer->expects($this->any()) + ->method('getDerivedQueries') + ->willReturn($derivedQueries); - $filterQuery = $this->createFilterQuery(); - $filterQuery->expects($this->once())->method('getReferenceType') - ->will($this->returnValue(Filter::REFERENCE_FILTER)); - $filterQuery->expects($this->once())->method('getReference')->will($this->returnValue($this->filter)); + $this->select->expects($this->any())->method('columns')->will($this->returnValue($this->select)); $this->request->expects($this->once())->method('getQuery')->will($this->returnValue($query)); - $this->filterBuilder->expects($this->once())->method('build')->will($this->returnValue('(1)')); + $response = $this->mapper->buildQuery($this->request); - $this->select->expects($this->once())->method('columns')->will($this->returnValue($this->select)); + $this->assertEquals($this->select, $response); + } - $query->expects($this->once()) - ->method('getMust') - ->will( - $this->returnValue( + public function buildQueryDataProvider() + { + return [ + [ + $this->createBoolQuery( [ $this->createMatchQuery(), - $this->createFilterQuery(), - ] - ) - ); - - $query->expects($this->once()) - ->method('getShould') - ->will( - $this->returnValue( + $this->createFilterQuery(Filter::REFERENCE_QUERY, $this->createMatchQuery()), + ], [ $this->createMatchQuery(), - $filterMatchQuery, - ] - ) - ); - - $query->expects($this->once()) - ->method('getMustNot') - ->will( - $this->returnValue( + $this->createFilterQuery(Filter::REFERENCE_FILTER, $this->createFilter()), + ], [ $this->createMatchQuery(), - $filterQuery, + $this->createFilterQuery(Filter::REFERENCE_FILTER, $this->createFilter()), ] - ) - ); - - $response = $this->mapper->buildQuery($this->request); - - $this->assertEquals($this->select, $response); + ), + ], + [ + $this->createBoolQuery( + [ + $this->createMatchQuery(), + $this->createMatchQuery(), + ], + [], + [] + ), + [ + $this->createMatchContainer( + $this->createMatchQuery(), + 'mustNot' + ), + ], + ], + [ + $this->createBoolQuery( + [ + $this->createMatchQuery(), + $this->createMatchQuery(), + ], + [], + [] + ), + [ + $this->createMatchContainer( + $this->createMatchQuery(), + 'mustNot' + ), + $this->createMatchContainer( + $this->createMatchQuery(), + 'must' + ), + ], + ], + ]; } /** @@ -291,9 +318,11 @@ private function createMatchQuery() } /** + * @param string $referenceType + * @param mixed $reference * @return MockObject */ - private function createFilterQuery() + private function createFilterQuery($referenceType, $reference) { $query = $this->getMockBuilder('Magento\Framework\Search\Request\Query\Filter') ->setMethods(['getType', 'getReferenceType', 'getReference']) @@ -302,13 +331,17 @@ private function createFilterQuery() $query->expects($this->exactly(1)) ->method('getType') ->will($this->returnValue(QueryInterface::TYPE_FILTER)); + $query->expects($this->once())->method('getReferenceType') + ->will($this->returnValue($referenceType)); + $query->expects($this->once())->method('getReference') + ->will($this->returnValue($reference)); return $query; } /** * @return MockObject */ - private function createBoolQuery() + private function createBoolQuery(array $must, array $should, array $mustNot) { $query = $this->getMockBuilder('Magento\Framework\Search\Request\Query\Bool') ->setMethods(['getMust', 'getShould', 'getMustNot', 'getType']) @@ -317,6 +350,44 @@ private function createBoolQuery() $query->expects($this->exactly(1)) ->method('getType') ->will($this->returnValue(QueryInterface::TYPE_BOOL)); + $query->expects($this->once()) + ->method('getMust') + ->will($this->returnValue($must)); + $query->expects($this->once()) + ->method('getShould') + ->will($this->returnValue($should)); + $query->expects($this->once()) + ->method('getMustNot') + ->will($this->returnValue($mustNot)); return $query; } + + /** + * @return MockObject + */ + private function createFilter() + { + return $this->getMockBuilder('Magento\Framework\Search\Request\FilterInterface') + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + } + + /** + * @param $request + * @param $conditionType + */ + private function createMatchContainer($request, $conditionType) + { + $matchContainer = $this->getMockBuilder('\Magento\Framework\Search\Adapter\Mysql\Query\MatchContainer') + ->setMethods(['getRequest', 'getConditionType']) + ->disableOriginalConstructor() + ->getMock(); + $matchContainer->expects($this->any()) + ->method('getRequest') + ->willReturn($request); + $matchContainer->expects($this->any()) + ->method('getConditionType') + ->willReturn($conditionType); + return $matchContainer; + } } diff --git a/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/Query/QueryContainerTest.php b/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/Query/QueryContainerTest.php index 97f403a6e1c8c..10d77becf5a25 100644 --- a/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/Query/QueryContainerTest.php +++ b/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/Query/QueryContainerTest.php @@ -5,6 +5,7 @@ */ namespace Magento\Framework\Search\Test\Unit\Adapter\Mysql\Query; +use Magento\Framework\Search\Adapter\Mysql\Query\MatchContainerFactory; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Framework\Search\Adapter\Mysql\Query\QueryContainer; use Magento\Framework\Search\Request\Query\Bool; @@ -14,101 +15,65 @@ class QueryContainerTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject */ private $select; - /** @var \Magento\Framework\Search\Adapter\Mysql\ScoreBuilder|\PHPUnit_Framework_MockObject_MockObject */ - private $scoreBuilder; - - /** @var \Magento\Framework\Search\Adapter\Mysql\ScoreBuilderFactory|\PHPUnit_Framework_MockObject_MockObject */ - private $scoreBuilderFactory; + /** @var MatchContainerFactory|\PHPUnit_Framework_MockObject_MockObject */ + private $matchContainerFactory; /** @var \Magento\Framework\Search\Request\QueryInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $query; - - /** @var \Magento\Framework\Search\Adapter\Mysql\Query\Builder\Match|\PHPUnit_Framework_MockObject_MockObject */ - private $matchBuilder; - - /** @var \Magento\Framework\Search\Adapter\Mysql\IndexBuilderInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $indexBuilder; - - /** @var \Magento\Framework\Search\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ - private $request; + private $requestQuery; /** @var \Magento\Framework\Search\Adapter\Mysql\Query\QueryContainer */ private $queryContainer; protected function setUp() { + if (version_compare('5.5.23', phpversion(), '=')) { + $this->markTestSkipped('This test fails with Segmentation fault on PHP 5.5.23'); + } $helper = new ObjectManager($this); $this->select = $this->getMockBuilder('Magento\Framework\DB\Select') ->disableOriginalConstructor() ->getMock(); - $this->scoreBuilder = $this->getMockBuilder('Magento\Framework\Search\Adapter\Mysql\ScoreBuilder') - ->disableOriginalConstructor() - ->getMock(); - $this->scoreBuilderFactory = $this->getMockBuilder('Magento\Framework\Search\Adapter\Mysql\ScoreBuilderFactory') + $this->matchContainerFactory = $this->getMockBuilder( + 'Magento\Framework\Search\Adapter\Mysql\Query\MatchContainerFactory' + ) ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); - $this->scoreBuilderFactory->expects($this->any())->method('create')->willReturn($this->scoreBuilder); - - $this->query = $this->getMockBuilder('Magento\Framework\Search\Request\QueryInterface') - ->disableOriginalConstructor() - ->getMock(); - - $this->matchBuilder = $this->getMockBuilder('Magento\Framework\Search\Adapter\Mysql\Query\Builder\Match') - ->setMethods(['build']) - ->disableOriginalConstructor() - ->getMock(); - $this->matchBuilder->expects($this->any())->method('build')->willReturnArgument(1); - $this->indexBuilder = $this->getMockBuilder('Magento\Framework\Search\Adapter\Mysql\IndexBuilderInterface') - ->setMethods(['build']) - ->disableOriginalConstructor() - ->getMock(); - - $this->request = $this->getMockBuilder('\Magento\Framework\Search\RequestInterface') + $this->requestQuery = $this->getMockBuilder('Magento\Framework\Search\Request\QueryInterface') ->disableOriginalConstructor() ->getMock(); $this->queryContainer = $helper->getObject( 'Magento\Framework\Search\Adapter\Mysql\Query\QueryContainer', [ - 'scoreBuilderFactory' => $this->scoreBuilderFactory, - 'matchBuilder' => $this->matchBuilder, - 'indexBuilder' => $this->indexBuilder, - 'request' => $this->request + 'matchContainerFactory' => $this->matchContainerFactory, ] ); } public function testBuild() { + $this->matchContainerFactory->expects($this->once())->method('create') + ->willReturn('asdf'); - $this->scoreBuilder->expects($this->once())->method('build')->willReturn('score condition'); - $subSelect = $this->getMockBuilder('Magento\Framework\DB\Select') - ->disableOriginalConstructor() - ->getMock(); - $this->indexBuilder->expects($this->once())->method('build')->willReturn($subSelect); - $subSelect->expects($this->once())->method('columns')->with('score condition'); - - $result = $this->queryContainer->addMatchQuery($this->select, $this->query, Bool::QUERY_CONDITION_MUST); + $result = $this->queryContainer->addMatchQuery($this->select, $this->requestQuery, Bool::QUERY_CONDITION_MUST); $this->assertEquals($this->select, $result); } - public function testGetDerivedQueryNames() - { - $this->testBuild(); - $expected = [QueryContainer::DERIVED_QUERY_PREFIX . '0']; - $this->assertEquals($expected, $this->queryContainer->getDerivedQueryNames()); - } - public function testGetDerivedQueries() { - $this->testBuild(); + $this->matchContainerFactory->expects($this->once())->method('create') + ->willReturn('asdf'); + + $result = $this->queryContainer->addMatchQuery($this->select, $this->requestQuery, Bool::QUERY_CONDITION_MUST); + $this->assertEquals($this->select, $result); + $queries = $this->queryContainer->getDerivedQueries(); $this->assertCount(1, $queries); - $this->assertEquals($this->select, reset($queries)); + $this->assertEquals('asdf', reset($queries)); } public function testFilters() diff --git a/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/ScoreBuilderTest.php b/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/ScoreBuilderTest.php index c9f895042d657..e3ed6e39d9d03 100644 --- a/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/ScoreBuilderTest.php +++ b/lib/internal/Magento/Framework/Search/Test/Unit/Adapter/Mysql/ScoreBuilderTest.php @@ -45,10 +45,11 @@ public function testBuild() $result = $builder->build(); + $weightExpression = 'POW(2, ' . ScoreBuilder::WEIGHT_FIELD . ')'; $expected = '((someCondition1 * %1$s + (someCondition2 * %1$s + someCondition3 * %1$s + ' . '(someCondition4 * %1$s + someCondition5 * %1$s) * 10.1 + (someCondition6 * %1$s + ' . 'someCondition7 * %1$s) * 10.2) * 10.3) * 10.4 + (0)) AS ' . $builder->getScoreAlias(); - $expected = sprintf($expected, ScoreBuilder::WEIGHT_FIELD); + $expected = sprintf($expected, $weightExpression); $this->assertEquals($expected, $result); } }