我在Fymlasticabundle中使用Elasticsearch在我的Symfony应用程序中进行搜索,但是返回空结果。 这是我的配置和搜索方法:
foselasticbunde.yml:
indexes:
search:
finder: ~
client: default
types:
course:
mappings:
id: ~
title: ~
persistence:
driver: orm
model: AppBundle\Entity\Course
finder: ~
provider: ~
listener: ~
SearchController.php
public function elasticSearchAction(Request $request)
{
$query = $request->get('q');
$finder = $this->container->get('fos_elastica.finder.search.course');
$results = $finder->find($query);
return new JsonResponse($results);
}
但是它返回空结果:
[{},{},{},{},{},{},{},{},{},{}]
有什么问题,我该如何解决?
答案 0 :(得分:2)
结果是一个对象数组,我更改了代码:
public function elaSearchAction(Request $request)
{
$query = $request->get('q');
$finder = $this->container->get('fos_elastica.finder.search.course');
$results = $finder->find($query);
$data = array();
foreach ($results as $course){
$data[] = array(
'id' => $course->getId(),
'title' => $course->getTitle(),
'description' => $course->getDescription(),
);
}
return new JsonResponse($data);
}