跳到主要内容

SCORE

引入或更新: v1.2.425

返回查询字符串的相关性。得分越高,数据的相关性越强。请注意,SCORE 函数只能与 QUERYMATCH 函数一起使用。

信息

Databend 的 SCORE 函数灵感来源于 Elasticsearch 的 SCORE

语法

SCORE()

示例

CREATE TABLE test(title STRING, body STRING);

CREATE INVERTED INDEX idx ON test(title, body);

INSERT INTO test VALUES
('The Importance of Reading', 'Reading is a crucial skill that opens up a world of knowledge and imagination.'),
('The Benefits of Exercise', 'Exercise is essential for maintaining a healthy lifestyle.'),
('The Power of Perseverance', 'Perseverance is the key to overcoming obstacles and achieving success.'),
('The Art of Communication', 'Effective communication is crucial in everyday life.'),
('The Impact of Technology on Society', 'Technology has revolutionized our society in countless ways.');

-- 检索 'title' 列包含关键词 'art' 且权重为 5,'body' 列包含关键词 'reading' 且权重为 1.2 的文档及其相关性得分
SELECT *, score() FROM test WHERE QUERY('title:art^5 body:reading^1.2');

┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ title │ body │ score()
├───────────────────────────┼────────────────────────────────────────────────────────────────────────────────┼───────────┤
│ The Importance of Reading │ Reading is a crucial skill that opens up a world of knowledge and imagination.1.3860708
│ The Art of Communication │ Effective communication is crucial in everyday life.7.1992116
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

-- 检索 'title' 列包含关键词 'reading' 且权重为 5,'body' 列包含关键词 'everyday' 且权重为 1.2 的文档及其相关性得分
SELECT *, score() FROM test WHERE MATCH('title^5, body^1.2', 'reading everyday');

┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ title │ body │ score()
├───────────────────────────┼────────────────────────────────────────────────────────────────────────────────┼───────────┤
│ The Importance of Reading │ Reading is a crucial skill that opens up a world of knowledge and imagination.8.585282
│ The Art of Communication │ Effective communication is crucial in everyday life.1.8575745
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
开始使用 Databend Cloud
低成本
快速分析
多种数据源
弹性扩展
注册