mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +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)
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import * as Sentry from '@sentry/nextjs'
|
|
import { createSupabaseClient, SEARCH_FUNCTION } from '~/scripts/search_v2/supabase'
|
|
import { type NextRequest } from 'next/server'
|
|
|
|
import { fetchMarkdown, resolveDocsBaseUrl } from './content'
|
|
import { corsHeaders } from './cors'
|
|
|
|
export const runtime = 'edge'
|
|
|
|
export async function OPTIONS() {
|
|
return new Response(null, { headers: corsHeaders })
|
|
}
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const { searchParams } = new URL(request.url)
|
|
const query = searchParams.get('q')?.trim()
|
|
const limit = Number(searchParams.get('limit')) || 10
|
|
const includeContent = searchParams.get('content') === 'true'
|
|
|
|
if (!query) {
|
|
return Response.json({ error: 'Missing q parameter' }, { status: 400, headers: corsHeaders })
|
|
}
|
|
|
|
const { data, error } = await createSupabaseClient().rpc(SEARCH_FUNCTION, {
|
|
query_text: query,
|
|
match_limit: limit,
|
|
})
|
|
|
|
if (error) {
|
|
console.error('Error running docs search v2:', error)
|
|
Sentry.captureException(new Error(error.message), {
|
|
tags: { route: 'search_v2' },
|
|
extra: { query, limit, error },
|
|
})
|
|
return Response.json({ error: error.message }, { status: 500, headers: corsHeaders })
|
|
}
|
|
|
|
if (!includeContent) {
|
|
return Response.json(data, { headers: corsHeaders })
|
|
}
|
|
|
|
// Attach each page's markdown export; null when it has none or can't be loaded.
|
|
const baseUrl = resolveDocsBaseUrl(request.url)
|
|
const results = await Promise.all(
|
|
(data as { slug: string }[]).map(async (row) => ({
|
|
...row,
|
|
content: await fetchMarkdown(baseUrl, row.slug),
|
|
}))
|
|
)
|
|
return Response.json(results, { headers: corsHeaders })
|
|
} catch (error) {
|
|
console.error('Error handling docs search v2 request:', error)
|
|
Sentry.captureException(error, { tags: { route: 'search_v2' } })
|
|
return Response.json(
|
|
{ error: 'There was an error processing your request' },
|
|
{ status: 500, headers: corsHeaders }
|
|
)
|
|
}
|
|
}
|