Full-Text Search Functions
This section provides reference information for the full-text search functions in Databend. These functions enable powerful text search capabilities similar to those found in dedicated search engines.
信息
Databend's full-text search functions are inspired by Elasticsearch Full-Text Search Functions.
Search Functions
Function | Description | Example |
---|---|---|
MATCH | Searches for documents containing specified keywords in selected columns | MATCH('title, body', 'technology') |
QUERY | Searches for documents satisfying a specified query expression with advanced syntax | QUERY('title:technology AND society') |
SCORE | Returns the relevance score of search results when used with MATCH or QUERY | SELECT title, SCORE() FROM articles WHERE MATCH('title', 'technology') |
Usage Examples
Basic Text Search
-- Search for documents with 'technology' in title or body columns
SELECT * FROM articles
WHERE MATCH('title, body', 'technology');
Advanced Query Expressions
-- Search for documents with 'technology' in title and 'impact' in body
SELECT * FROM articles
WHERE QUERY('title:technology AND body:impact');
Relevance Scoring
-- Search with relevance scoring and sorting by relevance
SELECT title, body, SCORE()
FROM articles
WHERE MATCH('title^2, body', 'technology')
ORDER BY SCORE() DESC;
Before using these functions, you need to create an inverted index on the columns you want to search:
CREATE INVERTED INDEX idx ON articles(title, body);