From 9ffb704648cefb4f9802de874b1af4ae706f079e Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sun, 12 Oct 2025 21:23:45 +1100 Subject: [PATCH] fix bug where AI search used wrong query as I rewrote the search_term and lost AI: now compares original / OPT.search_term. Also, the union/sql did not work with otdering, rewrote this to use python code to remove duplicates from the 3 separate queries and remove duplicates (if any) --- files.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/files.py b/files.py index 9d47b8b..2e0d3d1 100644 --- a/files.py +++ b/files.py @@ -380,7 +380,7 @@ def GetSearchQueryData(OPT): search_term = OPT.search_term # turn * wildcard into sql wildcard of % search_term = search_term.replace('*', '%') - if 'AI:' in search_term: + if 'AI:' in OPT.search_term: search_term = search_term.replace('AI:', '') # AI searches are for specific ppl/joins in the DB AND we do them for ALL types of searches, define this once @@ -391,7 +391,7 @@ def GetSearchQueryData(OPT): .order_by(*order_map.get(OPT.noo) ) ) - if 'AI:' in search_term: + if 'AI:' in OPT.search_term: all_entries = db.session.execute(ai_query).scalars().all() else: # match name of File @@ -399,9 +399,11 @@ def GetSearchQueryData(OPT): # match name of Dir dir_query = select(Entry.id).join(File).join(EntryDirLink).join(Dir).where(Dir.rel_path.ilike(f'%{search_term}%')).order_by(*order_map.get(OPT.noo)) + ai_entries = db.session.execute(ai_query).scalars().all() + file_entries = db.session.execute(file_query).scalars().all() + dir_entries = db.session.execute(dir_query).scalars().all() # Combine ai, file & dir matches with union() to dedup and then order them - combined_query = union( file_query, dir_query, ai_query ) - all_entries = db.session.execute(combined_query).scalars().all() + all_entries = list(dict.fromkeys(ai_entries + dir_entries + file_entries)) query_data['entry_list']=all_entries return query_data