gpt4 book ai didi

elasticsearch - 信息检索 - 我如何处理将单个单词分解为多个标记的搜索查询

转载 作者:行者123 更新时间:2023-12-03 02:37:15 24 4
gpt4 key购买 nike

我只是信息检索的初学者。
我正在寻求解决一个问题,即用户在输入单词时错误地在字符之间添加空格或将两个单词合并为一个,由于简单的倒排索引查找,该问题目前无法处理。
假设我对以下文档进行了倒排索引:

  • jack 和吉尔是好 friend 。
  • jack 去了阿拉斯加。
  • 吉尔住在纽约。

  • 现在拥有倒排索引意味着拥有 纽约 索引为单独的标记(假设仅作为示例并且没有使用 NLP 将纽约标记为位置)
    token    count    location
    jack 2 1,2
    jill 2 1,2
    new 1 3
    york 1 3
    alaska 1 4
    现在查询 千斤顶 ,我会得到位置 1,2,这很好。
    但查询 纽约 (假设查询没有空格)我怎样才能得到 纽约 来自将具有位置 3(组合)的索引。
    也可查询 阿拉斯卡 (带空格)如何检索 token 阿拉斯加 (索引中没有空格)分别。
    我错过的任何建议或任何特定算法。
    我只是信息检索的初学者。
    感谢您的帮助。
    我正在考虑将每个查询标记分解为字符元组合,最后将它们合并以找出最常见的标记。
    例如查询 纽约

    Find all the tokens of till limit n, starting with n... then ne....then new.... then newy.... etc, similarly like ne.. ew...wy..yo..or..rk...,

    which will finally after merging the array will get new and york somewhere..


    与查询 类似阿拉斯卡 (用空格打破这个词)

    最佳答案

    也许这样的东西对你有用:

    使用自定义分析器创建索引( ngram 标记器)
    Read about NGram Tokenizer

    PUT /index
    {
    "mappings": {
    "doc": {
    "properties": {
    "token": {
    "type": "text",
    "analyzer": "myanalyzer"
    },
    "location":{
    "type": "text"
    }
    }
    }
    },
    "settings": {
    "analysis": {
    "analyzer": {
    "myanalyzer": {
    "tokenizer": "my_tokenizer",
    "filter": []
    }
    },
    "tokenizer": {
    "my_tokenizer": {
    "token_chars": [
    "letter",
    "digit",
    "symbol",
    "punctuation"
    ],
    "min_gram": "3",
    "type": "ngram",
    "max_gram": "4"
    }
    }
    }
    }
    }

    让我们 发布 新文件
    POST index/doc
    {
    "token": "alaska",
    "location":[4]
    }

    POST index/doc
    {
    "token": "york",
    "location":[3]
    }

    POST index/doc
    {
    "token": "new",
    "location":[3]
    }

    POST index/doc
    {
    "token": "jack",
    "location":[1,2]
    }

    POST index/doc
    {
    "token": "jill",
    "location":[1,2]
    }

    搜索:
    GET index/_search
    {
    "query": {
    "match": {
    "token": "ala ska"
    }
    }
    }

    结果:
    {
    "took": 3,
    "timed_out": false,
    "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
    },
    "hits": {
    "total": 1,
    "max_score": 1.9346048,
    "hits": [
    {
    "_index": "index",
    "_type": "doc",
    "_id": "z7hBMG4BXy8wPzqAcq-C",
    "_score": 1.9346048,
    "_source": {
    "token": "alaska",
    "location": [
    4
    ]
    }
    }
    ]
    }
    }

    关于elasticsearch - 信息检索 - 我如何处理将单个单词分解为多个标记的搜索查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58678161/

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