I want to create Search box in front page of my website but I don't know how to create one using Solr. All my website is developed in Symfony2. I don't use Database for searching.
How I can do this?.
In my project Solr bundle use this:
use SolrClient;
use SolrQuery;
use SolrObject;
use SolrDocument;
use SolrInputDocument;
In base twig file :
<form action="{{ path("home_search") }}" method="get">
<input type="search" name="search"><br>
<input type="submit" value="search">
</form>
Some example of my controller:
public function searchAction($templateName = '')
{
$solrService = $this->get('rocket.solr_service');
$solrQuery = new SolrQuery('*:*');
$solrQuery->addField('id')
->addField('name');
if (!empty($templateName)) {
$solrQuery->addFilterQuery(sprintf('name:"%s" OR design_template_tag_name:"%1$s" OR design_category_name:"%1$s"',
$templateName));
}
$solrQuery->setRows(1000);
$solrObject = $solrService->query(
'RocketBraPrintBundle:DesignTemplate',
$solrQuery,
SolrService::WRITER_FORMAT_SOLR_OBJECT
);
$templates = $solrObject->offsetGet('response')->offsetGet('docs');
if (!$templates) {
if (!empty($templateName)) {
$this->setFlash('catalog-message', 'No results found for your search.');
return $this->searchDesignTemplates($categoryTreeSlug,
$productFamilyFaceId);
}
return array();
}
return $templates;
}
But in twig file where this is render I don't know what I will write.