Elasticquent
Elasticquent copied to clipboard
How to highlighting
I find that the elasticquent model doesn't include a highlighting object so that I need to get it from ElasticquentPaginator with complexSearch manually like this:
$resultPaginator->hits['hits'][0]['highlight']
Is there any way to get it easier or add it as an optional parameter?
Thanks!
Well, I think you can use the getHits() method to get the original content from ES.
fox example
{
total: 49,
max_score: null,
hits: [
{
_index: "game",
_type: "game",
_id: "1829352",
_score: null,
_source: {
id: 1829352,
title: "SpongeBob Obstacle Odyssey 2",
content: "xxxxx",
},
highlight: {
title: [
"<em>SpongeBob</em> Obstacle Odyssey 2"
]
},
sort: [
"2"
]
}
}
@itbdw Thanks, but seems that Paginator does not support getHits().
@AlexLove77 the paginator does have a way to access the 'hits' data.
$result = Post::search($q)->paginate(10)->toArray();
{
total: 373,
per_page: 10,
current_page: 1,
last_page: 38,
next_page_url: "x",
prev_page_url: null,
from: 1,
to: 10,
hits: {
hits:[
{
"_source":{}
"highlight":{}
}
]
},
data: []
}
true, add a config and replace the _source data with highlight data seems to be a good idea. @timgws
I've updated my pull request which should solve this problem. see #104
@itbdw Many thanks, 蛤蛤~
@itbdw when can use highlight in Elasticquent?
@nathan-zhu The author still did not merge the pr. I use my fork for now...
@itbdw 给个连接呗,多谢。用你的 如何安装呢?
我直接先用的这个,然后自己手动改的一些文件 https://github.com/elasticquent/Elasticquent/pull/104
@itbdw 感谢提供这个高亮功能,我还有个问题也请帮看下,下面是多字段模糊匹配的ES查询语句。
{
"query": {
"bool": {
"should": [
{
"wildcard": {
"name": "*盛世*"
}
},
{
"wildcard": {
"desc": "*盛世*"
}
}
]
}
},
"highlight": {
"pre_tags": [
"<tag>"
],
"post_tags": [
"</tag>"
],
"fields": {
"name": {},
"desc": {}
}
}
}
my code is :
$query = array(
"bool" => array(
"should" => array(
"wildcard" => array(
"name" => array(
'value' => '*'. $search .'*'
)
),
"wildcard" => array(
"desc" => array(
'value' => '*'. $search .'*'
)
)
)
)
);
$highlight = array(
"pre_tags" => array("<tag>"),
"post_tags" => array("</tag>"),
"fields"=> array(
"name" => (object) array(),
"desc" => (object) array()
)
);
get result from es :
#hits: array:3 [▼
"total" => 1
"max_score" => 1.0
"hits" => array:1 [▼
0 => array:6 [▼
"_index" => " xl_1"
"_type" => "xl_type"
"_id" => "5"
"_score" => 1.0
"_source" => array:32 [▶]
"highlight" => array:1 [▼
"desc" => array:1 [▼
0 => "北京出<tag>盛世</tag>咨询服务公司国际教育甄选人才的理念。公司专注于研究美国、加拿大、"
]
]
]
]
]
#original: array:32 [▼
"id" => 5
"user_id" => 1
"name" => "北京出盛世咨询服务有限公司"
"logo" => ""
"big_pic" => ""
"num" => ""
"desc" => "北京出盛世咨询服务公司国际教育甄选人才的理念。公司专注于研究美国、加拿大、"
这种多字段的高亮不支持吗,怎么只返回了一个字段的高亮内容。请指教
@nathan-zhu 我刚刚看到。。。。试了一下没问题啊。。。两个都高亮了
diff 里只是同一个字段高亮匹配到多个结果的时候只取第一个。