【发布时间】:2014-07-21 05:18:43
【问题描述】:
Cassandra 中的全文搜索;
我对 Cassandra 还很陌生,希望能更准确地理解它。我正在尝试在 Cassandra 中执行全文搜索,但经过一些研究,我发现 可能 没有一种“简单”的方法。我说可能是因为谷歌什么也没说。
所以我现在试图理解,这里最好的方法是什么。这种引导我根据我迄今为止对 Cassandra 的了解做出自己的假设,即基于这两个校长; a) 根据您的查询而不是数据来设计您的表格,并且 b) 更多数据是一件好事,只要使用得当。
话虽如此,我想出了几个我想分享的解决方案,并要求如果有人有更好的想法,请在我做出任何不合理/幼稚的事情之前告诉我。
第一个解决方案:创建一个列族(CF),具有两个主键和一个索引,如下所示:
CREATE TABLE "FullTextSearch" (
"PartialText" text,
"TargetIdentifier" uuid,
"CompleteText" text,
"Type" int,
PRIMARY KEY ("PartialText","TargetIdentifier")
);
CREATE INDEX IX_FullTextSearch_Type "keyspace"."FullTextSearch" ("Type");
对于上表,我需要为文本“Hello World”插入行,如下所示:
BATCH APPLY;
INSERT INTO "FullTextSearch" ("PartialText","TargetIdentifier","CompleteText","Type") VALUES ("H",000000000-0000-0000-0000-000000000,"Hello World",1);
INSERT INTO "FullTextSearch" ("PartialText","TargetIdentifier","CompleteText","Type") VALUES ("He",000000000-0000-0000-0000-000000000,"Hello World",1);
INSERT INTO "FullTextSearch" ("PartialText","TargetIdentifier","CompleteText","Type") VALUES ("Hel",000000000-0000-0000-0000-000000000,"Hello World",1);
.....
INSERT INTO "FullTextSearch" ("PartialText","TargetIdentifier","CompleteText","Type") VALUES ("Hello Wor",000000000-0000-0000-0000-000000000,"Hello World",1);
INSERT INTO "FullTextSearch" ("PartialText","TargetIdentifier","CompleteText","Type") VALUES ("Hello Worl",000000000-0000-0000-0000-000000000,"Hello World",1);
INSERT INTO "FullTextSearch" ("PartialText","TargetIdentifier","CompleteText","Type") VALUES ("Hello World",000000000-0000-0000-0000-000000000,"Hello World",1);
.....
INSERT INTO "FullTextSearch" ("PartialText","TargetIdentifier","CompleteText","Type") VALUES ("Wor",000000000-0000-0000-0000-000000000,"Hello World",1);
INSERT INTO "FullTextSearch" ("PartialText","TargetIdentifier","CompleteText","Type") VALUES ("Worl",000000000-0000-0000-0000-000000000,"Hello World",1);
INSERT INTO "FullTextSearch" ("PartialText","TargetIdentifier","CompleteText","Type") VALUES ("World",000000000-0000-0000-0000-000000000,"Hello World",1);
END BATCH;
基本上,上面将满足以下通配符/部分文本“%o W%”、“Hello%”、“Worl%”;但是它不能满足部分词,例如“Hello”的“%ell%”,我现在可以感觉还好.....(OCD 排序在这里开始)
这种方法对我来说有点糟糕,因为我现在必须在“TargetIdentifier”上发生保存/名称更改时删除/重新插入;
第二种解决方案,只是这次使用宽列非常相似;表格可能如下所示:
CREATE TABLE "FullTextSearch" (
"TargetIdentifier" uuid,
"Type" int,
"CompleteText" text,
PRIMARY KEY("TargetIdentifier")
);
现在在搜索过程中类似于:
SELECT * FROM "FullTextSearch" WHERE "He" = 1;
这样,如果该列存在,则返回相应的行;
第三个解决方案: 与上面类似,只是这次我们不使用宽列,而是使用集合列(例如 map)作为部分文本,并执行如下查询:
SELECT * FROM "FullTextSearch" WHERE "PartialTexts"['He'] = 1;
无论如何,我都没有想法,已经晚了,我只能希望得到很好的回应!请让我知道我应该在这里做什么......我是否走在正确的道路上?
【问题讨论】:
标签: cassandra full-text-search cql