初始化与索引:

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');

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部