I´m in the middle of building a search module for Magento, and I´m currently facing a little bit of trouble, specifically regarding applying "Search Types" (Like, Fulltext or Combine) according to the admin configuration.

Here is my working query code:

$searchQuery = 'my search';
$storeId = '1';
$collection = Mage::getResourceModel("catalog/product_collection")->addAttributeToSelect("*");
$query = Mage::helper("catalogSearch")->getQuery();
$collection = $query->getSearchCollection();
$collection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$collection->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);

The only thing I need is to somehow define "Search Types" so it´s either "like", "fulltext" or "combine" depending on the shop configuration.

In other words, if the shop owner has set "Search Type" to "Combine(Like and Fulltext)" - then my query must also be search type "combine".

My problem is that I don´t know where to apply search type in the query.

I hope someone out there can help.

P.S. I normally work in Joomla, so I´m a complete novice when it comes to the Magento framework..

2 Answers 2


I finally found the correct solution. It turned out I was using the wrong approach regarding the query.

I managed to modify my query according to Ron´s answer to this thread: What's the proper way to call CatalogSearch from a custom Block in Magento?

Here is my final query, which performs a search according to the general Magento catalog search settings in admin:

$searchQuery = 'my search';
$shopidajax = '1';

$appEmulation = Mage::getSingleton('core/app_emulation');
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($shopidajax);

$searchText = $searchQuery;
$query = Mage::getModel('catalogsearch/query')->setQueryText($searchText)->prepare();
$fulltextResource = Mage::getResourceModel('catalogsearch/fulltext')->prepareResult(

$collection = Mage::getResourceModel('catalog/product_collection');
    array('search_result' => $collection->getTable('catalogsearch/result')),
        'search_result.product_id=e.entity_id AND search_result.query_id=?',
    array('relevance' => 'relevance')



Note that $shopidajax should be the current active shop ID and $searchQuery should of course be the actual search query string.


In my case results are different from native search and from above methods I used filters like in layers (app\code\core\Mage\CatalogSearch\Model\Layer.php F:prepareProductCollection) and also add following filter for same results as on web:

$collection->getSelect()->order('relevance DESC');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.