def exclude(self, **kwargs): """Restrict the query to exclude results that match the given condition. Typically takes only a single kwarg, because Sphinx can't OR filters together (or, equivalently, exclude only documents which match all of several criteria). Taking multiple arbitrary kwargs would imply that it could, assuming parallel semantics with the Django ORM's ``exclude()``. However, closed range filters can have 2 kwargs: a ``__lte`` and a ``__gte`` about the same field. These mix down to a single call to SetFilterRange filter. Feel free to call ``exclude()`` more than once. Each exclusion is ANDed with any previously applied ones. If you pass something mutable as the value for any kwarg, please don't mutate it later. The values are internalized by ``S`` objects (and shared with their clones), and ``S`` objects are supposed to be immutable. """ items = lookup_triples(kwargs) if len(items) == 1: return self._clone(next_step=('exclude', items)) if len(items) == 2: # Make sure they're a gte/lte pair on the same field: (field1, cmp1, val1), (field2, cmp2, val2) = items if field1 == field2: cmps = {cmp1: val1, cmp2: val2} if 'lte' in cmps and 'gte' in cmps: return self._clone(next_step=('exclude', items)) raise TypeError('exclude() takes exactly 1 keyword argument or a ' 'pair of __lte/__gte arguments referencing the same ' 'field.')
def filter(self, **kwargs): """Restrict the query to results matching the given conditions. This filter is ANDed with any previously requested ones. If you pass something mutable as the value for any kwarg, please don't mutate it later. The values are internalized by ``S`` objects (and shared with their clones), and ``S`` objects are supposed to be immutable. """ return self._clone(next_step=('filter', lookup_triples(kwargs)))