初始化与索引:
```
CREATE TABLE docs (
id bigserial PRIMARY KEY,
title text NOT NULL,
body text NOT NULL
);
CREATE INDEX idx_docs_search ON docs USING GIN (to_tsvector('english', title || ' ' || body));
```
查询(标准与简单词法):
```
SET default_text_search_config = 'english';
SELECT id, title FROM docs
WHERE to_tsvector(title || ' ' || body) @@ to_tsquery('cloud & native');
SELECT id, title FROM docs
WHERE to_tsvector(title || ' ' || body) @@ plainto_tsquery('cloud native');
```

发表评论 取消回复