我想在我的网站的头版创造搜索框但我不知道如何创建使用Solr的之一。我所有的网站都是在Symfony2中开发的。我不使用数据库进行搜索。在搜索框的Symfony2使用Solr
我该如何做到这一点?
在我的项目Solr的捆绑使用本:
use SolrClient;
use SolrQuery;
use SolrObject;
use SolrDocument;
use SolrInputDocument;
在基地枝杈文件:
<form action="{{ path("home_search") }}" method="get">
<input type="search" name="search"><br>
<input type="submit" value="search">
</form>
我控制器的一些例子:
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;
}
但在小枝文件这里我s渲染我不知道我会写什么。
你在使用连接和Solr的搜索捆绑? –
@ArtemL谢谢你的评论。我正在使用solr bundle和搜索没有,因为我是新搜索与solr。 – Sid
你正在使用什么捆绑包?如何?一些鳕鱼可能有助于回答这个问题。 –