server/search: fix negating complex searches

Entering:

    miko -miko

is a contradiction that shouldn't have been returning any matches, but
it has nonetheless. This change fixes the construction of negated
expressions that use subqueries.
This commit is contained in:
rr- 2016-08-28 18:40:59 +02:00
parent 22342a29ad
commit c366b608da

View file

@ -127,8 +127,11 @@ def create_subquery_filter(
if subquery_decorator:
subquery = subquery_decorator(subquery)
subquery = subquery.options(sqlalchemy.orm.lazyload('*'))
subquery = filter_func(subquery, criterion, negated)
subquery = filter_func(subquery, criterion, False)
subquery = subquery.subquery('t')
return query.filter(left_id_column.in_(subquery))
expression = left_id_column.in_(subquery)
if negated:
expression = ~expression
return query.filter(expression)
return wrapper