The key to the fact that the layer block needs to be there can be found in Mage_CatalogSearch_Block_Layer
in the construct.
/**
* Internal constructor
*/
protected function _construct()
{
parent::_construct();
Mage::register('current_layer', $this->getLayer(), true);
}
The second line is the key: Mage::register('current_layer', $this->getLayer(), true);
without this line none of the search results will display correctly. What this does is tell the system what the current state of the search is.
This will set the current layer as type Mage_CatalogSearch_Model_Layer
but if this line is not run then later on the layer gets set as type Mage_Catalog_Model_Layer
. The two models have two similar but different prepareCollection functions.
Mage_CatalogSearch_Model_Layer
Has an important call to addSearchFilter
public function prepareProductCollection($collection)
{
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
->setStore(Mage::app()->getStore())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addStoreFilter()
->addUrlRewrite();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
return $this;
}
Mage_Catalog_Model_Layer
Has no addition of addSearchFilter and does not set or filter on the store.
public function prepareProductCollection($collection)
{
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addUrlRewrite($this->getCurrentCategory()->getId());
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
return $this;
}