tch*_*hap 1 php search highlighting elasticsearch foselasticabundle
我正在尝试使用FOSElastica Bundle进行全局索引搜索返回高亮显示.
我的配置中有一个全局索引查找器(yml文件):
fos_elastica:
  clients:
    default: { host: %elastic_host%, port: %elastic_port% }
  indexes:
    myIndex:
      client: default
      finder: ~
      types: 
       # different types here
我根据doc(这里)使用它:
$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())
));