Better docs search (#4015)

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

<!--  Please select a 'Scope' label ️ -->

- [ ] `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

<!--  Please select a 'Type' label ️ -->

- [ ] `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
This commit is contained in:
Taha 2024-06-26 12:04:23 +01:00 committed by GitHub
parent 80b758d466
commit a2ebf2984b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -36,14 +36,15 @@ export async function GET(req: NextRequest) {
const db = await getDb() const db = await getDb()
const searchForArticle = await db.db.prepare( const searchForArticle = await db.db.prepare(
` `
SELECT id, title, sectionId, categoryId, content SELECT id, title, sectionId, categoryId, content, keywords
FROM ftsArticles FROM ftsArticles
WHERE ftsArticles MATCH ? WHERE ftsArticles MATCH ? OR keywords MATCH ?
ORDER BY bm25(ftsArticles, 1000.0) ORDER BY bm25(ftsArticles, 1000.0)
`, `,
query [query, query]
) )
await searchForArticle.all().then(async (queryResults) => { await searchForArticle.all().then(async (queryResults) => {
for (const article of queryResults) { for (const article of queryResults) {
const section = await db.getSection(article.sectionId) const section = await db.getSection(article.sectionId)