gpt4 book ai didi

python - 在 mysql 中存储倒排索引

转载 作者:行者123 更新时间:2023-11-29 00:39:00 26 4
gpt4 key购买 nike

我正在努力创建一个非常大的倒排索引术语。你会建议什么方法?

首先

termId - > docId
a doc2[locations],doc5[locations],doc12[locations]
b doc5[locations],doc7[locations],doc4[locations]

第二

termId - > docId
a doc2[locations]
a doc5[locations]
a doc12[locations]
b doc5[locations]
b doc7[locations]
b doc4[locations]

p.s Lucene 不是一个选项

最佳答案

正确的表设计取决于您计划如何使用数据。如果您打算按原样使用 "doc2[locations],doc5[locations],doc12[locations]" 之类的字符串——无需任何进一步的后处理,那么您的 首先设计很好。

但是,如果——正如您的问题默示的那样——您有时可能希望将 doc2[locations]doc5[locations] 等视为单独的实体,那么您一定要使用您的Second 设计。

以下是一些用例,说明为什么第二种设计更好:

  • 如果您使用 First 并使用 termID = a 请求所有文档,那么您找回像这样的字符串doc2[locations],doc5[locations],doc12[locations] 然后你不得不 split 。

    如果您使用 Second,您会将每个文档作为单独的行获取。没有 split !

    第二种结构更方便。

  • 或者,假设在某个时候 doc5[locations] 发生了变化,您需要更新你的表。如果您使用 First 设计,则必须使用有些比较复杂MySQL string function查找并替换包含它的所有行中的子字符串。 (请注意,MySQL 没有内置 regex substitution。)

    如果您使用第二种设计,更新很容易:

    UPDATE table SET docId = "newdoc5[locations]" where docId = "doc5[locations]"

关于python - 在 mysql 中存储倒排索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13100166/

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