Skip to content
Browse files

Reorder if tests and add comment

  • Loading branch information...
1 parent eaccdd5 commit 0423513c90548e9ca4d004a0e8f3a6cbcff2bbbd @tow committed Oct 1, 2012
Showing with 15 additions and 13 deletions.
  1. +15 −13 sunburnt/search.py
View
28 sunburnt/search.py
@@ -158,19 +158,21 @@ def normalize(self):
ranges = reduce(operator.or_, _ranges),
subqueries = _subqueries)
- # having recaltulcated subqueries, there may be the opportunity for further normalization:
- if obj._not and not len(obj.subqueries):
- obj = obj.clone(_not=False, _and=True)
- mutated = True
- elif obj._not and len(obj.subqueries) == 1 and obj.subqueries[0]._not:
- obj = obj.clone(subqueries=obj.subqueries[0].subqueries, _not=False, _and=True)
- mutated = True
- elif obj._pow and not len(obj.subqueries):
- obj = obj.clone(_pow=False)
- mutated = True
- elif (obj._and or obj._or) and not obj.terms and not obj.phrases and not obj.ranges and len(obj.subqueries) == 1:
- obj = obj.subqueries[0]
- mutated = True
+ # having recaltulcated subqueries, there may be the opportunity for further normalization, if we have zero or one subqueries left
+ if not len(obj.subqueries):
+ if obj._not:
+ obj = obj.clone(_not=False, _and=True)
+ mutated = True
+ elif obj._pow:
+ obj = obj.clone(_pow=False)
+ mutated = True
+ elif len(obj.subqueries) == 1:
+ if obj._not and obj.subqueries[0]._not:
+ obj = obj.clone(subqueries=obj.subqueries[0].subqueries, _not=False, _and=True)
+ mutated = True
+ elif (obj._and or obj._or) and not obj.terms and not obj.phrases and not obj.ranges:
+ obj = obj.subqueries[0]
+ mutated = True
obj.normalized = True
return obj, mutated

0 comments on commit 0423513

Please sign in to comment.
Something went wrong with that request. Please try again.