【发布时间】:2016-01-22 04:58:51
【问题描述】:
由于我经常遇到下面描述的这个问题,我想改变但没有更好的选择。
我有 2 个查询应该返回相同的结果。但是第二个查询返回的结果要少得多,有时甚至没有结果。这是 2 个查询:
SELECT * FROM statistics WHERE source = 'toutiao' AND timespan = '3';
SELECT * FROM statistics WHERE source = 'toutiao' AND timespan = '3' AND text = '{ sort: {fields: [{field: "speed", reverse: true}]}}';.
我使用这个自定义的 cassandra 索引 https://github.com/Stratio/cassandra-lucene-index。
编辑:
我使用 Cassandra 2.2.4.1 cassandra-lucene-index 2.2.4
'text' 是我建立索引的表列。
我的索引创建查询是:
CREATE CUSTOM INDEX statistics_text_idx ON toutiao.statistics (text) USING 'com.stratio.cassandra.lucene.Index' WITH OPTIONS = {'schema': '{
fields : {
title: {
type : "text", analyzer : "english"},
category : {type:"string"},
genre : {type:"string"},
speed : {type : "integer",sorted : true}
}
}', '
refresh_seconds': '1'};
建表查询:
DROP TABLE IF EXISTS statistics;
CREATE TABLE statistics (
source text,
timespan text,
id text,
title text,
thumbnail text,
url text,
text text,
created_at timestamp,
category text,
category2 text,
genre text,
author text,
reads int,
likes int,
comments int,
shares int,
speed int,
PRIMARY KEY (source, timespan, id)
)WITH CLUSTERING ORDER BY (timespan DESC) AND caching = '{"keys":"ALL", "rows_per_partition":"ALL"}';
这是我的数据插入程序:
cluster = Cluster(['localhost'])
session_statis = cluster.connect(keyspace)
session_statis.execute('INSERT INTO tablename(col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11,col12,col13,col14,col15) values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)', (value1,value2,value3,value4,value5,value6,value7,value8,value9,value10,value11,value12,value13,value14,value15))
感谢您的帮助!
【问题讨论】:
-
这里回答的问题(替代 Stratio 索引):stackoverflow.com/questions/34938494/…