Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to highlighting #101

Open
AlexLove77 opened this issue Jul 27, 2016 · 10 comments
Open

How to highlighting #101

AlexLove77 opened this issue Jul 27, 2016 · 10 comments

Comments

@AlexLove77
Copy link

AlexLove77 commented Jul 27, 2016

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!

@itbdw
Copy link

itbdw commented Aug 2, 2016

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"
      ]
    }
  }

@AlexLove77
Copy link
Author

@itbdw Thanks, but seems that Paginator does not support getHits().

@itbdw
Copy link

itbdw commented Aug 6, 2016

@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

@AlexLove77
Copy link
Author

@itbdw Many thanks, 蛤蛤~

@nathan-zhu
Copy link

@itbdw when can use highlight in Elasticquent?

@itbdw
Copy link

itbdw commented Sep 7, 2016

@nathan-zhu The author still did not merge the pr. I use my fork for now...

@nathan-zhu
Copy link

nathan-zhu commented Sep 7, 2016

@itbdw 给个连接呗,多谢。用你的 如何安装呢?

@itbdw
Copy link

itbdw commented Sep 7, 2016

我直接先用的这个,然后自己手动改的一些文件 #104

@nathan-zhu
Copy link

nathan-zhu commented Sep 8, 2016

@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" => "北京出盛世咨询服务公司国际教育甄选人才的理念。公司专注于研究美国、加拿大、"

这种多字段的高亮不支持吗,怎么只返回了一个字段的高亮内容。请指教

@itbdw
Copy link

itbdw commented Dec 22, 2016

@nathan-zhu 我刚刚看到。。。。试了一下没问题啊。。。两个都高亮了

diff 里只是同一个字段高亮匹配到多个结果的时候只取第一个。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
@timgws @itbdw @nathan-zhu @AlexLove77 and others