mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Problem though they use the same package and were conceived to be 1-1, search v2 in Docs and Kb search have some differences: - Docs new search function is more complex to prevent no results, improvements kb search hasn't seen. For example, when you look for "passwor", incomplete term, Docs return results around the password term, but kb doesn't **(see screenshot below)**. - On kb side, we have a `content=true` parameter to fetch markdown content from results to serve some agentic tools, but Docs search never received that upgrade. Fair to say, in docs we are not covering all routes in markdown at the moment so it's not 100% reliable, but whenever we reach that, we can switch to use this search endpoint for MCP tooling. <img width="1512" height="867" alt="Screenshot 2026-11-16 at 13 06 08" src="https://github.com/user-attachments/assets/99baa772-d4b1-4d73-bfa7-7110d5635f0a" /> ## Solution - Add a migration file on kb search table to match docs search SQL function. - Add `content=true` parameter to docs search <!-- ## 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 - To test kb new search function, you would have checkout this branch, to spin locally kb search migration and search, other way we need to wait for merging and testing. It's important Supabase integration returns _green_ here to make sure migrations run safely. - For docs search new parameter. Open the preview for docs in this branch: 1. Open the search modal, and open your browser's dev tools, go to the network tab 1. Do a search, grab the URL and open it in a new tab 1. Add `content=true` and `limit=3` as query prameters 1. You should get back three results with a content property containing the markdown content of each route (see example below) <img width="1273" height="793" alt="Screenshot 2026-11-16 at 13 12 32" src="https://github.com/user-attachments/assets/d1af4663-e17e-438e-99ac-4e63f51460a9" /> ## 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)
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import { BASE_PATH, IS_DEV, IS_PRODUCTION, PROD_URL } from '~/lib/constants'
|
|
|
|
/**
|
|
* Resolves the docs base URL (origin + base path) from trusted sources only, so the Host header
|
|
* can't redirect the fetches made for `content=true` (SSRF). The request origin is used in local
|
|
* development only.
|
|
*/
|
|
export function resolveDocsBaseUrl(requestUrl: string): string | undefined {
|
|
if (IS_PRODUCTION) return PROD_URL
|
|
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}${BASE_PATH}`
|
|
if (process.env.NEXT_PUBLIC_SITE_URL) return `${process.env.NEXT_PUBLIC_SITE_URL}${BASE_PATH}`
|
|
if (IS_DEV) return `${new URL(requestUrl).origin}${BASE_PATH}`
|
|
return undefined
|
|
}
|
|
|
|
/**
|
|
* Fetches the markdown export of a page (`<base>/<slug>.md`). Returns null when it can't be
|
|
* loaded, including pages with no markdown export (only guides have one).
|
|
*/
|
|
export async function fetchMarkdown(
|
|
baseUrl: string | undefined,
|
|
slug: string
|
|
): Promise<string | null> {
|
|
const segments = slug.split('/')
|
|
if (!baseUrl || segments[0] !== 'guides' || segments.some((s) => !s || s === '.' || s === '..')) {
|
|
return null
|
|
}
|
|
|
|
const url = `${baseUrl}/${segments.map(encodeURIComponent).join('/')}.md`
|
|
try {
|
|
const response = await fetch(url)
|
|
if (!response.ok) {
|
|
console.warn(`Failed to fetch docs content from ${url}: ${response.status}`)
|
|
return null
|
|
}
|
|
return await response.text()
|
|
} catch (error) {
|
|
console.warn(`Failed to fetch docs content from ${url}:`, error)
|
|
return null
|
|
}
|
|
}
|