Cassandra CQL通配符搜索

5

我有一个如下的表结构:

create table file(id text primary key, fname text, mimetype text, isdir boolean, location text);
create index file_location on file (location);

表中有以下内容:

insert into file (id, fname, mimetype, isdir, location) values('1', 'f1', 'pdf', False, 'c:/test/');
insert into file (id, fname, mimetype, isdir, location) values('2', 'f2', 'pdf', False, 'c:/test/');
insert into file (id, fname, mimetype, isdir, location) values('3', 'f3', 'pdf', False, 'c:/test/');
insert into file (id, fname, mimetype, isdir, location) values('4', 'f4', 'pdf', False, 'c:/test/a/');

我想要列出所有符合以下条件的 id:

select id from file where location like '%/test/%';

我知道 CQL 不支持 like,有人能提供一些解决类似通配符查询的方法吗?请建议。

2个回答

7

有没有DataStax的替代品?它似乎没有Windows版本。我主要在寻找DSE Search。 - Shilpa

1
截至Cassandra 3.4版本,使用SASI索引可以实现此功能。以下是可行的方法:
CREATE CUSTOM INDEX string_search_idx ON file(location) 
USING 'org.apache.cassandra.index.sasi.SASIIndex'
WITH OPTIONS = {
    'mode': 'CONTAINS',
    'analyzer_class': 'org.apache.cassandra.index.sasi.analyzer.StandardAnalyzer',
    'tokenization_enable_stemming': 'true',
    'tokenization_locale': 'en',
    'tokenization_skip_stop_words': 'true',
    'analyzed': 'true',
    'tokenization_normalize_lowercase': 'true'
};

这将搜索列“file”中所有“%abc%”查询。更多信息在这里

2
请注意,SASI索引几乎没有维护,因此在C* 4.0中它们将被默认禁用,如果要启用它们,则需要更改 cassandra.yaml... - Alex Ott

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