13
13
use Magento \CatalogGraphQl \Model \Resolver \Products \SearchResultFactory ;
14
14
use Magento \Framework \Api \Search \SearchCriteriaInterface ;
15
15
use Magento \Framework \App \ObjectManager ;
16
+ use Magento \Framework \Exception \LocalizedException ;
16
17
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
17
18
use Magento \Framework \GraphQl \Query \Resolver \ArgumentsProcessorInterface ;
18
19
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
19
20
use Magento \GraphQl \Model \Query \ContextInterface ;
20
21
use Magento \Search \Api \SearchInterface ;
21
22
use Magento \Search \Model \Search \PageSizeProvider ;
22
- use Magento \Search \Model \QueryFactory ;
23
+ use Magento \CatalogGraphQl \Model \Resolver \ Products \ Query \ Search \ QueryPopularity ;
23
24
24
25
/**
25
26
* Full text search for catalog using given search criteria.
@@ -62,9 +63,9 @@ class Search implements ProductQueryInterface
62
63
private $ searchCriteriaBuilder ;
63
64
64
65
/**
65
- * @var QueryFactory
66
+ * @var QueryPopularity
66
67
*/
67
- private $ queryFactory ;
68
+ private $ queryPopularity ;
68
69
69
70
/**
70
71
* @param SearchInterface $search
@@ -74,7 +75,7 @@ class Search implements ProductQueryInterface
74
75
* @param ProductSearch $productsProvider
75
76
* @param SearchCriteriaBuilder $searchCriteriaBuilder
76
77
* @param ArgumentsProcessorInterface|null $argsSelection
77
- * @param QueryFactory |null $queryFactory
78
+ * @param QueryPopularity |null $queryPopularity
78
79
*/
79
80
public function __construct (
80
81
SearchInterface $ search ,
@@ -84,18 +85,16 @@ public function __construct(
84
85
ProductSearch $ productsProvider ,
85
86
SearchCriteriaBuilder $ searchCriteriaBuilder ,
86
87
ArgumentsProcessorInterface $ argsSelection = null ,
87
- QueryFactory $ queryFactory = null
88
+ QueryPopularity $ queryPopularity = null
88
89
) {
89
90
$ this ->search = $ search ;
90
91
$ this ->searchResultFactory = $ searchResultFactory ;
91
92
$ this ->pageSizeProvider = $ pageSize ;
92
93
$ this ->fieldSelection = $ fieldSelection ;
93
94
$ this ->productsProvider = $ productsProvider ;
94
95
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
95
- $ this ->argsSelection = $ argsSelection ?: ObjectManager::getInstance ()
96
- ->get (ArgumentsProcessorInterface::class);
97
- $ this ->queryFactory = $ queryFactory ?: ObjectManager::getInstance ()
98
- ->get (QueryFactory::class);
96
+ $ this ->argsSelection = $ argsSelection ?: ObjectManager::getInstance ()->get (ArgumentsProcessorInterface::class);
97
+ $ this ->queryPopularity = $ queryPopularity ?: ObjectManager::getInstance ()->get (QueryPopularity::class);
99
98
}
100
99
101
100
/**
@@ -136,12 +135,7 @@ public function getResult(
136
135
137
136
// add query statistics data
138
137
if (!empty ($ args ['search ' ])) {
139
- $ query = $ this ->queryFactory ->get ();
140
- $ query ->setQueryText ($ args ['search ' ]);
141
- $ store = $ context ->getExtensionAttributes ()->getStore ();
142
- $ query ->setStoreId ($ store ->getId ());
143
- $ query ->saveIncrementalPopularity ();
144
- $ query ->saveNumResults ($ searchResults ->getTotalCount ());
138
+ $ this ->queryPopularity ->execute ($ context , $ args ['search ' ], (int ) $ searchResults ->getTotalCount ());
145
139
}
146
140
147
141
$ productArray = [];
0 commit comments