Skip to content

Commit

Permalink
introduce "all" query terms for Field, Value and Set indexes.
Browse files Browse the repository at this point in the history
  • Loading branch information
janwijbrand committed Nov 20, 2015
1 parent 323896c commit 003455d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/hurry/query/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
"""
$Id$
"""
from hurry.query.query import And, Or, Eq, NotEq, Between, In, Ge, Le, Text
from hurry.query.query import All, And, Or, Eq, NotEq
from hurry.query.query import Between, In, Ge, Le, Text
6 changes: 6 additions & 0 deletions src/hurry/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ def apply(self, context=None):
return difference(all, r)


class All(FieldTerm):

def apply(self, context=None):
return self.getIndex(context).apply((None, None))


class Between(FieldTerm):

def __init__(self, index_id, min_value, max_value):
Expand Down
22 changes: 21 additions & 1 deletion src/hurry/query/query.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ easy::
FieldIndex Queries
------------------

We can query for all objects indexed in this index::

>>> from hurry.query import All
>>> f1 = ('catalog1', 'f1')
>>> displayQuery(All(f1))
[1, 2, 3, 4, 5, 6]

Now for a query where f1 equals a::

>>> from hurry.query import Eq
Expand Down Expand Up @@ -234,13 +241,21 @@ First let's set up some new data::
... Content(3, ['b'], 1),
... Content(4, ['c', 'd'], 2),
... Content(5, ['b', 'c'], 2),
... Content(6, ['a', 'c'], 2)]
... Content(6, ['a', 'c'], 2),
... Content(7, ['z'], 2),
... Content(8, [], 2)] # no value, so not indexed.

And catalog them now::

>>> for entry in content:
... catalog.index_doc(intid.register(entry), entry)

We can query for all indexes objects:

>>> from hurry.query.set import All
>>> displayQuery(All(f1))
[1, 2, 3, 4, 5, 6, 7]

Now do a a 'any of' query, which returns all documents that
contain any of the values listed::

Expand Down Expand Up @@ -306,6 +321,11 @@ And catalog them now:
>>> for entry in content:
... catalog.index_doc(intid.register(entry), entry)

We query for all indexes objects::

>>> f1 = ('catalog1', 'f1')
>>> displayQuery(value.All(f1))
[1, 2, 3, 4, 5, 6]

Let's now query for all objects where ``f1`` equals 'a':

Expand Down
6 changes: 6 additions & 0 deletions src/hurry/query/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def getIndex(self, context):
return index


class All(SetTerm):

def apply(self, context=None):
return self.getIndex(context).apply({'any': None})


class AnyOf(SetTerm):

def __init__(self, index_id, values):
Expand Down
2 changes: 1 addition & 1 deletion src/hurry/query/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$Id$
"""
import unittest
from zope.testing import doctest
import doctest

def test_suite():
return unittest.TestSuite((
Expand Down
6 changes: 6 additions & 0 deletions src/hurry/query/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def apply(self, context=None):
return index.apply({'any_of': values})


class All(ValueTerm):

def apply(self, context=None):
return self.getIndex(context).apply({'any': None})


class Between(ValueTerm):

def __init__(self, index_id, min_value=None, max_value=None,
Expand Down

0 comments on commit 003455d

Please sign in to comment.