我想在数十亿个字符串中进行通用子字符串搜索。这个要求与一般的全文搜索有点不同,因为我想要查询“ubst”也可以点击“substr”。
Lucene 或 Sphinx 能够做到这一点吗?如果没有,您认为最好的方法是什么?
这种情况的最佳索引结构是后缀树 Lucene 没有实现这种类型的索引,因此它的子字符串搜索速度很慢。但是 lucene 有前缀树索引,这意味着如果您通过前缀搜索术语,您可以进行快速搜索。
Sphinx 确实支持有效的子字符串搜索。不幸的是,截至今天,此支持仅涉及 beta 版本,如此处所述。
我尝试了2.1.1 beta版本。它似乎工作正常。请参阅手动输入了解字典类型,了解
keywords
类型。
当我尝试使用 2.0.6 发行版时,它回退到低效的 crc 索引,在索引过程中给出以下警告:
WARNING: min_infix_len is not supported yet with dict=keywords; using dict=crc
我的最小配置文件:
source sour
{
type = xmlpipe2
xmlpipe_command = type C:\Temp\1\sphinx\input.xml
}
index inde
{
source = sour
path = testpa
enable_star = 1
dict = keywords
charset_type = utf-8
min_infix_len = 1
}
sqlite 有一个名为 fts5 的全文扩展。看起来稳定又自由。
Lucene 是最好的可用选项之一。 Lucene 支持子字符串搜索,因此 ubst 将返回 substr。
查看 http://wiki.apache.org/lucene-java/LuceneImplementations 了解合适的语言实现。