Cassandra Lucene 索引布尔语法

Posted

技术标签:

【中文标题】Cassandra Lucene 索引布尔语法【英文标题】:Cassandra Lucene Index boolean syntax 【发布时间】:2016-02-18 15:46:13 【问题描述】:

我正在我的 Cassandra 数据库中执行用户搜索系统。为此,我从 Stratio 安装了Cassandra Lucene Index。 我可以通过用户名查找用户,但问题如下:

这是我的 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)。

【问题讨论】:

【参考方案1】:

你可以使用这个搜索:

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

【讨论】:

使用此语法,列出的用户经过验证。我想做的是首先获得经过验证的用户,然后是未经验证的用户。是否可以在一个查询中实现?或者我应该做两个查询?一个用于已验证,另一个用于未验证。 您想获得前 15 个经过验证的用户,然后是所有未验证的用户吗?或者只得到不超过 15 个满足由 is_verified 排序的通配符模式的结果? LIMIT 子句的目的是什么? 也许您需要添加一个排序子句以按“is_verified”对行进行排序: SELECT * FROM user WHERE lucene = ' filter: type : "wildcard", field : "username", value : "*%s*", sort: fields: [ field:"is_verified", reverse:true ] ' LIMIT 15;

以上是关于Cassandra Lucene 索引布尔语法的主要内容,如果未能解决你的问题,请参考以下文章

找不到自定义索引器类“com.stratio.cassandra.lucene.Index”

Cassandra 与 Stratio lucene 索引

选择带有stratio lucene索引的cassandra的排序查询,版本> 2.2

cassandra lucene 索引是不是适用于 vnode?说 num_tokens = 256

如何使用 Stratio Cassandra Lucene Index 进行小写前缀过滤

全文检索Lucene框架---查询索引