2626from . import frontend_boost
2727
2828from .database import engine , Base , Archive , Tag , Category
29- from sqlalchemy import func , select , or_ , update , delete
29+ from sqlalchemy import func , select , not_ , or_ , update , delete
3030from sqlalchemy .orm import Session
3131Base .metadata .create_all (bind = engine )
3232
@@ -103,6 +103,11 @@ def do_search(db: Session, category: str, filters: str, order: Union[OrderingDir
103103 else :
104104 filters += ', ' + search
105105 for f in filter (None , map (str .strip , filters .split (',' ))):
106+ if f [0 ] == '-' :
107+ f = f [1 :]
108+ condition = lambda * expressions : not_ (or_ (* expressions ))
109+ else :
110+ condition = or_
106111 pre = suff = '%'
107112 if f [- 1 ] == '$' :
108113 f = f [:- 1 ]
@@ -112,7 +117,7 @@ def do_search(db: Session, category: str, filters: str, order: Union[OrderingDir
112117 pre = suff = ''
113118 f = pre + f + suff
114119 f .replace ('*' , '%' ).replace ('?' , '_' )
115- stmt = stmt .where (or_ (Archive .title .like (f ), Archive .subtitle .like (f ), Archive .id .in_ (select (Archive .id ).outerjoin (Archive .tags ).where (Tag .tag .like (f )))))
120+ stmt = stmt .where (condition (Archive .title .like (f ), Archive .subtitle .like (f ), Archive .id .in_ (select (Archive .id ).outerjoin (Archive .tags ).where (Tag .tag .like (f )))))
116121 if order is None :
117122 stmt = stmt .order_by (func .random ())
118123 else :
0 commit comments