@@ -27,16 +27,24 @@ class PopularSearchTerms
27
27
*/
28
28
private $ queryCollection ;
29
29
30
+ /**
31
+ * @var \Magento\Search\Model\ResourceModel\Query
32
+ */
33
+ private $ queryResource ;
34
+
30
35
/**
31
36
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
32
37
* @param \Magento\Search\Model\ResourceModel\Query\Collection
38
+ * @param ResourceModel\Query $queryResource
33
39
*/
34
40
public function __construct (
35
41
\Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
36
- \Magento \Search \Model \ResourceModel \Query \Collection $ queryCollection
42
+ \Magento \Search \Model \ResourceModel \Query \Collection $ queryCollection ,
43
+ \Magento \Search \Model \ResourceModel \Query $ queryResource
37
44
) {
38
45
$ this ->scopeConfig = $ scopeConfig ;
39
46
$ this ->queryCollection = $ queryCollection ;
47
+ $ this ->queryResource = $ queryResource ;
40
48
}
41
49
42
50
/**
@@ -48,13 +56,17 @@ public function __construct(
48
56
*/
49
57
public function isCacheable (string $ term , int $ storeId )
50
58
{
51
- $ terms = $ this ->queryCollection
52
- ->setPopularQueryFilter ($ storeId )
53
- ->setPageSize ($ this ->getMaxCountCacheableSearchTerms ($ storeId ))
54
- ->load ()
55
- ->getColumnValues ('query_text ' );
59
+ $ connection = $ this ->queryResource ->getConnection ();
60
+ $ select = $ connection ->select ();
61
+ $ select ->from ($ this ->queryResource ->getMainTable (), [$ this ->queryResource ->getIdFieldName ()])
62
+ ->where ('query_text = ? ' , $ term )
63
+ ->where ('store_id = ? ' , $ storeId )
64
+ ->where ('num_results > 0 ' )
65
+ ->order (['popularity DESC ' ])
66
+ ->limit ($ this ->getMaxCountCacheableSearchTerms ($ storeId ));
67
+ $ queryId = $ connection ->fetchOne ($ select );
56
68
57
- return in_array ( $ term , $ terms ) ;
69
+ return ( bool ) $ queryId ;
58
70
}
59
71
60
72
/**
0 commit comments