For a specific store i want an remove search results, if search query matches our SKU pattern.
- disable "searchable" in attribute config is no solution
- rewrite core files is not wanted
So, what i need is an event which let me manipulate the search query or product collection for search result page.
I tried following events.
catalogsearch_searchable_attributes_load_after
... not triggeredcatalogsearch_query(_load_before/after)
... also not triggered- and some others ... ;)
... but without success.
Working solutions so far ... using catalog_product_collection_load_before
with following observer:
public function test(Varien_Event_Observer $observer)
{
// some logic for check current store
// ...
$action = Mage::app()->getFrontController()->getAction()->getFullActionName();
if ($action === 'catalogsearch_result_index') {
$query = Mage::app()->getRequest()->getParam('q');
if (preg_match("/my regex/", $query)) {
// force empty collection with invalid entity_id
$observer->getCollection()->addFieldToFilter('entity_id', false);
}
}
}
.but this looks like an ugly hack to me and shouldn't be final.
Hope you have some better approaches - maybe an more suitable event, that's no triggered for every product collection?
Update 1:
Regex check isn't really good, because partial search still works.
Preferred solution would be to disable SKU from searchable fields without disbale it globally from attribute configuration.
Update 2:
Instead of using regex i switched over to this, because it seems more correct if sku pattern is part of name/description/... and sould be searchable:
$observer->getCollection()->addFieldToFilter('sku', array('nlike' => "%{$query}%"));