我想过滤发布条件:
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/