我想在我的网站首页创建搜索框,但我不知道如何使用Solr创建一个。我所有的网站都是用Symfony2开发的。我不使用数据库进行搜索。
我怎么能做到这一点?
在我的项目Solr bundle 中使用这个:
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;
}
但是在渲染的树枝文件中,我不知道我会写什么。