PostgreSQL: Full Text Search - How to search partial words ?
Posted
by Anthoni Gardner
on Stack Overflow
See other posts from Stack Overflow
or by Anthoni Gardner
Published on 2010-03-25T06:32:11Z
Indexed on
2010/03/25
6:43 UTC
Read the original article
Hit count: 542
Hello,
Following a question posted here about how I can increase the speed on one of my SQL Search methods, I was advised to update my table to make use of Full Text Search. This is what I have now done, using Gist indexes to make searching faster. On some of the "plain" queries I have noticed a marked increase which I am very happy about.
However, I am having difficulty in searching for partial words. For example I have several records that contain the word Squire (454) and I have several records that contain Squirrel (173). Now if I search for Squire it only returns the 454 records but I also want it to return the Squirrel records as well.
My query looks like this
SELECT title FROM movies WHERE vectors @@ to_tsoquery('squire');
I thought I could do to_tsquery('squire%') but that does not work.
How do I get it to search for partial matches ?
Also, in my database I have records that are movies and others that are just TV Shows. These are differentiated by the "" over the name, so like "Munsters" is a TV Show, whereas The Munsters is the film of the show. What I want to be able to do is search for just the TV Show AND just the movies. Any idea on how I can achieve this ?
Regards Anthoni
© Stack Overflow or respective owner