cryogenic22 commited on
Commit
7ef7c2c
·
verified ·
1 Parent(s): a07e56d

Update utils/database.py

Browse files
Files changed (1) hide show
  1. utils/database.py +18 -1
utils/database.py CHANGED
@@ -175,7 +175,24 @@ def create_tables(conn: sqlite3.Connection) -> None:
175
  except Exception as e:
176
  st.error(f"Unexpected error in create_tables: {e}")
177
  raise
178
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  def force_recreate_collections_tables(conn: sqlite3.Connection) -> bool:
180
  """Force recreate collections tables if they're missing."""
181
  try:
 
175
  except Exception as e:
176
  st.error(f"Unexpected error in create_tables: {e}")
177
  raise
178
+ def search_documents_in_collection(conn: sqlite3.Connection, collection_id: int, query: str) -> List[Dict]:
179
+ """Search for documents within a collection."""
180
+ try:
181
+ with conn_lock:
182
+ cursor = conn.cursor()
183
+ cursor.execute('''
184
+ SELECT d.*
185
+ FROM documents d
186
+ JOIN document_collections dc ON d.id = dc.document_id
187
+ WHERE dc.collection_id = ?
188
+ AND (d.name LIKE ? OR d.content LIKE ?)
189
+ ''', (collection_id, f'%{query}%', f'%{query}%'))
190
+
191
+ return [dict(row) for row in cursor.fetchall()]
192
+
193
+ except sqlite3.Error as e:
194
+ st.error(f"Error searching documents: {e}")
195
+ return []
196
  def force_recreate_collections_tables(conn: sqlite3.Connection) -> bool:
197
  """Force recreate collections tables if they're missing."""
198
  try: