Let\'s say you have a postgres 8.3 table as follows:
CREATE TABLE t1 (body text, body_vector tsvector);
I want to be able to search it for phras
If you want exact phrase matching, that's the way to do it. You can also try WHERE body_vector @@ plainto_tsquery('w1 w2'), and then order it by ranking. (the point being that the hits where the words are right next to each other should end up on top)
Update: PostgreSQL 9.6 text search supports phrases
select
*
from (values
('i heart new york'),
('i hate york new')
) docs(body)
where
to_tsvector(body) @@ phraseto_tsquery('new york')
(1 row retrieved)
or by distance between words:
-- a distance of exactly 2 "hops" between "quick" and "fox"
select
*
from (values
('the quick brown fox'),
('quick brown cute fox')
) docs(body)
where
to_tsvector(body) @@ to_tsquery('quick <2> fox')
(1 row retrieved)