index relations and observations

This commit is contained in:
phernandez
2025-01-14 18:14:24 -06:00
parent 2aa965b611
commit 9dff24746d
3 changed files with 136 additions and 42 deletions
+33 -10
View File
@@ -5,16 +5,39 @@ from sqlalchemy import DDL
# Define FTS5 virtual table creation
CREATE_SEARCH_INDEX = DDL("""
CREATE VIRTUAL TABLE IF NOT EXISTS search_index USING fts5(
id UNINDEXED, -- row id of the indexed item
title, -- Title for exact/fuzzy matching
content, -- Additional searchable content
permalink UNINDEXED, -- Link to entity
file_path UNINDEXED, -- Filesystem path
type UNINDEXED, -- entity type
metadata UNINDEXED, -- Additional metadata
-- Core entity fields
id UNINDEXED, -- Row ID
title, -- Title for searching
content, -- Main searchable content
permalink UNINDEXED, -- Stable identifier
file_path UNINDEXED, -- Physical location
type UNINDEXED, -- entity/relation/observation
-- Use unicode61 for basic tokenization with prefix matching
tokenize='unicode61 remove_diacritics 2',
prefix='2,3' -- Enable prefix matching for 2-3 char prefixes
-- Relation fields
from_id UNINDEXED, -- Source entity
to_id UNINDEXED, -- Target entity
relation_type UNINDEXED, -- Type of relation
-- Observation fields
entity_id UNINDEXED, -- Parent entity
category UNINDEXED, -- Observation category
-- Common fields
metadata UNINDEXED, -- JSON metadata
created_at UNINDEXED, -- Creation timestamp
updated_at UNINDEXED, -- Last update
-- Configuration
tokenize='porter unicode61',
prefix='2,3',
content='title content' -- Default searchable columns
);
-- Add index for relation traversal
CREATE INDEX IF NOT EXISTS idx_search_relations
ON search_index(from_id, to_id) WHERE type = 'relation';
-- Add index for type filtering
CREATE INDEX IF NOT EXISTS idx_search_type_perm
ON search_index(type);
""")