1

Is there a way to get the 5 tops search terms like in the Dashboard as array without having to query database->table directly sorting them popularity limit 5?

1 Answer 1

1

Found a way using Magento\Search\Model\ResourceModel\Query\CollectionFactory

...
$searchCollection =  $this->_queryCollectionFactory->create()
   ->setPopularQueryFilter($this->_storeManager->getStore()->getId())
   ->setPageSize(5)
   ->load()
   ->getItems();

    foreach($searchCollection as $k=>$v) {
        echo $vv->getQueryText().', ';
    }
       ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.