【发布时间】:2015-04-20 17:48:29
【问题描述】:
我使用Redis 来为单词和包含这些单词的文档构建倒排索引系统。
设置非常简单:Redis Sets 其中Set 的键是:i:word,Set 的值是文档ID 有这个词的
假设我有 2 套:i:example 和 i:result
query - "example result" 将与 i:example 和 i:result 相交并返回所有同时具有 example 和 result 作为成员的 id
但我正在寻找的是一种执行(以有效方式)查询的方法,例如:“ex res”。结果集应至少包含查询 "example result"
中的所有 id我想到的解决方案:
创建大小为 2 的前缀集:
p:ex - contains {"example", "expertise", "ex"...}。查找运行时间不会成为问题 -O(1)获取集合,O(n)检查集合中的所有元素以查找以前缀开头的单词(其中n = set.size()),但我担心增加的尺寸价格。使用扫描:但我不确定运行时间 - 像
scan 0 match ex*这样的查询将花费 O(n) where n is the number of keys in the db?我知道 redis 很快,但它可能不是像 "ex machi cont" 这样的查询的优化解决方案。
【问题讨论】: