Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion tagging_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,22 @@ def find_files_by_tags(self, tags: List[str], match_all: bool = False,
"""Find files that match specified tags"""

with sqlite3.connect(self.db_path) as conn:
cursor = conn.execute("SELECT * FROM file_tags")
if not tags:
return []

# Pre-filter using SQLite LIKE to avoid full-table JSON parsing
conditions = []
params = []
for tag in tags:
# Safely escape tag for LIKE matching inside JSON array
safe_tag = json.dumps(tag)[1:-1]
conditions.append("(auto_tags LIKE ? OR user_tags LIKE ?)")
params.extend([f'%"{safe_tag}"%', f'%"{safe_tag}"%'])

where_clause = " OR ".join(conditions) if not match_all else " AND ".join(conditions)
query = f"SELECT * FROM file_tags WHERE {where_clause}"

cursor = conn.execute(query, params)
columns = [desc[0] for desc in cursor.description]
results = []

Expand Down
Loading