搜索推荐
搜索推荐:
一、Completion Suggester(为主)
Completion Suggester会被构建成FST对象,缓存在RAM中,查询速度会变快
1 #complate suggester 2 DELETE suggest_carinfo 3 PUT suggest_carinfo 4 { 5 "mappings": { 6 "properties": { 7 "title": { 8 "type": "text", 9 "analyzer": "ik_max_word", 10 "fields": { 11 "suggest": { 12 "type": "completion", 13 "analyzer": "ik_max_word" 14 } 15 } 16 }, 17 "content": { 18 "type": "text", 19 "analyzer": "ik_max_word" 20 } 21 } 22 } 23 } 24 25 26 27 POST _bulk 28 {"index":{"_index":"suggest_carinfo","_id":1}} 29 {"title":"宝马X5 两万公里准新车","content":"这里是宝马X5图文描述"} 30 {"index":{"_index":"suggest_carinfo","_id":2}} 31 {"title":"宝马5系","content":"这里是奥迪A6图文描述"} 32 {"index":{"_index":"suggest_carinfo","_id":3}} 33 {"title":"宝马3系","content":"这里是奔驰图文描述"} 34 {"index":{"_index":"suggest_carinfo","_id":4}} 35 {"title":"奥迪Q5 两万公里准新车","content":"这里是宝马X5图文描述"} 36 {"index":{"_index":"suggest_carinfo","_id":5}} 37 {"title":"奥迪A6 无敌车况","content":"这里是奥迪A6图文描述"} 38 {"index":{"_index":"suggest_carinfo","_id":6}} 39 {"title":"奥迪双钻","content":"这里是奔驰图文描述"} 40 {"index":{"_index":"suggest_carinfo","_id":7}} 41 {"title":"奔驰AMG 两万公里准新车","content":"这里是宝马X5图文描述"} 42 {"index":{"_index":"suggest_carinfo","_id":8}} 43 {"title":"奔驰大G 无敌车况","content":"这里是奥迪A6图文描述"} 44 {"index":{"_index":"suggest_carinfo","_id":9}} 45 {"title":"奔驰C260","content":"这里是奔驰图文描述"} 46 {"index":{"_index":"suggest_carinfo","_id":10}} 47 {"title":"nir奔驰C260","content":"这里是奔驰图文描述"} 48 49 50 GET suggest_carinfo/_search?pretty 51 { 52 "suggest": { 53 "car_suggest": { 54 "prefix": "奥迪", 55 "completion": { 56 "field": "title.suggest" 57 } 58 } 59 } 60 } 61 62 #1:内存代价太大,原话是:性能高是通过大量的内存换来的 63 #2:只能前缀搜索,假如用户输入的不是前缀 召回率可能很低 64 65 POST suggest_carinfo/_search 66 { 67 "suggest": { 68 "car_suggest": { 69 "prefix": "宝马5系", 70 "completion": { 71 "field": "title.suggest", 72 "skip_duplicates":true, 73 "fuzzy": { 74 "fuzziness": 2 75 } 76 } 77 } 78 } 79 } 80 GET suggest_carinfo/_doc/10 81 GET _analyze 82 { 83 "analyzer": "ik_max_word", 84 "text": ["奔驰AMG 两万公里准新车"] 85 } 86 87 POST suggest_carinfo/_search 88 { 89 "suggest": { 90 "car_suggest": { 91 "regex": "nir", 92 "completion": { 93 "field": "title.suggest", 94 "size": 10 95 } 96 } 97 } 98 }
作者:http://cnblogs.com/lyc-code/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权力。