@@ -3,9 +3,9 @@ title: MATCH
33---
44import FunctionDescription from '@site/src /components/FunctionDescription';
55
6- <FunctionDescription description =" ๅผๅ
ฅๆๆดๆฐ : v1.2.619" />
6+ <FunctionDescription description =" Introduced or updated : v1.2.619" />
77
8- ๆ็ดขๅ
ๅซๆๅฎๅ
ณ้ฎ่ฏ็ๆๆกฃใ่ฏทๆณจๆ๏ผ MATCH ๅฝๆฐๅช่ฝๅจ WHERE ๅญๅฅไธญไฝฟ็จ ใ
8+ ` MATCH ` ็จไบๅจๆๅฎๅไธญๆ็ดขๅ
ๅซๆๆไพๅ
ณ้ฎๅญ็่กใ่ฏฅๅฝๆฐๅช่ฝๅบ็ฐๅจ ` WHERE ` ๅญๅฅไธญ ใ
99
1010::: info
1111Databend ็ MATCH ๅฝๆฐ็ตๆๆฅๆบไบ Elasticsearch ็ [ MATCH] ( https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-functions-search.html#sql-functions-search-match ) ใ
@@ -14,83 +14,62 @@ Databend ็ MATCH ๅฝๆฐ็ตๆๆฅๆบไบ Elasticsearch ็ [MATCH](https://www.e
1414## ่ฏญๆณ
1515
1616``` sql
17- MATCH( ' <columns>' , ' <keywords>' [, ' <options>' ] )
17+ MATCH(' <columns>' , ' <keywords>' [, ' <options>' ])
1818```
1919
20- | ๅๆฐ | ๆ่ฟฐ |
21- | --------------| -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
22- | ` <columns> ` | ่กจไธญ่ฆๆ็ดขๆๅฎๅ
ณ้ฎ่ฏ็ๅๅๅ่กจ๏ผไปฅ้ๅทๅ้๏ผๅฏ้ๅฐไฝฟ็จ (^) ่ฏญๆณ่ฟ่กๅ ๆ๏ผๅ
่ฎธไธบๆฏไธชๅๅ้
ไธๅ็ๆ้๏ผๅฝฑๅๆฏไธชๅๅจๆ็ดขไธญ็้่ฆๆงใ |
23- | ` <keywords> ` | ่ฆๅน้
่กจไธญๆๅฎๅ็ๅ
ณ้ฎ่ฏใๆญคๅๆฐ่ฟๅฏ็จไบๅ็ผๅน้
๏ผๆ็ดข่ฏๅ่ทๆๅท (* ) ๅฏไปฅๅน้
ไปปๆๆฐ้็ๅญ็ฌฆๆ่ฏใ |
24- | ` <options> ` | ไธ็ปไปฅๅๅท ` ; ` ๅ้็้
็ฝฎ้้กน๏ผ็จไบ่ชๅฎไนๆ็ดข่กไธบใ่ฏฆๆ
่งไธ่กจใ |
20+ - ` <columns> ` ๏ผ่ฆๆ็ดข็ๅ๏ผไปฅ้ๅทๅ้ใๅฏ้ๅ ` ^<boost> ` ไธบๆๅ่ตไบๆด้ซๆ้ใ
21+ - ` <keywords> ` ๏ผ่ฆๆ็ดข็่ฏๆกใๅฏ้ๅ ` * ` ่ฟ่กๅ็ผๅน้
๏ผไพๅฆ ` rust* ` ใ
22+ - ` <options> ` ๏ผๅฏ้็ใไปฅๅๅทๅ้็ ` key=value ` ๅฏนๅ่กจ๏ผ็จไบๅพฎ่ฐๆ็ดขใ
2523
26- | ้้กน | ๆ่ฟฐ | ็คบไพ | ่งฃ้ |
27- | -----------| -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ------------------------------------------------------------------------------------------------------| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
28- | fuzziness | ๅ
่ฎธๅน้
ๆๅฎ Levenshtein ่ท็ฆปๅ
็่ฏ้กนใ` fuzziness ` ๅฏไปฅ่ฎพ็ฝฎไธบ 1 ๆ 2ใ | SELECT id, score(), content FROM t WHERE match(content, 'box', 'fuzziness=1'); | ๅฝๅน้
ๆฅ่ฏข่ฏ "box" ๆถ๏ผ` fuzziness=1 ` ๅ
่ฎธๅน้
"fox" ็ญ่ฏ้กน๏ผๅ ไธบ "box" ๅ "fox" ็ Levenshtein ่ท็ฆปไธบ 1ใ |
29- | operator | ๆๅฎๅคไธชๆฅ่ฏข่ฏ้กน็็ปๅๆนๅผใๅฏไปฅๆฏ OR๏ผ้ป่ฎค๏ผๆ ANDใOR ่ฟๅๅ
ๅซไปปๆๆฅ่ฏข่ฏ้กน็็ปๆ๏ผ่ AND ่ฟๅๅ
ๅซๆๆๆฅ่ฏข่ฏ้กน็็ปๆใ | SELECT id, score(), content FROM t WHERE match(content, 'action works', 'fuzziness=1;operator=AND'); | ไฝฟ็จ ` operator=AND ` ๏ผๆฅ่ฏข่ฆๆฑ็ปๆไธญๅๆถๅ
ๅซ "action" ๅ "works"ใ็ฑไบ ` fuzziness=1 ` ๏ผๅฎๅน้
"Actions" ๅ "words" ็ญ่ฏ้กน๏ผๅ ๆญค่ฟๅ "Actions speak louder than words"ใ |
30- | lenient | ๆงๅถๅฝๆฅ่ฏขๆๆฌๆ ๆๆถๆฏๅฆๆฅๅ้่ฏฏใ้ป่ฎคไธบ ` false ` ใๅฆๆ่ฎพ็ฝฎไธบ ` true ` ๏ผๅไธๆฅๅ้่ฏฏ๏ผๅฆๆๆฅ่ฏขๆๆฌๆ ๆ๏ผๅ่ฟๅ็ฉบ็ปๆ้ใ | SELECT id, score(), content FROM t WHERE match(content, '()', 'lenient=true'); | ๅฆๆๆฅ่ฏขๆๆฌ ` () ` ๆ ๆ๏ผ่ฎพ็ฝฎ ` lenient=true ` ไผ้ปๆญขๆๅบ้่ฏฏ๏ผๅนถ่ฟๅ็ฉบ็ปๆ้ใ |
24+ ## ้้กน
25+
26+ | ้้กน | ๅผ | ๆ่ฟฐ | ็คบไพ |
27+ | --------| --------| -------------| ---------|
28+ | ` fuzziness ` | ` 1 ` ๆ ` 2 ` | ๅน้
ๅจๆๅฎ Levenshtein distance๏ผ่ฑๆๆฏๅฆ่ท็ฆป๏ผๅ
็ๅ
ณ้ฎๅญใ | ` MATCH('summary, tags', 'pedestrain', 'fuzziness=1') ` ๅน้
ๅ
ๅซๆญฃ็กฎๆผๅ ` pedestrian ` ็่กใ |
29+ | ` operator ` | ` OR ` ๏ผ้ป่ฎค๏ผๆ ` AND ` | ๅจๆชๆๅฎๅธๅฐๆไฝ็ฌฆๆถ๏ผๆงๅถๅคไธชๅ
ณ้ฎๅญ็็ปๅๆนๅผใ | ` MATCH('summary, tags', 'traffic light red', 'operator=AND') ` ่ฆๆฑๅๆถๅ
ๅซ่ฟไธคไธช่ฏใ |
30+ | ` lenient ` | ` true ` ๆ ` false ` | ไธบ ` true ` ๆถ๏ผๆๅถ่งฃๆ้่ฏฏๅนถ่ฟๅ็ฉบ็ปๆ้ใ | ` MATCH('summary, tags', '()', 'lenient=true') ` ่ฟๅ็ฉบ่ก่้ๆฅ้ใ |
3131
3232## ็คบไพ
3333
34+ ๅจ่ฎธๅค AI Pipeline๏ผๆตๆฐด็บฟ๏ผไธญ๏ผไฝ ๅฏ่ฝไผๅจ ` VARIANT ` ๅไธญๆ่ท็ปๆๅๅ
ๆฐๆฎ๏ผๅๆถไธบไบบ็ฑปๅฏ่ฏปๆ่ฆๅปบ็ซ็ดขๅผไปฅไพฟๆ็ดขใไปฅไธ็คบไพๅญๅจไบไป JSON ่ด่ฝฝไธญๆๅ็่ก่ฝฆ่ฎฐๅฝไปชๅธงๆ่ฆๅๆ ็ญพใ
35+
36+ ### ็คบไพ๏ผๆๅปบๅฏๆ็ดข็ๆ่ฆ
37+
38+ ``` sql
39+ CREATE OR REPLACE TABLE frame_notes (
40+ id INT ,
41+ camera STRING,
42+ summary STRING,
43+ tags STRING,
44+ INVERTED INDEX idx_notes (summary, tags)
45+ );
46+
47+ INSERT INTO frame_notes VALUES
48+ (1 , ' dashcam_front' ,
49+ ' Green light at Market & 5th with pedestrian entering the crosswalk' ,
50+ ' downtown commute green-light pedestrian' ),
51+ (2 , ' dashcam_front' ,
52+ ' Vehicle stopped at Mission & 6th red traffic light with cyclist ahead' ,
53+ ' stop urban red-light cyclist' ),
54+ (3 , ' dashcam_front' ,
55+ ' School zone caution sign in SOMA with pedestrian waiting near crosswalk' ,
56+ ' school-zone caution pedestrian' );
57+ ```
58+
59+ ### ็คบไพ๏ผๅธๅฐ AND
60+
61+ ``` sql
62+ SELECT id, summary
63+ FROM frame_notes
64+ WHERE MATCH(' summary, tags' , ' traffic light red' , ' operator=AND' );
65+ -- ่ฟๅ id 2
66+ ```
67+
68+ ### ็คบไพ๏ผๆจก็ณๅน้
69+
3470``` sql
35- CREATE TABLE test (title STRING, body STRING);
36-
37- CREATE INVERTED INDEX idx ON test(title, body);
38-
39- INSERT INTO test VALUES
40- (' The Importance of Reading' , ' Reading is a crucial skill that opens up a world of knowledge and imagination.' ),
41- (' The Benefits of Exercise' , ' Exercise is essential for maintaining a healthy lifestyle.' ),
42- (' The Power of Perseverance' , ' Perseverance is the key to overcoming obstacles and achieving success.' ),
43- (' The Art of Communication' , ' Effective communication is crucial in everyday life.' ),
44- (' The Impact of Technology on Society' , ' Technology has revolutionized our society in countless ways.' );
45-
46- -- ๆฃ็ดข 'title' ๅๅน้
'art power' ็ๆๆกฃ
47- SELECT * FROM test WHERE MATCH(' title' , ' art power' );
48-
49- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
50- โ title โ body โ
51- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
52- โ The Power of Perseverance โ Perseverance is the key to overcoming obstacles and achieving success. โ
53- โ The Art of Communication โ Effective communication is crucial in everyday life. โ
54- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
55-
56- -- ๆฃ็ดข 'title' ๅๅ
ๅซไปฅ 'The' ๅผๅคดๅ่ทไปปๆๅญ็ฌฆ็ๅผ็ๆๆกฃ
57- SELECT * FROM test WHERE MATCH(' title' , ' The*' )
58-
59- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
60- โ title โ body โ
61- โ Nullable(String) โ Nullable(String) โ
62- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
63- โ The Importance of Reading โ Reading is a crucial skill that opens up a world of knowledge and imagination. โ
64- โ The Benefits of Exercise โ Exercise is essential for maintaining a healthy lifestyle. โ
65- โ The Power of Perseverance โ Perseverance is the key to overcoming obstacles and achieving success. โ
66- โ The Art of Communication โ Effective communication is crucial in everyday life. โ
67- โ The Impact of Technology on Society โ Technology has revolutionized our society in countless ways. โ
68- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
69-
70- -- ๆฃ็ดข 'title' ๆ 'body' ๅๅน้
'knowledge technology' ็ๆๆกฃ
71- SELECT * , score() FROM test WHERE MATCH(' title, body' , ' knowledge technology' );
72-
73- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
74- โ title โ body โ score() โ
75- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโค
76- โ The Importance of Reading โ Reading is a crucial skill that opens up a world of knowledge and imagination. โ 1 .1550591 โ
77- โ The Impact of Technology on Society โ Technology has revolutionized our society in countless ways. โ 2 .6830134 โ
78- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
79-
80- -- ๆฃ็ดข 'title' ๆ 'body' ๅๅน้
'knowledge technology' ็ๆๆกฃ๏ผๅนถๅฏนไธคๅ่ฟ่กๅ ๆ
81- SELECT * , score() FROM test WHERE MATCH(' title^5, body^1.2' , ' knowledge technology' );
82-
83- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
84- โ title โ body โ score() โ
85- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโค
86- โ The Importance of Reading โ Reading is a crucial skill that opens up a world of knowledge and imagination. โ 1 .3860708 โ
87- โ The Impact of Technology on Society โ Technology has revolutionized our society in countless ways. โ 7 .8053584 โ
88- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
89-
90- -- ๆฃ็ดข 'body' ๅๅ
ๅซ "knowledge" ๅ "imagination"๏ผๅ
่ฎธ่ฝปๅพฎๆผๅ้่ฏฏ๏ผ็ๆๆกฃ
91- SELECT * FROM test WHERE MATCH(' body' , ' knowledg imaginatio' , ' fuzziness = 1; operator = AND' );
92-
93- - [ RECORD 1 ]-- ---------------------------------
94- title: The Importance of Reading
95- body: Reading is a crucial skill that opens up a world of knowledge and imagination.
71+ SELECT id, summary
72+ FROM frame_notes
73+ WHERE MATCH(' summary^2, tags' , ' pedestrain' , ' fuzziness=1' );
74+ -- ่ฟๅ id 1 ๅ 3
9675```
0 commit comments