Symfony Elasticsearch标准

时间:2015-01-05 19:17:33

标签: php symfony elasticsearch

我想过滤帖子标准:

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

我收到了所有“汽车”类别的帖子,其中一些内容包含“关键字”,但我只需要发布“汽车”类别,即“关键字”关键字“关键字”,但不是全部

如何修复我的代码。

1 个答案:

答案 0 :(得分:1)