开发者

Magento - Exclude Search Term

Does anyone know if there is any way to exclude certain word开发者_StackOverflow中文版s from being searched for in Magento?

For example: Say I have a store that sells hats, I want to exclude the word “hats” from being searched, so if someone searches for “black hats” the it would only return results for “black”, because all the products are hats anyway, and if it allowed “hats” in the search term then it would return ALL hats.

Any ideas?


I am not sure you really need to do this, given the scenario you outlined. Magento uses like or fulltext as available search options (set via admin > system > configuration > catalog > catalog search), and neither of those would return all hats if the search query was "black hats."

If you still feel the need to exclude certain search terms, you could either extend app/code/core/Mage/CatalogSearch/Model/Query.php in the local code pool, and add a method that removes any unwanted search terms. Or - and this is the approach I would take - create a small module with an observer that catches the controller_action_predispatch event. This would allow you to sanitize/modify the query parameters to remove any search terms that should excluded, before the query ever gets passed to the ResultController.php.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜