6

I am trying to retrieve the data from the a database using to_tsquery() on the basis of text search. I am able to get the results for complete word search but not for the substring.

Example:

SELECT * FROM snp_gene_context WHERE protein_name @@ to_tsquery('english','KIN') AND gene_dist='0'; 

I am able to get the rows containing the word 'KIN11' but I am unable to get rows containing 'Kinase'.

4
  • do a case-insensitive search. Commented May 15, 2015 at 6:28
  • 1
    can u explain how to do case insensitive search to_tsquery()? i searched with 'Kin' and 'kin' now and got same results as above mentioned. Commented May 15, 2015 at 6:40
  • Do you really need full text search for that? Why not just search for '%kin%'? Commented May 15, 2015 at 6:55
  • 2
    If you only interested in prefix matching, you can use to_tsquery('kin:*') -- for a more custom containment testing, you can use like / ilike with pg_trgm index (what Tometzky already mentioned). Commented May 15, 2015 at 7:55

1 Answer 1

6

Full text search doesn't work on substrings — only words.

For indexed substring searches you'd need to use pg_trgm extension. There's a good article about faster like/ilike searches using pg_trgm on select * from depesz blog. There's a trade-of though — much slower writes.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.