6
6
7
7
namespace Magento \CatalogSearch \Model \ResourceModel \Fulltext \Collection ;
8
8
9
- use Magento \Framework \Data \Collection ;
10
- use Magento \Framework \Search \Adapter \Mysql \TemporaryStorage ;
11
- use Magento \Framework \Search \Adapter \Mysql \TemporaryStorageFactory ;
12
9
use Magento \Framework \Api \Search \SearchResultInterface ;
10
+ use Magento \Framework \Data \Collection ;
13
11
14
12
/**
15
13
* Resolve specific attributes for search criteria.
@@ -29,11 +27,6 @@ class SearchResultApplier implements SearchResultApplierInterface
29
27
*/
30
28
private $ searchResult ;
31
29
32
- /**
33
- * @var TemporaryStorageFactory
34
- */
35
- private $ temporaryStorageFactory ;
36
-
37
30
/**
38
31
* @var array
39
32
*/
@@ -42,18 +35,15 @@ class SearchResultApplier implements SearchResultApplierInterface
42
35
/**
43
36
* @param Collection $collection
44
37
* @param SearchResultInterface $searchResult
45
- * @param TemporaryStorageFactory $temporaryStorageFactory
46
38
* @param array $orders
47
39
*/
48
40
public function __construct (
49
41
Collection $ collection ,
50
42
SearchResultInterface $ searchResult ,
51
- TemporaryStorageFactory $ temporaryStorageFactory ,
52
43
array $ orders
53
44
) {
54
45
$ this ->collection = $ collection ;
55
46
$ this ->searchResult = $ searchResult ;
56
- $ this ->temporaryStorageFactory = $ temporaryStorageFactory ;
57
47
$ this ->orders = $ orders ;
58
48
}
59
49
@@ -62,21 +52,22 @@ public function __construct(
62
52
*/
63
53
public function apply ()
64
54
{
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
+ }
67
63
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 );
75
66
76
67
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 ) " ) );
80
71
}
81
72
}
82
73
}
0 commit comments