【问题标题】:cassandra lucene - how to score a field highercassandra lucene - 如何获得更高的分数
【发布时间】:2017-02-21 13:29:52
【问题描述】:

我希望表中的某个字段得分高于另一个字段。 例如,我有两列名称和姓氏。如果我搜索“Hans”,我希望名称中的内容得分更高。 如何使用 official examples 中的 cql 语句执行此操作。

问候 图吉

【问题讨论】:

    标签: java cassandra lucene stratio cassandra-lucene-index


    【解决方案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}
            ]
        }
    }');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 2011-04-05
      • 1970-01-01
      相关资源
      最近更新 更多