Repository navigation
feat(search): add SearchIndex.toJSON() / fromJSON() for pre-built static indices - #11
Open
ashishbhateja wants to merge 1 commit into
Open
ashishbhateja wants to merge 1 commit into
ashishbhateja wants to merge 1 commit into
Conversation
Enables the index to be serialised to a plain JSON-safe snapshot and reconstructed from it. The build pipeline can now write a pre-built index per edition to disk and serve it as a static asset, which is the foundation for archive-wide search without a client-side rebuild step (issue #3). Three new smoke checks: toJSON throws before build, fromJSON round-trip produces identical results, snapshot survives JSON.stringify/parse.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Adds two methods to
SearchIndexinsrc/search.js:index.toJSON()— serialises the built index to a plain, JSON-safe object{ postings, docs }. Throws if called beforebuild(), consistent withsearch().SearchIndex.fromJSON(snapshot)— static factory that reconstructs a fully operationalSearchIndexfrom that snapshot. The docId keys (strings in JSON) are coerced back to numbers to match the internal representation.Three new smoke checks in
scripts/smoke.mjsverify:toJSON()throws beforebuild()fromJSONround-trip returns identical results to the original index for the same queryJSON.stringify→JSON.parseand is still searchableAll 22 checks pass;
npm run buildstill succeeds.Why — advances issue #3
Issue #3 asks for archive-wide search across editions. The prerequisite for that is a serialisable index: the build pipeline can call
index.build(articles).toJSON()per edition, write the snapshot todist/as a static asset, and the client loads whichever edition snapshots it needs — no re-building at query time. Multiple snapshots can also be merged by unioning theirdocsarrays and re-keying the postings, keeping everything on-device and dependency-free.This PR adds only the engine capability; wiring it into
build.mjsand the reader UI is a natural follow-on.Scope
Engine-only (
src/search.js+scripts/smoke.mjs). No UI changes, no new dependencies, no breaking changes to the existingbuild()/search()/snippet()/tokenize()API.Generated by Claude Code