|
| 1 | +CREATE TABLE documents ( |
| 2 | + en text not null, |
| 3 | + score float not null, |
| 4 | + textsearch_index_en_col tsvector |
| 5 | +); |
| 6 | +INSERT INTO documents VALUES ('the pet cat is in the shed', 56, to_tsvector('english', 'the pet cat is in the shed')); |
| 7 | +CREATE INDEX textsearch_index_en ON documents |
| 8 | + USING rum (textsearch_index_en_col rum_tsvector_addon_ops, score) |
| 9 | + WITH (attach = 'score', to = 'textsearch_index_en_col'); |
| 10 | +SET enable_seqscan=off; |
| 11 | +-- should be 1 row |
| 12 | +SELECT * FROM documents WHERE textsearch_index_en_col @@ ('pet'::tsquery <-> ('dog'::tsquery || 'cat'::tsquery)); |
| 13 | + en | score | textsearch_index_en_col |
| 14 | +----------------------------+-------+-------------------------- |
| 15 | + the pet cat is in the shed | 56 | 'cat':3 'pet':2 'shed':7 |
| 16 | +(1 row) |
| 17 | + |
| 18 | +SET enable_seqscan=on; |
| 19 | +-- 1 row |
| 20 | +SELECT * FROM documents WHERE textsearch_index_en_col @@ ('pet'::tsquery <-> ('dog'::tsquery || 'cat'::tsquery)); |
| 21 | + en | score | textsearch_index_en_col |
| 22 | +----------------------------+-------+-------------------------- |
| 23 | + the pet cat is in the shed | 56 | 'cat':3 'pet':2 'shed':7 |
| 24 | +(1 row) |
| 25 | + |
| 26 | +DROP TABLE documents; |