From db64266bf35f2c7a43d5891b776c9efaab2bf35d Mon Sep 17 00:00:00 2001 From: Khairul Haaziq <101852870+khairulhaaziq@users.noreply.github.com> Date: Mon, 20 Mar 2023 00:46:17 +0800 Subject: [PATCH] docs(guides/database/full-text-search) update searching multiple columns guide Update searching multiple columns guide with a workaround involving --- .../guides/database/full-text-search.mdx | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/apps/docs/pages/guides/database/full-text-search.mdx b/apps/docs/pages/guides/database/full-text-search.mdx index f3d98ff302a..9e75b3036d1 100644 --- a/apps/docs/pages/guides/database/full-text-search.mdx +++ b/apps/docs/pages/guides/database/full-text-search.mdx @@ -227,6 +227,9 @@ final result = await client ### Search multiple columns +Right now there is no direct way to use Javascript or Dart to search through multiple columns. A workaround exist where using SQL is required. +The method involves creating [computed virtual columns](https://postgrest.org/en/stable/api.html#computed-virtual-columns). + To find all `books` where `description` or `title` contain the word `little`: + + +```sql +CREATE FUNCTION title_description(books) RETURNS text AS $$ + SELECT $1.title || ' ' || $1.description; +$$ LANGUAGE SQL; +``` + +```js +const { data, error } = await supabase + .from('books') + .select() + .textSearch('title_description', `little`) +``` + + + + +```sql +CREATE FUNCTION title_description(books) RETURNS text AS $$ + SELECT $1.title || ' ' || $1.description; +$$ LANGUAGE SQL; +``` + +```dart +final result = await client + .from('books') + .select() + .textSearch('title_description', "little") +``` +