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:
10
files.py
10
files.py
@@ -380,7 +380,7 @@ def GetSearchQueryData(OPT):
|
|||||||
search_term = OPT.search_term
|
search_term = OPT.search_term
|
||||||
# turn * wildcard into sql wildcard of %
|
# turn * wildcard into sql wildcard of %
|
||||||
search_term = search_term.replace('*', '%')
|
search_term = search_term.replace('*', '%')
|
||||||
if 'AI:' in search_term:
|
if 'AI:' in OPT.search_term:
|
||||||
search_term = search_term.replace('AI:', '')
|
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
|
# 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) )
|
.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()
|
all_entries = db.session.execute(ai_query).scalars().all()
|
||||||
else:
|
else:
|
||||||
# match name of File
|
# match name of File
|
||||||
@@ -399,9 +399,11 @@ def GetSearchQueryData(OPT):
|
|||||||
# match name of Dir
|
# 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))
|
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
|
# Combine ai, file & dir matches with union() to dedup and then order them
|
||||||
combined_query = union( file_query, dir_query, ai_query )
|
all_entries = list(dict.fromkeys(ai_entries + dir_entries + file_entries))
|
||||||
all_entries = db.session.execute(combined_query).scalars().all()
|
|
||||||
|
|
||||||
query_data['entry_list']=all_entries
|
query_data['entry_list']=all_entries
|
||||||
return query_data
|
return query_data
|
||||||
|
|||||||
Reference in New Issue
Block a user