gpt4 book ai didi

elasticsearch - 在词组提示中建议下一个单词

转载 作者:行者123 更新时间:2023-12-02 22:29:04 26 4
gpt4 key购买 nike

我如何建议词组提示中的下一个单词?
我尝试了https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html的一个简单示例,但似乎没有建议

如果我键入“red”,我什么也没得到,当我期望得到“red dog”时,带状疱疹过滤器的确会产生我期望的二元体。

这是一个例子

PUT test
{
"settings": {
"index": {
"number_of_shards": 1,
"analysis": {
"analyzer": {
"trigram": {
"type": "custom",
"tokenizer": "standard",
"filter": ["standard", "shingle"]
}
},
"filter": {
"shingle": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 3
}
}
}
}
},
"mappings": {
"test": {
"properties": {
"summary": {
"type": "text",
"fields": {
"trigram": {
"type": "text",
"analyzer": "trigram"
}
}
}
}
}
}
}
POST test/test?refresh=true
{"summary": "Red dog"}
POST test/test?refresh=true
{"summary": "Blue word"}


GET test/_analyze
{
"field":"summary.trigram",
"text":"red dog"
}

POST test/_search
{
"suggest": {
"text": "red",
"simple_phrase": {
"phrase": {
"field": "summary.trigram",
"size": 1,
"gram_size": 3,
"direct_generator": [ {
"field": "summary.trigram",
"suggest_mode": "always",
"min_word_length":2
} ],
"highlight": {
"pre_tag": "<em>",
"post_tag": "</em>"
}
}
}
}
}

最佳答案

短语提示器为什么不起作用?

Phrase suggester不为字符串"red"建议任何内容的原因是因为它的拼写正确,而短语提示者实际上是拼写提示者,而不是completion suggester

如果您尝试执行"reddog"(不带空格),则会得到建议:

  "suggest": {
"simple_phrase": [
{
"text": "reddog",
"offset": 0,
"length": 6,
"options": [
{
"text": "red dog",
"highlighted": "<em>red dog</em>",
"score": 0.44063255
}
]
}
]
}

如果添加此文档:
POST test/test?refresh=true
{"title": "reddish dog"}

并查询输入 "reddi"的建议,您还将获得拼写更正:
  "suggest": {
"simple_phrase": [
{
"text": "reddi",
"offset": 0,
"length": 5,
"options": [
{
"text": "reddish",
"highlighted": "<em>reddish</em>",
"score": 0.3440574
}
]
}
]
}

如何建议词组中的下一个单词?

似乎您正在寻找其他类型的建议- Completion Suggest

如果尝试使用此映射:
PUT test
{
"mappings": {
"test": {
"properties": {
"summary": {
"type": "text",
"fields": {
"suggest": {
"type" : "completion"
}
}
}
}
}
}
}

而这个查询:
POST test/_search
{

"suggest" : {
"my-suggestion" : {
"text" : "red",
"completion" : {
"field" : "summary.suggest"
}
}
}
}

您将获得想要的东西:
{
// ...
"suggest": {
"my-suggestion": [
{
"text": "red",
"offset": 0,
"length": 3,
"options": [
{
"text": "Red dog",
"_index": "test",
"_type": "test",
"_id": "AWGanwweVn0PQ9k--kkE",
"_score": 1,
"_source": {
"summary": "Red dog"
}
}
]
}
]
}
}

希望有帮助!

关于elasticsearch - 在词组提示中建议下一个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48767600/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com