CQL中的子字符串查询

3
可以在CQL中找到一个字符串的子串吗? 例如,像这样查询: select id from table where string contains 'do' 谢谢。
1个回答

2
是的,使用存储附加索引(SASI)可以实现这一点。您的查询将类似于:
SELECT * FROM table WHERE colname LIKE 'do%';

请查看官方文档,了解如何使用它。


嗯,这就是我想要的,但它不起作用。我创建了这个 create table test (id int, string text, primary key (id));。然后我在 string 上创建了一个索引,之后我执行了这个查询:select * from test where string like 'and';,但是我没有得到任何答案。我已经尝试在 like 子句中使用 %,但问题仍然存在。 - Alexandre S.
这是我的索引:create custom index test on test(string) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = { 'mode': 'CONTAINS', 'analyzer_class': 'org.apache.cassandra.index.sasi.analyzer.StandardAnalyzer', 'analyzed': 'true', 'tokenization_skip_stop_words': 'and, the, or', 'tokenization_enable_stemming': 'true', 'tokenization_normalize_lowercase': 'true', 'tokenization_locale': 'en' };。我的查询是:select * from test where string like 'and' - Alexandre S.
我正在使用Cassandra 3.6版本。 - Alexandre S.
仍然返回0行,我错过了什么吗?我的表包含这两行: insert into test (id, string) values (1, 'test'); insert into test (id, string) values (2, 'banana and black'); - Alexandre S.
@AlexandreS。我看到你正在使用StandardAnalyzer跳过and。请注意验证您是否能够通过其他单词获取(例如插入一个包含单词cassandra的句子并查找%sand%)。 - xmas79
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接