gpt4 book ai didi

symfony - Fos elastica 滤波器结果与数组 "record id' s"

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

我有一个包含许多记录的 SQL 表。当我搜索时,我不想使用所有结果,但我希望它在我想要的 id 中。

我添加了'term ' 并添加了 ' addMust ' 到 boolQuery .但是没有结果。 ' addShould ' 正如我添加的那样,没有搜索我的标准。

// only the results of the ids in the data_ids array.
$finder = $this->container->get('fos_elastica.finder.xxxxx');
$boolQuery = new \Elastica\Query\BoolQuery();

$fieldQuery = new \Elastica\Query\Match();
$fieldQuery->setFieldQuery('name', $searchKey);
$fieldQuery->setFieldFuzziness('name', 1);
$boolQuery->addShould($fieldQuery);

$termQuery = new \Elastica\Query\Term();
$termQuery->setTerm('id', $data_ids);
$boolQuery->addShould($termQuery); // Without my criteria
//$boolQuery->addMust($termQuery); // No result

$vars = $finder->find($boolQuery, $limit);

样本 !!!
// seaching id's.
$data_ids = [1,2,3,12,13,16,17,24,65,234,657,45];

如果我使用 addMust ;
总是输出;
[]

如果我使用 addShould ;
样本输出;
[
{
"station": {
"id": 8,
"name": "ETC"
},
"area": {
"id": 1,
"name": "ETC"
},
"city": {
"id": 2,
"name": "Istanbul"
},
"district": {
"id": 2,
"name": "Besiktas"
}
}
]

但站 id 8不在 $data_ids 中大批。

我怎么解决这个问题。

最佳答案

试试这个:

$termsQuery = new \Elastica\Query\Term();
$termsQuery->setTerms('ids', $data_ids); // note: $data_ids is an array
$boolQuery->addMust($termQuery);

关于symfony - Fos elastica 滤波器结果与数组 "record id' s",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56037234/

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