2

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);
2
$queryText = Mage::helper('catalogSearch')->getQueryText();

$collection = Mage::getResourceModel('catalogsearch/query_collection')
->setStoreId($storeId)
->setQueryFilter($queryText);

May this helps

  • I updated the question with the solution that worked for me. Appreciate your answer, thanks. – excaliber Sep 25 '13 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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