我试图通过全局索引搜索返回突出显示 FOSElastica Bundle .
我的配置(yml 文件)中有一个全局索引查找器:
fos_elastica:
clients:
default: { host: %elastic_host%, port: %elastic_port% }
indexes:
myIndex:
client: default
finder: ~
types:
# different types here
我按照文档使用它(here):
$finder = $this->container->get('fos_elastica.finder.myIndex');
// Returns a mixed array of any objects mapped
$results = $finder->find('whatever');
效果完美并返回预期结果。 现在我想使用 ES 的快速矢量荧光笔来突出显示结果中找到的单词。但我没有找到任何示例或任何文档来这样做。
我想我需要定义一个更合适的\Query 对象,例如:
$query = new \Elastica\Query();
$query->setHighlights(array("whatever"));
$query->setTerm("whatever");
$results = $finder->find($query);
但是我找不到任何信息。有什么提示吗?
非常感谢!!
最佳答案
首先用 JSON 编写查询:
{
"query" : {
"match" : {
"content" : "this is a test"
}
},
"highlight" : {
"fields" : {
"content" : {}
}
}
}
当它起作用时,转换为 Elastica:
$matchQuery = new \Elastica\Query\Match();
$matchQuery->setField('content', 'this is a test');
$searchQuery = new \Elastica\Query();
$searchQuery->setQuery($matchQuery);
$searchQuery->setHighlight(array(
"fields" => array("content" => new \stdObject())
));
关于php - FOSElastica bundle : retrieving highlights for results,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24340385/