On my site i have an input textbox where you can enter some searchtext. The results of this search should show up in a dropdown below the textbox (autocomplete like).
When i hit enter in the textbox Magento searches like this:
../catalogsearch/result/?q=some+searchtext
I want the dropdown results to be the same as what Magento gives back with the above searchmethod.
I tried with following code:
$_query = Mage::helper('catalogsearch')->getQuery();
$_productCollection = Mage::getModel('catalogsearch/fulltext')->getCollection()
->addSearchFilter($_query)
->addAttributeToSelect('name')
->addAttributeToSelect('description')
->addAttributeToSelect('price')
->addAttributeToSelect('short_description')
->setPageSize($pagesize)
->load();
The problem here is that it only works on searchcriteria that has already been processed by the first method (by hitting enter in the textbox).
Can anyone point me out how Magento manages this search? I know that the ResultController handles this method in a way, but i can't figure it out.
Thank you in advance.
UPDATE: Turns out to be that the query needed to be prepared first
$_query = Mage::helper('catalogsearch')->getQuery()
->prepare();
$_productCollection = Mage::getResourceModel('catalogsearch/fulltext_collection')
->addAttributeToSelect('name')
->addAttributeToSelect('description')
->addAttributeToSelect('price')
->addAttributeToSelect('short_description')
->addAttributeToSelect('thumbnail')
->addSearchFilter($_query)
->setPageSize($pagesize);