Cassandra CQL wildcard search

◇◆丶佛笑我妖孽 提交于 2019-12-23 12:32:43

问题


I have a table structure like

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

and following is the content in the table:

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/');

I want to list out all the ids matching the following criteria:

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

I know that like is not supported in CQL, can anyone please suggest the approach should I take for these kind of wildcard search queries. Please suggest.


回答1:


DataStax Enterprise adds full text search to Cassandra: http://www.datastax.com/docs/datastax_enterprise3.1/solutions/search_index




回答2:


As of Cassandra 3.4, this is possible with SASI indexes. This should work:

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'
};

This shall search for all "%abc%" queries on the column "file". More information here.



来源:https://stackoverflow.com/questions/18444567/cassandra-cql-wildcard-search

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!