MATCH (Lakehouse v1)
지정한 키워드가 포함된 문서를 검색합니다. 참고: MATCH 함수는 WHERE 절에서만 사용할 수 있습니다.
PlaidCloud Lakehouse의 MATCH 함수는 Elasticsearch의 MATCH에서 착안했습니다.
SQL Syntax
섹션 제목: “SQL Syntax”MATCH( '<columns>', '<keywords>'[, '<options>'] )| 매개변수 | 설명 |
|---|---|
<columns> |
지정한 키워드를 검색할 테이블의 열 이름을 쉼표로 구분한 목록입니다. 구문 (^)을 사용해 가중치를 선택적으로 지정할 수 있으며, 열마다 다른 가중치를 부여해 검색에서 각 열의 중요도에 영향을 줄 수 있습니다. |
<keywords> |
테이블의 지정한 열과 대조할 키워드입니다. 이 매개변수는 접미사 일치에도 사용할 수 있으며, 검색어 뒤에 별표(*)를 붙이면 임의 개수의 문자나 단어와 일치합니다. |
<options> |
검색 동작을 사용자 지정하는 구성 옵션 집합이며, 세미콜론 ;으로 구분합니다. 자세한 내용은 아래 표를 참조하십시오. |
| 옵션 | 설명 | 예시 | 설명 |
|---|---|---|---|
| fuzziness | 지정한 레벤슈타인 거리 이내의 용어와 일치하도록 허용합니다. fuzziness는 1 또는 2로 설정할 수 있습니다. |
SELECT id, score(), content FROM t WHERE match(content, ‘box’, ‘fuzziness=1’); | 검색어 “box”와 일치시킬 때 fuzziness=1이면 “fox” 같은 용어도 일치합니다. “box”와 “fox”의 레벤슈타인 거리가 1이기 때문입니다. |
| 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”가 반환됩니다. |
| lenient | 검색 텍스트가 올바르지 않을 때 오류를 보고할지 여부를 제어합니다. 기본값은 false입니다. true로 설정하면 오류를 보고하지 않으며, 검색 텍스트가 올바르지 않을 경우 빈 결과 집합을 반환합니다. |
SELECT id, score(), content FROM t WHERE match(content, ‘()’, ‘lenient=true’); | 검색 텍스트 ()가 올바르지 않더라도 lenient=true로 설정하면 오류가 발생하지 않고 대신 빈 결과 집합을 반환합니다. |
SQL Examples
섹션 제목: “SQL Examples”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.');
-- Retrieve documents where the 'title' column matches 'art power'SELECT * FROM test WHERE MATCH('title', 'art power');
┌────────────────────────────────────────────────────────────────────────────────────────────────────┐│ title │ body │├───────────────────────────┼────────────────────────────────────────────────────────────────────────┤│ 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. │└────────────────────────────────────────────────────────────────────────────────────────────────────┘
-- Retrieve documents where the 'title' column contains values that start with 'The' followed by any charactersSELECT * FROM test WHERE MATCH('title', 'The*')
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐│ title │ body ││ Nullable(String) │ Nullable(String) │├─────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────┤│ 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. │└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
-- Retrieve documents where either the 'title' or 'body' column matches 'knowledge technology'SELECT *, score() FROM test WHERE MATCH('title, body', 'knowledge technology');
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐│ title │ body │ score() │├─────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────┼───────────┤│ The Importance of Reading │ Reading is a crucial skill that opens up a world of knowledge and imagination. │ 1.1550591 ││ The Impact of Technology on Society │ Technology has revolutionized our society in countless ways. │ 2.6830134 │└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
-- Retrieve documents where either the 'title' or 'body' column matches 'knowledge technology', with weighted importance on both columnsSELECT *, score() FROM test WHERE MATCH('title^5, body^1.2', 'knowledge technology');
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐│ title │ body │ score() │├─────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────┼───────────┤│ The Importance of Reading │ Reading is a crucial skill that opens up a world of knowledge and imagination. │ 1.3860708 ││ The Impact of Technology on Society │ Technology has revolutionized our society in countless ways. │ 7.8053584 │└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
-- Retrieve documents where the 'body' column contains both "knowledge" and "imagination" (allowing for minor typos).SELECT * FROM test WHERE MATCH('body', 'knowledg imaginatio', 'fuzziness = 1; operator = AND');
-[ RECORD 1 ]-----------------------------------title: The Importance of Reading body: Reading is a crucial skill that opens up a world of knowledge and imagination.