Search code examples
javacassandralucenestratiocassandra-lucene-index

Cassandra Lucene Index boolean syntax


I am performing a user search system in my Cassandra database. For that purpose I installed Cassandra Lucene Index from Stratio. I am able to lookup users by username, but the problem is as follows:

This is my Cassandra users table and the Lucene Index:

CREATE TABLE user (
    username text PRIMARY KEY,
    email text,
    password text,
    is_verified boolean,
    lucene text
);
CREATE CUSTOM INDEX search_main ON user (lucene) USING 'com.stratio.cassandra.lucene.Index' WITH OPTIONS = {
    'refresh_seconds': '3600',
    'schema': '{
        fields : {
            username : {type : "string"},
            is_verified : {type : "boolean"}
        }
    }'
};

This is a normal query performed to Lookup a user by username:

SELECT * FROM user WHERE lucene = '{filter: {type : "wildcard", field : "username", value : "*%s*"}}' LIMIT 15;

My Question is:

How could I sort the returned results to ensure that any verified users are between the first 15 results in the query? (Limit is 15).


Solution

  • You can use this search:

    SELECT * FROM user WHERE lucene = '{filter: {type:"boolean", must:[
        {type : "wildcard", field : "username", value : "*%s*"},
        {type : "match", field : "is_verified", value : true}
    ]}}' LIMIT 15;