If I have strings/phrases like this stored in the database:
- What are Q-type Operations?
- Programmer’s Guide
- A.B.C’s of Coding
Is there a way to pass a query parameter in like "Programmers" or "abc" or "q-type" and have it find "Programmer's", "A.B.C" and "Q-type"?
tsvector
Use the
tsvectortype, which is part of the PostgreSQL text-search feature.You can use familiar operators on tsvectors as well:
From tsvector documentation:
If you also want to do language-specific normalization, like removing common words (‘the’, ‘a’, etc) and multiplies, use the
to_tsvectorfunction. It also assigns weights to different words for text search:Full-blown text search
Obviously doing this for every row in a query will be expensive — so you should store the tsvector in a separate column and use ts_query() to search for it. This also allows you to create a GiST index on the tsvector.
Searching is done using tsquery and the @@ operator: