Skip to content

Add indexed title field for efficient keyword search in @mention system #821

Closed

Description

@malibio

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:

  1. No full-text indexing - The content field isn't indexed for keyword search
  2. Mixed content types - Would search through lengthy markdown content unnecessarily
  3. 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 from content
  • Task nodes (node_type = 'task') - Copy from content

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 = content for root/task nodes
  • Update: Sync title when content changes (for root/task nodes only)
  • Type change: If a node becomes/stops being a task, update title accordingly

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 title field to SurrealDB node schema
  • Create full-text search index on title field
  • Update NodeService::create_node to populate title for root/task nodes
  • Update NodeService::update_node to sync title when content changes
  • Handle edge case: node type changes to/from task

Phase 2: Query Integration

  • Add title_contains query parameter to NodeQuery (or update content_contains to use title for referenceable nodes)
  • Update @ mention autocomplete to search against title
  • Ensure existing include_roots_and_tasks filter works with title search

Phase 3: Migration & Testing

  • Create migration to populate title for 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

  • title chosen over display_name or label for clarity
  • Matches common UI terminology ("node title")

Future Considerations

  • Could extend to other "referenceable" node types beyond root/task
  • Could add title to more node types if needed for other search features

Related

Activity

  1. malibio commented on Jan 26, 2026

    @malibio
    CollaboratorAuthor

    Test baseline recorded: Frontend: 102 files, 3468 tests passed. Rust (src-tauri): 25 tests passed. Rust (packages/core): 144 tests passed (23 ignored).

  2. self-assigned this
    on Jan 26, 2026
  3. added a commit that references this issue on Jan 26, 2026
    a66b0a7
  4. added 4 commits that reference this issue on Feb 4, 2026
    11269ca
    227a809
    12fc200
    2c92ec3
  5. added 2 commits that reference this issue on Feb 26, 2026
    661676d
    a06d5fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backendenhancementfrontend

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions