4

In my keyspace

posts = [
    #key
    'post1': {
        # columns and value
        'url': 'foobar.com/post1',
        'body': 'Currently has client support FOOBAR for the following programming languages..',
    },
    'post2': {
        'url': 'foobar.com/post2',
        'body': 'The table with the following table FOOBAR structure...',
    },
   #  ... ,
}

How to create a like query in Cassandra to get all posts that contains the word 'FOOBAR'? In SQL is SELECT * FROM POST WHERE BODY LIKE '%FOOBAR%', but in Cassandra?

Dan D.
  • 73,243
  • 15
  • 104
  • 123
Bruce
  • 1,145
  • 1
  • 10
  • 16

3 Answers3

5

The only way to do this efficiently is to use a full-text search engine like https://github.com/tjake/Solandra (Solr-on-cassandra). Of course you can roll your own using the same techniques manually, but usually this is not called for.

Note that this is true for SQL databases too: they will translate %FOO% to a table scan, unless you use a FTS extension like postgresql's tsearch2.

jbellis
  • 19,347
  • 2
  • 38
  • 47
  • If your Cassandra cluster is big enough, doing table scans might be reasonably quick, because each node only has to scan a fraction of the data. I'm not sure if there is a way of doing this natively though. – minimalis May 18 '11 at 18:12
0

Cassandra 3.4 added support for LIKE in CSQL. So finally it is available natively.

bdutta74
  • 2,798
  • 3
  • 31
  • 54
0

You might create another column family where the keys are the domains, and the values are the keys in your original column family. That way you could refer to records within a specific domain directly.

bitcycle
  • 7,632
  • 16
  • 70
  • 121
  • Well, for me create another column family it's very complicated. I think that cassandra need to improve this issue. In MongoDB it's very easy. – Bruce Apr 28 '11 at 11:59