supabase-py icon indicating copy to clipboard operation
supabase-py copied to clipboard

Full text search in python

Open aaa3334 opened this issue 1 year ago • 1 comments

Hi!

I am wondering if there is a way to do the full text search as described here? https://supabase.com/docs/guides/database/full-text-search?language=js&example-view=sql

Note I am fine on creating the fts column in the table I am searching, just when I am trying to do the actual search.

Note I am trying to use this: initial_query = initial_query.filter('fts', 'plfts', keyword_query)

Where the keyword_query is either one word or a few strung together by |

If I attempt the same query in the sql in supabase itself it works, but it doesnt work if I try and use .filter and I am not sure what else to use (eg textsearch does not exist on it).

How can I get this to work?

I have considered:

  1. Perhaps there is a different way to format it so I get the actual results here that i have just missed
  2. Perhaps there is a way to send the sql statement directly? (this is in python so all in the back end)

Unsure how to get this to work

Thanks in advance!

aaa3334 avatar Apr 01 '24 22:04 aaa3334

You would perform a full text search using the .text_search method.

client.table("movies").select("*").text_search("title", "'The Aveng'").execute()

or if you want to manually use a filter you can do

client.table("movies").select("*").filter("title", "fts", "'The Aveng'").execute()

Do note the single quote around 'The Aveng' as it is necessary for the full text search to work. Also in your example you have the order incorrect, its column_name, operator and criteria that the .filter function takes.

silentworks avatar Apr 10 '24 23:04 silentworks

This has now been documented in the reference docs https://supabase.com/docs/reference/python/textsearch

silentworks avatar Jun 25 '24 06:06 silentworks