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();
$query->setStoreId($storeId);
$query->setQueryText($searchQuery);
$collection = $query->getSearchCollection();
$collection->addSearchFilter($searchQuery);
$collection->addAttributeToSelect("*");
$collection->addCategoryIds();
$collection->addFinalPrice();
$collection->addUrlRewrite();
$collection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$collection->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
$collection->setPageSize(20);
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..
Best Answer
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:
Note that $shopidajax should be the current active shop ID and $searchQuery should of course be the actual search query string.