我希望我的表中的字段得分高于另一个字段。 例如,我有两列名称和姓氏。如果我搜索" Hans"我希望名字内容得分更高。 如何使用official examples中的cql语句执行此操作。
问候 Tugi
答案 0 :(得分:1)
如doc所述,每种搜索类型都有提升选项,允许用户为每个不同的查询设置权重。
您的用例应如下所示:
CREATE KEYSPACE test with replication = {
'class' : 'SimpleStrategy', 'replication_factor' : '1'
};
CREATE TABLE test.users (
id bigint PRIMARY KEY,
name text,
surname text
);
CREATE CUSTOM INDEX test_users_idx ON test.users()
USING 'com.stratio.cassandra.lucene.Index'
WITH OPTIONS = {
'refresh_seconds': '1',
'schema': '{
fields: {
name: {type: "string"},
surname:{type:"string"}
}
}'
};
INSERT INTO test.users(id, name, surname) VALUES (1, 'Hans', 'Albers');
INSERT INTO test.users(id, name, surname) VALUES (2, 'Quintina', 'Koch');
INSERT INTO test.users(id, name, surname) VALUES (3, 'Orlando', 'Schwarz');
INSERT INTO test.users(id, name, surname) VALUES (4, 'Federico', 'Hans');
INSERT INTO test.users(id, name, surname) VALUES (5, 'Berenice', 'Schwarz');
INSERT INTO test.users(id, name, surname) VALUES (6, 'Zaida', 'Koch');
SELECT * FROM test.users WHERE expr(test_users_idx,'{
query: {
type : "boolean",
should : [
{type: "match", field: "name", value: "Hans", boost: 1.5},
{type: "match", field: "surname", value: "Hans", boost: 1.0}
]
}
}');