CREATE TABLE doc_articles (
id INT,
title STRING,
body STRING,
INDEX idx_body (body) USING INVERTED PROPERTIES("parser" = "unicode")
);
INSERT INTO doc_articles VALUES
(1, 'Intro to SQL', 'SQL is a language for relational databases'),
(2, 'Python Basics', 'Python is easy to learn and widely used'),
(3, 'Cloud Storage', 'Object storage scales automatically in the cloud'),
(4, 'SQL and Python', 'Combine SQL queries with Python for data analysis');
BUILD INDEX idx_body ON doc_articles;
场景一:单关键词匹配
SELECT id, title
FROM doc_articles
WHERE MULTI_MATCH(body, 'SQL');
+----+----------------+
| id | title |
+----+----------------+
| 1 | Intro to SQL |
| 4 | SQL and Python |
+----+----------------+
场景二:多关键词匹配(任意一个命中即返回)
SELECT id, title
FROM doc_articles
WHERE MULTI_MATCH(body, 'Python', 'cloud');
+----+----------------+
| id | title |
+----+----------------+
| 2 | Python Basics |
| 3 | Cloud Storage |
| 4 | SQL and Python |
+----+----------------+