Sub string search like "LIKE" keyword in SQL - cassandra

I'm using apache-cassandra 1.2 (CLI version), I want to search a sub string in columns, just like we search in SQL using like or where clause.
Can anyone tell me how to search a sub string in rows?
I only want to do it in CLI, please don's suggest CQL cassandra.

Perhaps if cassandra supports indexing on collection columns in near future, it will be very much possible. In that case we can defragment the text into pieces and easily perform the like operation.
But for now the best you can do is prefix, if your order is alphabetical. For example I have a CF with comparator UTF8Type, and then I can do slice query and bring all columns that start with the prefix, and end with the prefix where you replace the last char with the next one in order (i.e. "aaa"-"aab")

Related

How to select specific values from a column in Presto sql?

I would like to exclude the (Non-mall) from stall_type column so that I get only High End, Mid End, and Low End as values in my query output. Does anyone know if this can be done in presto sql?
You can do this by replacing the text you want to exclude by an empty string:
select replace("stall type", '(Non-mall)') from ...
more details on the use of the replace function can be found on the presto docs

Can we specifiy order of columns to search in solr?

Can we specify order of columns to be searched in solr?
For example my search string is : "Test"
Then my result should contain all rows matching column1 and then all rows matching column 2... Similar to union query in SQL.
I tried with custom search handler which will fire multiple requests to solr and then append to get final result.
But is there any other way to get this type of search using SOLR?
I am using solr-5.4.1.
Thanks
You could use eDismax and match on both fields (I assume you mean columns by that). Then, use boosting to prioritize the matches in the first field to rank higher.
As an easy example, you would search against field1^10 field2, where ^10 is the boost factor. If that works but is not perfect, you can look into the documentation for other methods to apply boost.

Is there a "SOUNDS LIKE" function in CQL like the one in MySQL?

When I used MySQL I was able to query the database with a statement like SELECT * FROM table WHERE col LIKE "%attribute%";
Is there a way I can do that in Cassandra?
Cassandra CQL doesn't have a LIKE operator. It has limited filtering capabilities so you are restricted to equals, range queries on some numeric fields, and the IN operator which is similar to equals.
The most common approach to doing searches of Cassandra data seems to be pairing Cassandra with Apache Solr. Or you can pair it with Apache Spark which has more filtering capabilities than CQL.
If your col is a collection of data like set, list, map. You could use CONTAINS, to perform search.
Sample:
SELECT id, description FROM products WHERE features CONTAINS '32-inch';
For map data type,
SELECT id, description FROM products WHERE features CONTAINS KEY 'refresh-rate';
References:
http://www.datastax.com/dev/blog/cql-in-2-1
CQL LIKE statements now available are in Scylla Open Source 3.2 RC1, the release candidate for Scylla, a CQL-compatible database. We'd love feedback before release. Here's the details:
CQL: LIKE Operation #4477
The new CQL LIKE keyword allows matching any column to a search pattern, using % as a wildcard. Note that LIKE only works with ALLOW FILTERING.
LIKE Syntax support:
'_' matches any single character
'%' matches any substring (including an empty string)
'\' escapes the next pattern character, so it matches verbatim
any other pattern character matches itself
an empty pattern matches empty text fields
For example:
INSERT INTO t (id, name) VALUES (17, ‘Mircevski’)
SELECT * FROM t where name LIKE 'Mirc%' allow filtering
Source: [RELEASE] Scylla 3.2 RC1 2

How is it possible to do wildcard search on apache cassandra at the beginning of the string like '%string' as we do in Sql?

i need to do wildcard search like this on apache cassandra, SELECT * FROM table_name where col_name like "string%";
I know there is no wildcard support like this in Cassandra. I have to maintain some indices for this purpose. I have read through these links which were very much helpful.
Cassandra CQL 3 - Prefix Select
is there any trick to do wildcards search on apache cassandra?
I could design data model which allows wild cards at the end of the string and where I can get result like -->
SELECT * FROM table_name where col_name like 'str%'; by maintaning an index and with normal range queries from str:sts. But I want wild cards at the beginning of the string like '%str'.
Is there any possible way to do this? Any help will be appreciated.
Thanks in advance.
Cassandra is not a right tool to do any searches beyond the primary keys. You should better look for something like Solr for this type of job.
Of course you can create a table with all triplet combinations of letters and numbers as a partition key, and then reference to the partitioning or primary keys of the table which contains the data.
For example you will have rows with the partition key "aaa", "aab", "aac", ..., "ZZZ", etc, and the rest of the columns will tell you the values of the primary key of the table_name where this triplet exists in the col_name. Then you will have to update this table every time you modify the data in that col_name of the table_name.
But I don't think it will be a very efficient use of Cassandra.

Search technique in Mysql using only sql not pl/sql

Here i want to search from one table's column to another table's column.
so if the string is "Introduction To Php" so this string will compare to another table all data for particular column but the new things is order of words may be different in table.
i.e : it can be like "Php introduction to" , "to indtroduction php" and so on... means combination of different words and there place in the string should be compare with
If you have any idea related this , please answer for this question.
Thanks a lot in advance..
You may be interested in full-text search functions in MySQL http://dev.mysql.com/doc/refman/5.0/en/fulltext-natural-language.html

Resources