feat(search): offline search index for courses (#393)#431
Open
mmorgsmorgan wants to merge 1 commit into
Open
Conversation
Adds a pure-JS inverted index that builds at app start, persists to AsyncStorage, and replaces the inline filter in MobileSearch. Search intersects per-token postings (AND), supports prefix matching on the trailing token, and ranks by field-weighted scoring (title > category > level > body). Falls back through courseApi -> offlineStorage -> sampleCourse so the screen works offline once the snapshot has been built. Snapshots persist under a versioned key with a 200KB cap.
|
@mmorgsmorgan Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
kindly resolve conflict and fix workflow. |
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.
Closes #393
Summary
Replaced the inline
.includes()filtering inMobileSearchwith a local offline-first search index for faster and more scalable search.What changed
Added a pure JavaScript inverted index in
src/services/searchIndex/No new dependencies added
Added tokenization with:
Implemented:
Added weighted ranking:
Added prefix match bonus scoring
Persistence
Search snapshots persist to AsyncStorage under:
@teachlink_search_index_v1Snapshot includes:
Added a 200KB size cap
Search lifecycle
Added
SearchIndexProviderinapp/_layout.tsxProvider flow:
Hydrates from AsyncStorage on startup
Rebuilds asynchronously from:
courseApi.getCourses()offlineStorage.getAllCourses()[sampleCourse]After one successful online build, search works fully offline
Public API
useSearchIndex()exposes:readysizesearchrebuildIncremental updates supported through:
searchIndex.update(doc)searchIndex.remove(id)User indexing
User search is intentionally out of scope for this PR.
The codebase currently includes
getUser(id)but no list source. TheIndexableDocAPI already supports a'user'type, so future support only requires:Acceptance Criteria
Build search index on app startup via
SearchIndexProviderImplement efficient search algorithm with:
Instant search results (<100ms)
Offline search support through AsyncStorage snapshot persistence
Index size management with 200KB payload cap
Incremental index updates through:
update(doc)remove(id)rebuild()Added JSDoc documentation for public exports
Files
New
src/services/searchIndex/{types,tokenize,SearchIndex,persistence,courseAdapter,index}.tssrc/components/SearchIndexProvider.tsxsrc/hooks/useSearchIndex.tssrc/__tests__/services/searchIndex/{tokenize,SearchIndex,persistence}.test.tsModified
src/components/mobile/MobileSearch.tsxfilterCourse(sampleCourse, ...)withuseSearchIndex().search(...)app/_layout.tsx<SearchIndexProvider>src/components/index.tssrc/hooks/index.tsTest Plan
npm test -- searchIndexFull test suite completed
only existing failures remain:
DebounceIntegrationsecureStorageno regressions introduced
eslint --max-warnings=0Manual Verification
sampleCourse, restart app, and confirm rebuild occurs instead of serving stale data