mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Currently we experience a lot of empty results responses from our new search_v2 experiment. We are improving our search logic on our frontend plus our search functions in the backend ot fix this. ## Solution Improve our search setup to follow this path: 1. Same as before, strict full text search. 1. If that returns zero results, we do prefixes via wild cards, ie: "edge fun" becomes "edge fun|*" so people don't have to type the full term. 1. If that returns zero results, then we run the terms under OR, which will give partial results for individual terms. 1. If that returns zero results then we are most probably under a typo/misspelling scenario, then we use `pg_trgm` extension with a `0.4` tier to return the closest bit, which is good cause it covers missing first letters like "dge functions" too. We will do this migration in three steps to not disrupt current users under the experiments, I will be posting the PRs here: 1. First, we will create a new search_v2 table on `supabase.com [LIVE]` project where production parts of our monorepo go + already implement the improvements I just mentioned. 1. Re-route the ingest script to populate once per day the database table in this new project. At this point we will have the data and the search function ready. 1. Update the API search_v2 function to query from this new project, so users will experience no down time. 👈 **this PR is here** <!-- ## Preview links If relevant, include links to changed pages for easy review access. Copy the preview base URL from the Vercel bot comment on this PR. Use the following table as an example template. | Site | Live | Preview | Search for | | -------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------- | | WWW | [/blog/your-post](https://supabase.com/blog/your-post) | [/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post) | unique phrase from the change | | Docs | [/docs/guides/your-page](https://supabase.com/docs/guides/your-page) | [/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page) | unique phrase from the change | | Studio | [/dashboard](https://supabase.com/dashboard) | [/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard) | unique phrase from the change | | Design system | [/design-system](https://supabase.com/design-system) | [/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system) | unique phrase from the change | | UI library | [/library](https://supabase.com/library) | [/library](https://ui-library-git-branch-name-supabase.vercel.app/library) | unique phrase from the change | | Knowledge base | [/kb/guides/your-page](https://supabase.com/kb/guides/your-page) | [/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page) | unique phrase from the change | --> <!-- ## Additional context Optionally add any other context or screenshots. --> ## Review instructions 1. Open the preview of docs 1. Make sure you are on the search_v2 experiment or open it on an incognito window 1. Open the search modal and run a query like "edge fun" 1. Search should return results, confirming it's using the new database table ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
23 lines
745 B
TypeScript
23 lines
745 B
TypeScript
import { createClient, type SupabaseClient } from '@supabase/supabase-js'
|
|
|
|
export const TABLE_NAME = 'docs_search_v2'
|
|
export const SEARCH_FUNCTION = 'docs_search_v2'
|
|
|
|
function requireEnv(name: string): string {
|
|
const value = process.env[name]
|
|
if (!value) {
|
|
throw new Error(`Missing ${name}. Set it in .env.local.`)
|
|
}
|
|
return value
|
|
}
|
|
|
|
/** Server-side client built from NEXT_PUBLIC_SUPABASE_URL + SUPABASE_SECRET_KEY in .env.local. */
|
|
export function createSupabaseClient(): SupabaseClient {
|
|
const url = requireEnv('NEXT_PUBLIC_SUPABASE_URL')
|
|
const secretKey = requireEnv('SUPABASE_SECRET_KEY')
|
|
|
|
return createClient(url, secretKey, {
|
|
auth: { autoRefreshToken: false, persistSession: false, detectSessionInUrl: false },
|
|
})
|
|
}
|