确定哪些词在模糊搜索中匹配 [英] Determining which words were matched in a fuzzy search

查看:26
本文介绍了确定哪些词在模糊搜索中匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行模糊搜索,需要查看匹配的单词.例如,如果我正在搜索查询 testing,并且它与带有句子 The boy was resting 的字段匹配,我需要能够知道匹配是由于resting这个词.

I'm running a fuzzy search, and need to see which words were matched. For example, if I am searching for the query testing, and it matches a field with the sentence The boy was resting, I need to be able to know that the match was due to the word resting.

我尝试设置参数explain = true,但它似乎没有包含我需要的信息.有什么想法吗?

I tried setting the parameter explain = true, but it doesn't seem to contain the information I need. Any thoughts?

推荐答案

好的,这就是我要找的:

Alright, this is what I was looking for:

经过一番研究,我找到了 elasticsearch 的突出显示功能.

After a bit of research, I found the Highlighting feature of elasticsearch.

默认情况下,它返回围绕匹配的上下文片段,但您可以将片段大小设置为查询长度以仅返回完全匹配.例如:

By default it returns a snippet of context surrounding the match, but you can set the fragment size to the query length to return only the exact match. For example:

{
    query : query,
    highlight : {
        "fields" : {
            'text' : {
                "fragment_size" : query.length
            }
        }
    }
}

这篇关于确定哪些词在模糊搜索中匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆