Update FTS to support partial and title matches

This commit is contained in:
2025-01-27 10:51:29 -06:00
parent 1134a814d2
commit 20cfdf75e4
2 changed files with 42 additions and 26 deletions

View File

@@ -95,14 +95,14 @@ def init_fts():
conn = engine.raw_connection()
cursor = conn.cursor()
# Create FTS table for history content
# Update FTS table configuration to use trigrams for better partial matching
cursor.execute("""
CREATE VIRTUAL TABLE IF NOT EXISTS history_fts USING fts5(
title,
markdown_content,
content='history',
content_rowid='id',
tokenize='porter unicode61'
tokenize='trigram'
)
""")
@@ -137,6 +137,15 @@ def init_fts():
# Initialize FTS tables
init_fts()
def reindex_fts():
"""Reindex the FTS tables"""
conn = engine.raw_connection()
cursor = conn.cursor()
cursor.execute("INSERT INTO history_fts(history_fts) VALUES('rebuild')")
conn.commit()
cursor.close()
conn.close()
def get_db():
"""Get database session"""
db = SessionLocal()