postgresqlfull-text-searchtrigram

Is there a way to do trigram similarly with whole phrases Postgres


right now with Postgres and pg_tgrm if I do any similarity(strict word, word, or just standard) it does it based on words so the query 'ruined by' will get a rank of 1 for the term 'ruined' but less for something like 'ruined by design' is there a way to do it on whole phrases. I tried using FTS but that has the problem where 'ruined by' won't match 'ruined' at all unless you use 'ruined | by' but using | makes order no longer matter is this something that is possible at all. thanks


Solution

  • Similarity search is always a heuristics; I don't think that there is a way to automatically “do the right thing”.

    If I read your question right, and you also want to find matches for the components of a phrase, perhaps you should use full text search an preprocess the search term to indicate explicitly what you want.

    Then ruined by would become

    to_tsquery('ruined | by | ruined <-> by')