Search Box in Symfony2 with Solr Search Box in Symfony2 with Solr symfony symfony

Search Box in Symfony2 with Solr


you can use https://github.com/nelmio/NelmioSolariumBundle with use solarium implementation

Really great for better solr query

i already use it

here a sample

    $query = 'foo';    $page = 1;    if (array_key_exists('page', $params)) {        $page = (int) $params['page'];    }    $rows = 10;    if (array_key_exists('limit', $params)) {        $rows = (int) $params['limit'];    }    $solarium = $this->get('solarium.client');    //select    $select = $solarium->createSelect();    $escapedQuery = $select->getHelper()->escapePhrase($query);    //dismax    $dismax = $select->getDisMax();    // override the default setting of 'dismax' to enable 'edismax'    $dismax->setQueryParser('edismax');    //fields    $dismax->setQueryFields(                    array('title^5','description^0.7'));    $select->setQuery($escapedQuery);    //limit    $select->setRows($rows);    $select->setStart(($page - 1) * $rows);    //type spot only    $select->createFilterQuery('typeFilter')            ->setQuery(sprintf('type:%s', 'spot'));    $resultset = $solarium->select($select);

use foreach or twig "for in" to display your solr doc


Try something like this..

Controlloer.php:

public function searchAction($templateName = ''){    // ------    // ------    $resultset = $solrObject->offsetGet('response');    // Do some error checks    return array('resultset'=>$resultset);}

twig:

<ul>{% for doc in resultset %}  <li> {{ doc.name }} </li>{% endfor %}</ul>


I still have not tried, but you can try use this new Jobeet tutorial in Symfony2 that explains how to build a system and also how to use Solr in it.
I hope this help.