From a2ebf2984b2a6b5e19182faa88dbd78eb611595c Mon Sep 17 00:00:00 2001 From: Taha <98838967+Taha-Hassan-Git@users.noreply.github.com> Date: Wed, 26 Jun 2024 12:04:23 +0100 Subject: [PATCH] Better docs search (#4015) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Search through the keywords of an article as well as the text. This ensures that relevant examples show up for people using the search feature. ### Change Type - [ ] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [x] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Search for 'camera' 2. examples such as pdf annotator and image annotator now display ### Release Notes - Improves the docs search by searching through keywords --- apps/docs/app/api/search/route.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/docs/app/api/search/route.ts b/apps/docs/app/api/search/route.ts index 848ced297..83de50297 100644 --- a/apps/docs/app/api/search/route.ts +++ b/apps/docs/app/api/search/route.ts @@ -36,14 +36,15 @@ export async function GET(req: NextRequest) { const db = await getDb() const searchForArticle = await db.db.prepare( ` - SELECT id, title, sectionId, categoryId, content + SELECT id, title, sectionId, categoryId, content, keywords FROM ftsArticles - WHERE ftsArticles MATCH ? + WHERE ftsArticles MATCH ? OR keywords MATCH ? ORDER BY bm25(ftsArticles, 1000.0) `, - query + [query, query] ) + await searchForArticle.all().then(async (queryResults) => { for (const article of queryResults) { const section = await db.getSection(article.sectionId)