infinilabs / analysis-ik

🚌 The IK Analysis plugin integrates Lucene IK analyzer into Elasticsearch and OpenSearch, support customized dictionary.
Apache License 2.0
16.54k stars 3.27k forks source link

About IK + Phrase Suggester #447

Open cailurus opened 7 years ago

cailurus commented 7 years ago

Hi @medcl

最近在打算使用 Phrase Suggester 的时候碰到点困难,想咨询下是不是哪里出了问题。

比方说我的 Mapping 是这样设置的:

"title_zh": {"type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word"} "title_en": {"type": "text"}

title_zh和title_en分别是document中两个field,title_zh采用IK分词,title_en采用默认的分词。

随后我随便塞一个document进去,其中两个字段内容分别是: "title_zh": "苹果手机", "title_en":"apple iphone"

接下来我想使用 Phrase suggester 的功能:

curl -XPOST 'localhost:9200/anew/_search?pretty' -H 'Content-Type: application/json' -d' { "suggest": { "text": "applo iphene", "simple_phrase": { "phrase": { "field": "title_en", "size": 1, "gram_size": 3, "highlight": { "pre_tag": "<em>", "post_tag": "</em>" } } } } } '

返回结果是我想要的: { "took" : 2, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 0, "max_score" : 0.0, "hits" : [ ] }, "suggest" : { "simple_phrase" : [ { "text" : "applo iphene", "offset" : 0, "length" : 12, "options" : [ { "text" : "applo iphone", "highlighted" : "applo <em>iphone</em>", "score" : 0.24598429 } ] } ] } }

但是换做title_zh这个field却不行,是哪里配置不对呢? curl -XPOST 'localhost:9200/anew/_search?pretty' -H 'Content-Type: application/json' -d' { "suggest": { "text": "平果手机", "simple_phrase": { "phrase": { "field": "title_zh", "size": 1, "gram_size": 3, "highlight": { "pre_tag": "<em>", "post_tag": "</em>" } } } } } '

{ "took" : 1, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 0, "max_score" : 0.0, "hits" : [ ] }, "suggest" : { "simple_phrase" : [ { "text" : "平果手机", "offset" : 0, "length" : 4, "options" : [ ] } ] } }

medcl commented 7 years ago

ik_max_word 不适合 phrase 查询,可以换成 smart 么

cailurus commented 7 years ago

@medcl 将mapping中title_zh这个field改成了: "title_zh": {"type": "text", "analyzer": "ik_smart"}

其他均不变,依然是空返回,还需要其他的设置吗?

haochun commented 6 years ago

@ailurus1991 哥们,你解决了没?我也遇到同样的问题了,英文的参照官网没问题,但用中文就有问题

cailurus commented 6 years ago

@haochun 没有,放弃 Phrase Suggester 这个方案了。

haochun commented 6 years ago

@ailurus1991 请问你怎么处理的呢

ghost commented 5 years ago

ik_smart确实也遇到这个问题,请问是否已经解决了?谢谢

ghost commented 5 years ago

266

meme-lau commented 4 years ago

加一,terms也是不行

baixiaoshi commented 3 years ago

请问有解决方案了吗

curryQin commented 3 years ago

请问有解决办法没

curryQin commented 3 years ago

@uxnow @medcl @cailurus @baixiaoshi 你们有啥解决方案了么 推荐词中文纠错这个根们没任何返回结果

ghost commented 3 years ago

没有

lsz8888 commented 3 years ago

@curryQin 需要在term suggest时加上min_word_length=2。默认值为4,而一般中文词的长度都小于4,设置为2比较合适。

flyinghawker commented 3 years ago

@curryQin 需要在term suggest时加上min_word_length=2。默认值为4,而一般中文词的长度都小于4,设置为2比较合适。 二(四)两拨千斤!

curryQin commented 3 years ago

感谢两位大佬@lsz8888@flyinghawker