How to override catalogsearch model class in magento

In magento if you wish to override some controller then definately you will get lots of site which will describe how to do that but for model class, you will have some result. So I think to share my knowledge here. I am going to override default catalog search Model of magento. For that I will create an module with name space name Mage and module name Searchby. I hope you people know how to create an module so I will show you how to override model class only

Go to config.xml of your custom module then write the below code to override the catalogsearch model class

<?xml version="1.0" encoding="UTF-8"?>

Now create an Layer.php file inside yourmodulename/Model then write the below code

class Mage_Searchby_Model_Layer extends Mage_CatalogSearch_Model_Layer
    public function prepareProductCollection($collection)
        //Code to be executed

That's all thanks