gpt4 book ai didi

symfony - Foselasticabundle:方法返回空结果

转载 作者:行者123 更新时间:2023-12-02 22:22:16 24 4
gpt4 key购买 nike

我将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);
}

但它返回以下空结果:
[{},{},{},{},{},{},{},{},{},{}]

有什么问题,我该如何解决?

最佳答案

结果是一个对象数组,我更改了代码:

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);
}

关于symfony - Foselasticabundle:方法返回空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51822343/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com