If you’ve got a fairly popular Magento store, you’ve probably got the problem of spam or malicious search terms showing up on the Popular Search Terms page. It’s ugly and you want to get rid of them once and for all, but at the same time leaving legitimate search terms performed by good-will users intact.
Of course you do. Me too. Look at this:
So how to delete spam search terms from Popular Search Terms page?
What I’ve done is to edit the /app/design/frontend/default/your_theme/template/catalogsearch/term.phtml until it looks something like this:
<?php
$princessly_search_term = $this->htmlEscape($_term->getName());
if (strpos($princessly_search_term, '%') !== false
|| strpos($princessly_search_term, "'") !== false
|| strpos($princessly_search_term, '`') !== false
|| strpos($princessly_search_term, '=') !== false) {
continue;
}
?>
<li><a href="<?php echo $this->getSearchUrl($_term) ?>" style="font-size:<?php echo $_term->getRatio()*70+75 ?>%;"><?php echo $princessly_search_term ?></a></li>
The PHP function strpos() checks if a specific character is existent in the string $princessly_search_term which contains the originally raw search phrase. If it does, it’s not displayed (continue to the next phrase and check it to see if it does).
Most malicious / spam search attempts contain ‘%’, “‘”, or ‘=’ which normal users wouldn’t use in a legitimate search for your products. Now the Popular Search Terms page is a lot more clean and user friendly.



