Repository navigation
Description
Overview
Add a title field to the node table to enable efficient keyword search for the @ mention autocomplete system. This field will be indexed and populated only for root nodes and task nodes.
Problem Statement
Currently, nodes use a single content field that serves dual purposes:
- Short titles for root nodes (e.g., "Project Planning", "2025-01-26")
- Full markdown content for child nodes (paragraphs, lists, code blocks, etc.)
The @ mention autocomplete system needs to perform keyword searches to find referenceable nodes. Searching against the content field is problematic because:
- No full-text indexing - The
contentfield isn't indexed for keyword search - Mixed content types - Would search through lengthy markdown content unnecessarily
- Performance - Searching unindexed text across all nodes doesn't scale
SurrealDB Limitation
SurrealDB does not support partial indexing (e.g., "index only where root_id IS NULL"). Therefore, we cannot simply add an index on content filtered to root nodes.
Proposed Solution
1. Add title Field to Node Table
DEFINE FIELD title ON TABLE node TYPE option<string>;
DEFINE INDEX idx_node_title ON TABLE node COLUMNS title SEARCH ANALYZER ascii BM25;The field is:
- Optional (
option<string>) - Only populated for root nodes and task nodes - Indexed with full-text search - Using BM25 analyzer for keyword matching
2. Population Rules
The title field is populated for:
- Root nodes (
root_id IS NULL) - Copy fromcontent - Task nodes (
node_type = 'task') - Copy fromcontent
All other nodes have title = None.
3. Sync on Modification
When content is updated on a root node or task node, the title field must be synced:
- Create: Set
title = contentfor root/task nodes - Update: Sync
titlewhencontentchanges (for root/task nodes only) - Type change: If a node becomes/stops being a task, update
titleaccordingly
4. Update @Mention Search
The mention autocomplete should query against title instead of content:
SELECT * FROM node
WHERE title @@ $search_term
AND (node_type = 'task' OR root_id IS NULL)
ORDER BY score DESC
LIMIT $limit;Acceptance Criteria
Phase 1: Schema & Backend
- Add
titlefield to SurrealDB node schema - Create full-text search index on
titlefield - Update
NodeService::create_nodeto populatetitlefor root/task nodes - Update
NodeService::update_nodeto synctitlewhen content changes - Handle edge case: node type changes to/from task
Phase 2: Query Integration
- Add
title_containsquery parameter to NodeQuery (or updatecontent_containsto use title for referenceable nodes) - Update
@mention autocomplete to search againsttitle - Ensure existing
include_roots_and_tasksfilter works with title search
Phase 3: Migration & Testing
- Create migration to populate
titlefor existing root/task nodes - Add unit tests for title population/sync logic
- Add integration tests for mention search using title
- Verify performance improvement with indexed search
Phase 4: Quality
- Documentation updated
- Code passes
bun run quality:fix - All tests pass (
bun run test:all)
Technical Notes
Why Not Index Content Directly?
- SurrealDB doesn't support partial indexes
- Indexing all content would be wasteful (child nodes have long content)
- Title field gives us precise control over what's indexed
Field Naming
titlechosen overdisplay_nameorlabelfor clarity- Matches common UI terminology ("node title")
Future Considerations
- Could extend to other "referenceable" node types beyond root/task
- Could add
titleto more node types if needed for other search features
Related
- ADR-022: Mention Autocomplete Referenceable Nodes Filter
- Issue Optimize populate_mentions with batch query for N+1 performance #163: Optimize populate_mentions with batch query
Activity
malibio commentedon Jan 26, 2026
Test baseline recorded: Frontend: 102 files, 3468 tests passed. Rust (src-tauri): 25 tests passed. Rust (packages/core): 144 tests passed (23 ignored).
feat: Add indexed title field for @mention search (closes #821)
fix: Include title field in semantic search results and optimize asyn…
fix: Use title field for @mention autocomplete display
Migrate project documentation to NodeSpace collections (#831)
Add indexed title field for efficient keyword search in @mention syst…
Migrate project documentation to NodeSpace collections (#831)
Add indexed title field for efficient keyword search in @mention syst…
Migrate project documentation to NodeSpace collections (#831)
Add indexed title field for efficient keyword search in @mention syst…
Migrate project documentation to NodeSpace collections (#831)