scopeConfig = $scopeConfig; $this->queryCollection = $queryCollection; } /** * Check if is cacheable search term * * @param string $term * @param int $storeId * @return bool */ public function isCacheable(string $term, int $storeId) { $terms = $this->queryCollection ->setPopularQueryFilter($storeId) ->setPageSize($this->getMaxCountCacheableSearchTerms($storeId)) ->load() ->getColumnValues('query_text'); return in_array($term, $terms); } /** * Retrieve maximum count cacheable search terms * * @param int $storeId * @return int */ private function getMaxCountCacheableSearchTerms(int $storeId) { return $this->scopeConfig->getValue( self::XML_PATH_MAX_COUNT_CACHEABLE_SEARCH_TERMS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId ); } }