I need to get current product collection (actually I just need all Product IDS of products in current search result) of search result page in outside result.phtml, because I'm going to do something on layered navigation according to the product collection of search page can someone help me to get the product collection outside search result page

I have tried with

$term = Mage::helper('catalogsearch')->getQueryText();
    $collection = Mage::getResourceModel('catalogsearch/query_collection')->setQueryFilter($term)->getData();

but can not seems a way to return product IDs from above code.

1 Answer 1


Never mind I found a solution and it got work

$term = Mage::helper('catalogsearch')->getQueryText();
    $query = Mage::getModel('catalogsearch/query')->setQueryText($term)->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')

    $productIds = array();
    $productIds = $collection->getAllIds(); // as per Amit Bera s' comment
  • 2
    Chamal Chamikara,instead of get product ids from loop,you need to use $collection->getAllIds()better for getting data fast
    – Amit Bera
    Jul 7, 2015 at 12:02
  • @AmitBera ah yes :) it worked well thanks Jul 7, 2015 at 12:05

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.