You can do it in Postgres and donβt need Lucene.
You can quote phrases in tsquery or tsvector as shown below. You can add :* after tsquery to search by prefixes:
select '''new york city'''::tsvector @@ '''new yo'':*'::tsquery, --true '''new york times'''::tsvector @@ '''new yo'':*'::tsquery, --true '''new york'''::tsvector @@ '''new yo'':*'::tsquery, --true '''new'''::tsvector @@ '''new yo'':*'::tsquery, --false 'new'::tsvector @@ '''new yo'':*'::tsquery, --false 'new york'::tsvector @@ '''new yo'':*'::tsquery --false
The main problem is that to_tsvector() and [plain]to_tsquery() will separate your quotes. You can write your own versions that do not (this is not so difficult), or after processing after them build your own term n-grams.
Extra single quotes are just shoots. select $$ i heart 'new york city' $$::tsvector; equivalent to.
Neil McGuigan
source share