我正在我的 Cassandra 数据库中执行用户搜索系统。为此,我安装了 Cassandra Lucene Index来自 Stratio。 我可以通过用户名查找用户,但问题如下:
这是我的 Cassandra 用户表和 Lucene 索引:
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"}
}
}'
};
这是通过用户名查找用户的正常查询:
SELECT * FROM user WHERE lucene = '{filter: {type : "wildcard", field : "username", value : "*%s*"}}' LIMIT 15;
我的问题是:
我如何对返回的结果进行排序以确保任何经过验证的用户都在查询的前 15 个结果之间? (限制为 15)。
最佳答案
您可以使用此搜索:
SELECT * FROM user WHERE lucene = '{filter: {type:"boolean", must:[
{type : "wildcard", field : "username", value : "*%s*"},
{type : "match", field : "is_verified", value : true}
]}}' LIMIT 15;
关于java - Cassandra Lucene 索引 boolean 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35486016/