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)

This commit is contained in:
2025-10-12 21:23:45 +11:00
parent 27e06a9462
commit 9ffb704648

View File

@@ -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