Skip to content

Commit c813a54

Browse files
aa-kashkadifucan
authored andcommitted
MCP-1012: Creation of Tmp Tables during Search
1 parent 7a08e18 commit c813a54

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
namespace Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection;
88

9-
use Magento\Framework\Data\Collection;
10-
use Magento\Framework\Search\Adapter\Mysql\TemporaryStorage;
11-
use Magento\Framework\Search\Adapter\Mysql\TemporaryStorageFactory;
129
use Magento\Framework\Api\Search\SearchResultInterface;
10+
use Magento\Framework\Data\Collection;
1311

1412
/**
1513
* Resolve specific attributes for search criteria.
@@ -29,11 +27,6 @@ class SearchResultApplier implements SearchResultApplierInterface
2927
*/
3028
private $searchResult;
3129

32-
/**
33-
* @var TemporaryStorageFactory
34-
*/
35-
private $temporaryStorageFactory;
36-
3730
/**
3831
* @var array
3932
*/
@@ -42,18 +35,15 @@ class SearchResultApplier implements SearchResultApplierInterface
4235
/**
4336
* @param Collection $collection
4437
* @param SearchResultInterface $searchResult
45-
* @param TemporaryStorageFactory $temporaryStorageFactory
4638
* @param array $orders
4739
*/
4840
public function __construct(
4941
Collection $collection,
5042
SearchResultInterface $searchResult,
51-
TemporaryStorageFactory $temporaryStorageFactory,
5243
array $orders
5344
) {
5445
$this->collection = $collection;
5546
$this->searchResult = $searchResult;
56-
$this->temporaryStorageFactory = $temporaryStorageFactory;
5747
$this->orders = $orders;
5848
}
5949

@@ -62,21 +52,22 @@ public function __construct(
6252
*/
6353
public function apply()
6454
{
65-
$temporaryStorage = $this->temporaryStorageFactory->create();
66-
$table = $temporaryStorage->storeApiDocuments($this->searchResult->getItems());
55+
if (empty($this->searchResult->getItems())) {
56+
$this->collection->getSelect()->where('NULL');
57+
return;
58+
}
59+
$ids = [];
60+
foreach ($this->searchResult->getItems() as $item) {
61+
$ids[] = (int)$item->getId();
62+
}
6763

68-
$this->collection->getSelect()->joinInner(
69-
[
70-
'search_result' => $table->getName(),
71-
],
72-
'e.entity_id = search_result.' . TemporaryStorage::FIELD_ENTITY_ID,
73-
[]
74-
);
64+
$orderList = implode(',', $ids);
65+
$this->collection->getSelect()->where('e.entity_id IN (?)', $ids);
7566

7667
if (isset($this->orders['relevance'])) {
77-
$this->collection->getSelect()->order(
78-
'search_result.' . TemporaryStorage::FIELD_SCORE . ' ' . $this->orders['relevance']
79-
);
68+
$this->collection->getSelect()
69+
->reset(\Magento\Framework\DB\Select::ORDER)
70+
->order(new \Magento\Framework\DB\Sql\Expression("FIELD(e.entity_id, $orderList)"));
8071
}
8172
}
8273
}

0 commit comments

Comments
 (0)