gpt4 book ai didi

php - Symfony Elasticsearch准则

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

我想过滤发布条件:

SELECT * FROM posts WHERE (title LIKE '%AA%' OR subtitile LIKE '%BB%') AND category = 'Car'

我尝试的是:
$finder = $this->container->get('fos_elastica.finder.website.article');
$boolQuery = new \Elastica_Query_Bool();

$fieldQuery = new \Elastica_Query_Text();
$fieldQuery->setFieldQuery('title', '*keyword*');
$fieldQuery->setFieldParam('title', 'analyzer', 'my_analyzer');
$boolQuery->addShould($fieldQuery);

$fieldQuery1 = new \Elastica_Query_Text();
$fieldQuery1->setFieldQuery('subtitle', '*keyword*');
$fieldQuery1->setFieldParam('subtitle', 'analyzer', 'my_analyzer');
$boolQuery->addShould($fieldQuery1);

$fieldQuery2 = new \Elastica_Query_Text();
$fieldQuery2->setFieldQuery('category', 'Car');
$boolQuery->addMust($fieldQuery2);

$data = $finder->find($boolQuery);

我收到“汽车”类别的所有帖子,并且其中一些帖子包含“关键字”,但我只需要“汽车”类别的帖子,那么contais关键字“关键字”却不是全部

如何修复我的代码。

最佳答案

将两个addShould替换为addMust

我还建议使用https://github.com/ongr-io/ElasticsearchBundle而不是https://github.com/FriendsOfSymfony/FOSElasticaBundle :)

关于php - Symfony Elasticsearch准则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27786294/

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