ElasticSearch的搜索推荐(typeahead)
来源:互联网 发布:查淘宝号的网址 编辑:程序博客网 时间:2024/06/06 07:00
搜索推荐,即typeahead,也就是我们在搜索的时候,比如输入lucene el,这时候会给我一些提示:
lucene elasticsearch
lucene elasticsearch 区别
lucene elasticsearch solr
一 短语前缀匹配(phrase prefix matching)
即我通过使用短语前缀匹配,既可以查询所有lucene el开始的短语的文档。原理跟match_phrase类似,唯一的区别,就是把最后一个term作为前缀去搜索。
lucene会进行match搜索对应的文档;el作为前缀去扫描整个倒排索引找到以el开头的文档;然后再在所有文档中找到既包含lucene,又包含el的文档,根据你的slop参数,看在slop范围内,能不能让lucene el正好跟doc中的lucene 和 el开始的单词的position匹配
POST /typeahead/guitar/_search
{
"query":{
"match_phrase_prefix": {
"title": {
"query":"Guitar F",
"slop":2
}
}
}
}
但是这种机制,性能不好,因为最后一个前缀始终要去扫描大量的索引,性能可能会很差
二 ngram
2.1 什么是ngram,其运行原理是什么?
ngram是一种分词方法照顾所有的可能,N表示一个数字,比如2-gram分词法,表示以长度为2进行分割单词,然后编进索引。比如针对hadoop这个term。
如果
N=1:h a d o o p
N=2: ha ad do oo op
N=3: had ado doo oop
N=4: hado adoo doop
N=5: hadoo adoop
N=6: hadoop
2.2 什么是edge_ngram
edge_ngram: 指的就是一个词条过滤器,然后会根据在索引里配置的最小ngram和最大ngram进行词条的切分。
PUT /typeahead
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 15
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
}
}
min_ngram: 1表示至少为1
max_ngram: 表示词条最大长度为15,超过这个长度将不再进行切分
我们可以利用如下代码检测:
GET /typeahead/_analyze
{
"analyzer": "autocomplete",
"text": " congratulations "
}
2.3 利用ngram进行搜索推荐
首先索引进行映射
PUT /typeahead/_mapping/guitar
{
"properties": {
"title": {
"type": "string",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
然后就可以开始搜索了:
POST /typeahead/guitar/_search
{
"query": {
"match_phrase":{
"title":{
"query": "Guitar F",
"slop":3
}
}
}
}
2.4 ngram 优缺点
优点:比短语前缀匹配的性能更好些
缺点:ngram分词法的缺点是:为了照顾所有可能,于是把很多不必要的词也加入到索引中,索引项增加。
- ElasticSearch的搜索推荐(typeahead)
- Elasticsearch-搜索推荐
- typeahead搜索提示
- typeahead搜索提示
- ElasticSearch学习29_基于Elasticsearch实现搜索推荐
- Bootstrap-------------之Typeahead 组件,配合elasticsearch使用
- 由Typeahead想到的搜索的本质,和OO和数据库是统一的
- boostrap 搜索框typeahead自动补全
- twitter-bootstrap-typeahead文本框搜索提醒组件
- elasticsearch的java搜索语法
- Elasticsearch搜索附近的人
- ElasticSearch 数组搜索的资料
- ElasticSearch搜索优化的方法
- elasticsearch里面的内容搜索
- Bootstrap Typeahead 组件的使用
- bootstrap-typeahead的ajax调用
- 分布式搜索elasticsearch java API 之(八)------使用More like this实现基于内容的推荐
- 分布式搜索elasticsearch java API 之(八)------使用More like this实现基于内容的推荐
- <input type="file"/>实现图片预览
- laravel路由设置模型绑定
- PHP大数组过滤元素、修改元素性能分析
- Mysql Server 安装
- 调整数组使奇数全部都位于偶数前面
- ElasticSearch的搜索推荐(typeahead)
- jquery得到版本方法
- java学习第48天,删除目录
- BigDecimal
- junit的Rule使用方法介绍
- 初读GoogLeNet《Going Deeper with Convolutions》
- LNMP中的mysql,php,nginx安装
- web前端优化(1)
- (翻译)票选模式(Vote To Promote)