进阶-第22__深度探秘搜索技术_实战match_phrase_prefix实现search-time搜索推荐

搜索推荐,search as you type,搜索提示,解释一下什么意思

 

hello w --> 点击搜索(下面的结果都给你推荐出来)

 

hello world

hello we

hello win

hello wind

hello dog

hello cat

 

hello w -->

 

hello world

hello we

hello win

hello wind

 

搜索推荐的功能

添加数据

PUT /my_index/my_type/1

{

  "title":"hello world"

}

PUT /my_index/my_type/2

{

  "title":"hello we"

}

PUT /my_index/my_type/3

{

  "title":"hello win"

}

PUT /my_index/my_type/4

{

  "title":"hello wind"

}

 

百度 --> elas 接下来后面的都会提示出来--> elasticsearch --> elasticsearch权威指南

 

搜索

GET /my_index/my_type/_search

{

  "query": {

    "match_phrase_prefix": {

      "title": "hello w"

    }

  }

}

GET /my_index/my_type/_search

{

  "query": {

    "match_phrase_prefix": {

      "title": {

        "query": "hello w",

        "slop":10,

        "max_expansions": 10

      }

    }

  }

}

结果:

{

  "took": 4,

  "timed_out": false,

  "_shards": {

    "total": 5,

    "successful": 5,

    "failed": 0

  },

  "hits": {

    "total": 4,

    "max_score": 1.4074042,

    "hits": [

      {

        "_index": "my_index",

        "_type": "my_type",

        "_id": "2",

        "_score": 1.4074042,

        "_source": {

          "title": "hello we"

        }

      },

      {

        "_index": "my_index",

        "_type": "my_type",

        "_id": "4",

        "_score": 1.4074042,

        "_source": {

          "title": "hello wind"

        }

      },

      {

        "_index": "my_index",

        "_type": "my_type",

        "_id": "1",

        "_score": 0.51623213,

        "_source": {

          "title": "hello world"

        }

      },

      {

        "_index": "my_index",

        "_type": "my_type",

        "_id": "3",

        "_score": 0.51623213,

        "_source": {

          "title": "hello win"

        }

      }

    ]

  }

}

 

 

 

原理跟match_phrase类似,唯一的区别,就是把最后一个term作为前缀去搜索

 

hello就是去进行match,搜索对应的doc

w,会作为前缀,去扫描整个倒排索引,找到所有w开头的doc

然后找到所有doc中,即包含hello,又包含w开头的字符的doc

根据你的slop去计算,看在slop范围内,能不能让hello w,正好跟doc中的hello和w开头的单词的position相匹配

 

也可以指定slop,但是只有最后一个term会作为前缀

 

max_expansions:指定prefix最多匹配多少个term,超过这个数量就不继续匹配了,限定性能

 

默认情况下,前缀要扫描所有的倒排索引中的term,去查找w打头的单词,但是这样性能太差。可以用max_expansions限定,w前缀最多匹配多少个term,就不再继续搜索倒排索引了。

 

尽量不要用,因为,最后一个前缀始终要去扫描大量的索引,性能可能会很差

 

搜索的时候,搜索推荐的功能,所以这个就叫做search-time 搜索推荐

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值