Back to 2.x

Magento prevent spammy search terms

Post a reply
167 views
Mageuser
Mageuser

In our Magento site, we are getting a lot of spammy searches having Chinese characters. Some of them are even coming from Google and Bing bots. We have blocked them using robots.txt. But we still get many spammy searches. How can we block these searches

Moderator
Moderator

You can create a module to override the catalog search module of Magento. In the di.xml override the controller

<?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\CatalogSearch\Controller\Result\Index" type="Vendor\SpamSearch\Controller\Result\Index" />
</config>

In the SpamSearch\Controller\Result\Index.php after $queryText = $query->getQueryText(); check for non English characters.

if (preg_match('/[^A-Za-z0-9]/', $queryText)) 
{
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
}else{

Last updated

1-2 of 2

Reply to this discussion

You cannot edit posts or make replies: You should be logged in before you can post.