Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra CQL wildcard search

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.

like image 693
Dawood Avatar asked Feb 15 '23 11:02

Dawood


2 Answers

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

like image 152
jbellis Avatar answered Feb 23 '23 12:02

jbellis


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.

like image 20
Fabulous Avatar answered Feb 23 '23 12:02

Fabulous