我使用Elasticsearch和Foselasticabundle在我的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);
}但是它返回的结果是空的:
[{},{},{},{},{},{},{},{},{},{}]问题出在哪里?我该如何解决它?
发布于 2018-08-15 01:07:15
结果是一个对象数组,我更改了我的代码:
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);
}https://stackoverflow.com/questions/51822343
复制相似问题