Skip to content
Browse files

Implemented __hash__ and __eq__ for Q objects, closing issue #5.

  • Loading branch information...
1 parent e1de334 commit cf3d0d8a9bae38239cfb2eecde348ef67cab569b @mhluongo mhluongo committed Aug 4, 2011
Showing with 6 additions and 1 deletion.
  1. +6 −0 lucenequerybuilder/query.py
  2. +0 −1 lucenequerybuilder/tests.py
View
6 lucenequerybuilder/query.py
@@ -108,6 +108,12 @@ def __add__(self, other):
def __sub__(self, other):
return self | Q._make_must_not(self)
+ def __eq__(self, other):
+ return hash(self) == hash(other)
+
+ def __hash__(self):
+ return hash((tuple(self.should), tuple(self.must), tuple(self.must_not)))
+
def __str__(self):
rv = ''
if hasattr(self, 'field'):
View
1 lucenequerybuilder/tests.py
@@ -51,7 +51,6 @@ def test_hashing():
d[q2] = 2
except:
raise AssertionError('There was an error using queries as dict keys.')
- assert d[q1] == 1, 'Got the wrong value back from the query dict!'
assert d[q2] == 2, 'Got the wrong value back from the query dict!'

0 comments on commit cf3d0d8

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