Skip to content

Header search bar search terms retrieve products collection

I’m working on header autosuggest search, keywords that show the popularity of search suggestions based on old customers in that search suggetions.

like if we search shirt then it suggest t-shirts, boys shirt, and casual shirts bla bla with the terms count.

When we select a keyword its lands on the PLP page.

So I want to show the collection of product count in front of the autosuggestion keyword.

/vendor/magento/module-catalog-search/Model/Autocomplete/DataProvider there we can get the result of serach terms by search query.

I tried with the SearchcriteriaBuilder and FilterGroupBuilder but it returns the wrong product collection count.

Can someone please help me with this?