Magento – Where I can modify Magento search query

magento2

In magento2 I want to change the catalog search query of the frontend.

In particular, when there are multiple words in search query I would search with AND instead of OR. Example "red apple" not "red" and "apple".

Which file should I change?

Best Answer

You can find the execute function at

/vendor/magento/module-search/Controller/Ajax/Suggest.php


public function execute()
{
    if (!$this->getRequest()->getParam('q', false)) {
        /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
        $resultRedirect->setUrl($this->_url->getBaseUrl());
        return $resultRedirect;
    }

You can modify the query by your module Ref

Hope this helps.

Related Topic