-
Notifications
You must be signed in to change notification settings - Fork 1
feat(search): client side fts #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
larbish
wants to merge
62
commits into
main
Choose a base branch
from
feat/client-side-fts-search
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
8069af1
feat(search): client side fts
larbish 2f703a0
feat: add agent skills discovery via `/.well-known/skills` (#19)
atinux 44c8e0e
fix(responsive): remove playground in hero on mobile
larbish 8ea6404
run on worker
larbish c9a22f7
Merge branch 'main' into feat/client-side-fts-search
larbish d26bc6f
use comark-cms latest
larbish 06e5eec
app search nav groups
larbish a783a63
debug system
larbish 74dfd6e
Merge branch 'main' into feat/client-side-fts-search
larbish d1b2cbc
pnpm lock file
larbish 060607b
up
larbish 4017871
up
larbish 6b95a04
use resolveContentSha
larbish 0c602ab
Merge branch 'main' into feat/client-side-fts-search
larbish fccb570
up tests
larbish ba0354a
fix lock
larbish 4ac9598
Merge branch 'main' into feat/client-side-fts-search
larbish d7f91e9
use nuxt-workers
larbish 8658fc4
fix lockfile
larbish c04e129
Merge branch 'main' into feat/client-side-fts-search
larbish 321bb5e
Merge branch 'main' into feat/client-side-fts-search
larbish a593fbd
improvements
larbish 1f52fe8
Apply comark 4.0 changes
larbish b5bc5ca
try warm with function invocation
larbish 8e65942
feat: built time snapshot
larbish 1b49f44
Merge branch 'main' into feat/client-side-fts-search
atinux aa28e59
snapshot improvements
larbish 8ed1944
add metrics
larbish 83fb86f
Merge branch 'main' into feat/client-side-fts-search
larbish 2378af0
Merge branch 'main' into feat/client-side-fts-search
larbish d6a2ca8
Merge branch 'main' into feat/client-side-fts-search
larbish 01457f6
improve icon bundle
larbish 1b4a029
feat(content): pin instances per commit with withRef() (#42)
atinux e462783
small cache / driver refactor
larbish 8a9b20f
refactor: move preview in a new util
larbish 31e7e7b
simplify icon collections
larbish 291fc31
nitro icon aliases
larbish b5ad6da
chore: update comark-content
atinux 14a6ff0
chore: fix import snapshot + add manifest.json
atinux fd85d3e
always use sha to pin instance in production (no ref)
larbish 972f26e
chore: add renovate config
benjamincanac d543244
chore: pin pnpm version
benjamincanac 6423017
chore: add node engines
benjamincanac fd587bc
chore(pnpm): scope minimum release age excludes to comark packages
benjamincanac 8472957
chore(deps): use `@nuxt/ui` 4.11.1 release
benjamincanac 937adb6
Update pnpm-lock.yaml
atinux fdd81de
feat(cache): persist production content ref
atinux a31954e
fix(cache): bound production ref staleness
atinux bdbc1fa
chore: follow coderabbit advice
atinux 00eb564
Merge branch 'main' into feat/client-side-fts-search
atinux ab69ef6
fix(cache): rotate bounded ref namespace
atinux 09a4f13
chore(pnpm): scope comark release-age exemptions
atinux 400ec0a
fix: build
atinux 6559d78
Merge branch 'main' into feat/client-side-fts-search
larbish 3a9bdd2
use agent-discovery utils
larbish 5056ac4
no prerendering skills
larbish eb9dede
Merge branch 'main' into feat/client-side-fts-search
atinux a12be8e
fix(config): keep an explicit `schemaOrg: false` disabled
benjamincanac 2424b27
refactor(config): assign seeded options through the typed view
benjamincanac 37e6d5a
fix(prose): keep default link styles for inline code
benjamincanac e8200ff
Merge branch 'main' into feat/client-side-fts-search
larbish 1d75c41
chore(search): import comark-content from runtime package
larbish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| <script setup lang="ts"> | ||
| import type { NavigationItem } from 'comark-content' | ||
|
|
||
| const props = defineProps<{ | ||
| navigation: NavigationItem[] | ||
| }>() | ||
|
|
||
| const { search, status } = useSearch() | ||
|
|
||
| const appConfig = useAppConfig() | ||
|
|
||
| interface PageItem { | ||
| label: string | ||
| prefix?: string | ||
| suffix?: string | ||
| to: string | ||
| icon: string | ||
| } | ||
|
|
||
| /** Leaf pages, flattened; ancestor titles become the `Section > Page` prefix the palette renders. */ | ||
| function pageItems(items: NavigationItem[], ancestors: string[] = []): PageItem[] { | ||
| return items.flatMap((item) => { | ||
| if (item.children?.length) return pageItems(item.children, [...ancestors, item.title]) | ||
| if (!item.path || item.page === false) return [] | ||
| return [{ | ||
| label: item.title, | ||
| prefix: ancestors.length ? `${ancestors.join(' > ')} >` : undefined, | ||
| suffix: item.description, | ||
| to: item.path, | ||
| icon: (item.icon as string | undefined) || appConfig.ui.icons.file, | ||
| }] | ||
| }) | ||
| } | ||
|
|
||
| function browseOnly(query: string, items?: PageItem[]): PageItem[] { | ||
| return query ? [] : (items ?? []) | ||
| } | ||
|
|
||
| // One group per top-level section, mirroring how `UContentSearch` groups navigation when it can. | ||
| const groups = computed(() => { | ||
| if (props.navigation.some((item) => item.children?.length)) { | ||
| return props.navigation | ||
| .filter((section) => section.children?.length) | ||
| .map((section) => ({ | ||
| id: section.path, | ||
| label: section.title, | ||
| items: pageItems(section.children ?? []), | ||
| postFilter: browseOnly, | ||
| })) | ||
| .filter((group) => group.items.length > 0) | ||
| } | ||
| return [{ id: 'docs', items: pageItems(props.navigation), postFilter: browseOnly }] | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <ClientOnly> | ||
| <LazyUContentSearch | ||
| :search="search" | ||
| :search-status="status" | ||
| :navigation="navigation" | ||
| :groups="groups" | ||
| :transition="false" | ||
| :loading="status === 'loading'" | ||
| /> | ||
| </ClientOnly> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import type { SearchOptions, SearchResult } from 'comark-content' | ||
|
|
||
| type SearchStatus = 'idle' | 'loading' | 'ready' | 'error' | ||
|
|
||
| const status = ref<SearchStatus>('idle') | ||
|
|
||
| /** | ||
| * Hydration logging switch: `?debug=search` | ||
| */ | ||
| function searchDebug(): boolean { | ||
| if (!import.meta.client) return false | ||
| return new URLSearchParams(location.search).get('debug') === 'search' | ||
| } | ||
|
|
||
| /** | ||
| * Client-side full-text search over production content (sqlite-wasm FTS5) hydrated from the | ||
| * per-commit snapshot artifacts. | ||
| */ | ||
| export function useSearch() { | ||
| const { data: headSha } = useAsyncData( | ||
| 'content-head-sha', | ||
| () => $fetch<{ sha: string | null }>('/api/content/head').then(({ sha }) => sha), | ||
| { default: () => null } | ||
| ) | ||
|
|
||
| /** | ||
| * Load the database. | ||
| * No-op once loading or ready; retries after a failure. | ||
| */ | ||
| async function warmup(): Promise<void> { | ||
| if (status.value === 'loading' || status.value === 'ready') return | ||
| status.value = 'loading' | ||
| try { | ||
| if (!headSha.value && !import.meta.dev) { | ||
| throw new Error('[search] /api/content/head returned no commit pin') | ||
| } | ||
|
|
||
| // Immutable per-commit artifacts, CDN-cached forever. Only unpinned in dev, per the guard above. | ||
| const apiBase = headSha.value ? `/api/content/blob/${headSha.value}` : '/api/content' | ||
|
|
||
| const debug = searchDebug() | ||
| if (debug) console.info(`[search] warmup from ${apiBase} (head ${headSha.value ?? 'unpinned'})`) | ||
|
|
||
| await warmupSearch(apiBase, location.origin, debug) | ||
| status.value = 'ready' | ||
| } catch (error) { | ||
| status.value = 'error' | ||
| console.error('[search] could not load the search database', error) | ||
| } | ||
| } | ||
|
|
||
| if (import.meta.client) { | ||
| onNuxtReady(warmup) | ||
| } | ||
|
|
||
| async function search(query: string, opts?: SearchOptions): Promise<SearchResult[]> { | ||
| return searchContent(query, opts) | ||
| } | ||
|
|
||
| return { search, status: readonly(status), warmup } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /** | ||
| * Logging for the search worker. | ||
| * | ||
| * Triggered by `?debug=search` param. | ||
| */ | ||
| import type { ContentFile, Logger, RelationalDatabase } from 'comark-content/runtime' | ||
|
|
||
| const PREFIX = '[search:worker]' | ||
|
|
||
| let debug = false | ||
|
|
||
| /** Called on every `warmup`; once on, it stays on for the life of the worker. */ | ||
| export function setDebug(value: boolean): void { | ||
| debug = debug || value | ||
| } | ||
|
|
||
| export function isDebug(): boolean { | ||
| return debug | ||
| } | ||
|
|
||
| export function log(...args: unknown[]): void { | ||
| if (debug) console.info(PREFIX, ...args) | ||
| } | ||
|
|
||
| /** Milliseconds since `from`, for log lines. */ | ||
| export function since(from: number): string { | ||
| return `${(performance.now() - from).toFixed(1)}ms` | ||
| } | ||
|
|
||
| /** | ||
| * Warn and error are deliberately ungated: the FTS plugin reports a missing snapshot through this | ||
| * channel, and that failure is otherwise indistinguishable from "the query matched nothing". | ||
| */ | ||
| export const logger: Logger = { | ||
| debug: (tag, ...args) => log(`${tag}:`, ...args), | ||
| info: (tag, ...args) => log(`${tag}:`, ...args), | ||
| warn: (tag, ...args) => console.warn(`${PREFIX} ${tag}:`, ...args), | ||
| error: (tag, ...args) => console.error(`${PREFIX} ${tag}:`, ...args), | ||
| } | ||
|
|
||
| /** | ||
| * What a decoded artifact holds: a snapshot decodes to the source's items, the manifest to an object | ||
| * keyed by path. `with nodes` is the number that matters — the FTS plugin indexes | ||
| * `kind === 'document' && nodes?.length`, so a bodies-less (partial) snapshot builds an empty index. | ||
| */ | ||
| export function describeArtifact(decoded: unknown): string { | ||
| if (Array.isArray(decoded)) { | ||
| const items = decoded as ContentFile[] | ||
| const documents = items.filter((item) => item.meta.kind === 'document') | ||
| const withNodes = documents.filter((item) => item.nodes?.length) | ||
| return `${items.length} item(s), ${documents.length} document(s), ${withNodes.length} with nodes` | ||
| } | ||
| const items = (decoded as { items?: Record<string, unknown> } | null)?.items | ||
| return `${items ? Object.keys(items).length : 0} manifest item(s)` | ||
| } | ||
|
|
||
| /** | ||
| * Rows in the FTS plugin's index — the one number that separates "nothing was indexed" from "the | ||
| * query found nothing", since `search()` catches SQL errors and returns `[]` either way. Reads the | ||
| * plugin's private table, so it is a diagnostic, not something to build on. | ||
| */ | ||
| export async function indexedRows(database: RelationalDatabase, source: string): Promise<number | string> { | ||
| try { | ||
| const rows = await database.all<{ n: number }>('SELECT count(*) as n FROM __fts_search WHERE source = ?', [source]) | ||
| return rows?.[0]?.n ?? 'unknown' | ||
| } catch (error) { | ||
| return `unknown (${error instanceof Error ? error.message : String(error)})` | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.