{ "info": { "author": "Infrae", "author_email": "faassen@startifact.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Zope3", "Intended Audience :: Developers", "License :: OSI Approved :: Zope Public License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Internet :: WWW/HTTP" ], "description": "Hurry Query\n===========\n\nThe hurry query system for the zope.catalog builds on its catalog\nindexes, as well as the indexes in zc.catalog. It is in part inspired\nby AdvancedQuery for Zope 2 by Dieter Maurer, though has an independent\norigin.\n\n.. contents::\n\nSetup\n-----\n\nLet's define a simple content object. First its interface::\n\n >>> from zope.interface import Interface, Attribute, implementer\n >>> class IContent(Interface):\n ... f1 = Attribute('f1')\n ... f2 = Attribute('f2')\n ... f3 = Attribute('f3')\n ... f4 = Attribute('f4')\n ... t1 = Attribute('t1')\n ... t2 = Attribute('t2')\n\nAnd its implementation::\n\n >>> import functools\n >>> from zope.container.contained import Contained\n >>> @functools.total_ordering\n ... @implementer(IContent)\n ... class Content(Contained):\n ... def __init__(self, id, f1='', f2='', f3='', f4='', t1='', t2=''):\n ... self.id = id\n ... self.f1 = f1\n ... self.f2 = f2\n ... self.f3 = f3\n ... self.f4 = f4\n ... self.t1 = t1\n ... self.t2 = t2\n ... def __lt__(self, other):\n ... return self.id < other.id\n ... def __eq__(self, other):\n ... return self.id == other.id\n ... def __repr__(self):\n ... return '<Content "{}">'.format(self.id)\n\nThe id attribute is just so we can identify objects we find again\neasily. By including the __cmp__ method we make sure search results\ncan be stably sorted.\n\nWe use a fake int id utility here so we can test independent of\nthe full-blown zope environment::\n\n >>> from zope import interface\n >>> import zope.intid.interfaces\n >>> @interface.implementer(zope.intid.interfaces.IIntIds)\n ... class DummyIntId(object):\n ... MARKER = '__dummy_int_id__'\n ... def __init__(self):\n ... self.counter = 0\n ... self.data = {}\n ... def register(self, obj):\n ... intid = getattr(obj, self.MARKER, None)\n ... if intid is None:\n ... setattr(obj, self.MARKER, self.counter)\n ... self.data[self.counter] = obj\n ... intid = self.counter\n ... self.counter += 1\n ... return intid\n ... def getId(self, obj):\n ... return getattr(obj, self.MARKER)\n ... def getObject(self, intid):\n ... return self.data[intid]\n ... def __iter__(self):\n ... return iter(self.data)\n >>> intid = DummyIntId()\n >>> from zope.component import provideUtility\n >>> provideUtility(intid, zope.intid.interfaces.IIntIds)\n\nNow let's register a catalog::\n\n >>> from zope.catalog.interfaces import ICatalog\n >>> from zope.catalog.catalog import Catalog\n >>> catalog = Catalog()\n >>> provideUtility(catalog, ICatalog, 'catalog1')\n\nAnd set it up with various indexes::\n\n >>> from zope.catalog.field import FieldIndex\n >>> from zope.catalog.text import TextIndex\n >>> catalog['f1'] = FieldIndex('f1', IContent)\n >>> catalog['f2'] = FieldIndex('f2', IContent)\n >>> catalog['f3'] = FieldIndex('f3', IContent)\n >>> catalog['f4'] = FieldIndex('f4', IContent)\n >>> catalog['t1'] = TextIndex('t1', IContent)\n >>> catalog['t2'] = TextIndex('t2', IContent)\n\nNow let's create some objects so that they'll be cataloged::\n\n >>> content = [\n ... Content(1, 'a', 'b', 'd'),\n ... Content(2, 'a', 'c'),\n ... Content(3, 'X', 'c'),\n ... Content(4, 'a', 'b', 'e'),\n ... Content(5, 'X', 'b', 'e'),\n ... Content(6, 'Y', 'Z')]\n\nAnd catalog them now::\n\n >>> for entry in content:\n ... catalog.index_doc(intid.register(entry), entry)\n\nNow let's register a query utility::\n\n >>> from hurry.query.query import Query\n >>> from hurry.query.interfaces import IQuery\n >>> provideUtility(Query(), IQuery)\n\nSet up some code to make querying and display the result\neasy::\n\n >>> from zope.component import getUtility\n >>> from hurry.query.interfaces import IQuery\n >>> def displayQuery(q, context=None):\n ... query = getUtility(IQuery)\n ... r = query.searchResults(q, context)\n ... return [e.id for e in sorted(list(r))]\n\nFieldIndex Queries\n------------------\n\nWe can query for all objects indexed in this index::\n\n >>> from hurry.query import All\n >>> f1 = ('catalog1', 'f1')\n >>> displayQuery(All(f1))\n [1, 2, 3, 4, 5, 6]\n\nNow for a query where f1 equals a::\n\n >>> from hurry.query import Eq\n >>> f1 = ('catalog1', 'f1')\n >>> displayQuery(Eq(f1, 'a'))\n [1, 2, 4]\n\nNot equals (this is more efficient than the generic ~ operator)::\n\n >>> from hurry.query import NotEq\n >>> displayQuery(NotEq(f1, 'a'))\n [3, 5, 6]\n\nTesting whether a field is in a set::\n\n >>> from hurry.query import In\n >>> displayQuery(In(f1, ['a', 'X']))\n [1, 2, 3, 4, 5]\n\nWhether documents are in a specified range::\n\n >>> from hurry.query import Between\n >>> displayQuery(Between(f1, 'X', 'Y'))\n [3, 5, 6]\n\nYou can leave out one end of the range::\n\n >>> displayQuery(Between(f1, 'X', None)) # 'X' < 'a'\n [1, 2, 3, 4, 5, 6]\n >>> displayQuery(Between(f1, None, 'X'))\n [3, 5]\n\nYou can also use greater-equals and lesser-equals for the same purpose::\n\n >>> from hurry.query import Ge, Le\n >>> displayQuery(Ge(f1, 'X'))\n [1, 2, 3, 4, 5, 6]\n >>> displayQuery(Le(f1, 'X'))\n [3, 5]\n\nIt's also possible to use not with the ~ operator::\n\n >>> displayQuery(~Eq(f1, 'a'))\n [3, 5, 6]\n\nUsing and (&)::\n\n >>> f2 = ('catalog1', 'f2')\n >>> displayQuery(Eq(f1, 'a') & Eq(f2, 'b'))\n [1, 4]\n\nUsing or (|)::\n\n >>> displayQuery(Eq(f1, 'a') | Eq(f2, 'b'))\n [1, 2, 4, 5]\n\nThese can be chained::\n\n >>> displayQuery(Eq(f1, 'a') & Eq(f2, 'b') & Between(f1, 'a', 'b'))\n [1, 4]\n >>> displayQuery(Eq(f1, 'a') | Eq(f1, 'X') | Eq(f2, 'b'))\n [1, 2, 3, 4, 5]\n\nAnd nested::\n\n >>> displayQuery((Eq(f1, 'a') | Eq(f1, 'X')) & (Eq(f2, 'b') | Eq(f2, 'c')))\n [1, 2, 3, 4, 5]\n\n"and" and "or" can also be spelled differently::\n\n >>> from hurry.query import And, Or\n >>> displayQuery(And(Eq(f1, 'a'), Eq(f2, 'b')))\n [1, 4]\n >>> displayQuery(Or(Eq(f1, 'a'), Eq(f2, 'b')))\n [1, 2, 4, 5]\n\nCombination of In and &\n-----------------------\n\nA combination of 'In' and '&'::\n\n >>> displayQuery(In(f1, ['a', 'X', 'Y', 'Z']))\n [1, 2, 3, 4, 5, 6]\n >>> displayQuery(In(f1, ['Z']))\n []\n >>> displayQuery(In(f1, ['a', 'X', 'Y', 'Z']) & In(f1, ['Z']))\n []\n\n\nSetIndex queries\n----------------\n\nThe SetIndex is defined in zc.catalog.\n\n >>> from hurry.query import set\n\nLet's make a catalog which uses it::\n\n >>> intid = DummyIntId()\n >>> provideUtility(intid, zope.intid.interfaces.IIntIds)\n >>> from zope.catalog.interfaces import ICatalog\n >>> from zope.catalog.catalog import Catalog\n >>> catalog = Catalog()\n >>> provideUtility(catalog, ICatalog, 'catalog1')\n >>> from zc.catalog.catalogindex import SetIndex\n >>> catalog['f1'] = SetIndex('f1', IContent)\n >>> catalog['f2'] = FieldIndex('f2', IContent)\n\nFirst let's set up some new data::\n\n >>> content = [\n ... Content(1, ['a', 'b', 'c'], 1),\n ... Content(2, ['a'], 1),\n ... Content(3, ['b'], 1),\n ... Content(4, ['c', 'd'], 2),\n ... Content(5, ['b', 'c'], 2),\n ... Content(6, ['a', 'c'], 2),\n ... Content(7, ['z'], 2),\n ... Content(8, [], 2)] # no value, so not indexed.\n\nAnd catalog them now::\n\n >>> for entry in content:\n ... catalog.index_doc(intid.register(entry), entry)\n\nWe can query for all indexes objects:\n\n >>> displayQuery(set.All(f1))\n [1, 2, 3, 4, 5, 6, 7]\n\nNow do a a 'any of' query, which returns all documents that\ncontain any of the values listed::\n\n >>> displayQuery(set.AnyOf(f1, ['a', 'c']))\n [1, 2, 4, 5, 6]\n >>> displayQuery(set.AnyOf(f1, ['c', 'b']))\n [1, 3, 4, 5, 6]\n >>> displayQuery(set.AnyOf(f1, ['a']))\n [1, 2, 6]\n\nDo a 'all of' query, which returns all documents that\ncontain all of the values listed::\n\n >>> displayQuery(set.AllOf(f1, ['a']))\n [1, 2, 6]\n >>> displayQuery(set.AllOf(f1, ['a', 'b']))\n [1]\n >>> displayQuery(set.AllOf(f1, ['a', 'c']))\n [1, 6]\n\nThe next interesting set of queries allows you to make evaluations of the\nvalues. For example, you can ask for all objects between a certain set of\nvalues:\n\n >>> displayQuery(set.SetBetween(f1, 'a', 'c'))\n [1, 2, 3, 4, 5, 6]\n\n >>> displayQuery(set.SetBetween(f1, 'a', 'c', exclude_min=True))\n [1, 3, 4, 5, 6]\n\n >>> displayQuery(set.SetBetween(f1, 'b', 'c', exclude_max=True))\n [1, 3, 5]\n\n >>> displayQuery(set.SetBetween(f1, 'a', 'c',\n ... exclude_min=True, exclude_max=True))\n [1, 3, 5]\n\nYou can also leave out one end of the range:\n\n >>> displayQuery(set.SetBetween(f1, 'c', None))\n [1, 4, 5, 6, 7]\n >>> displayQuery(set.SetBetween(f1, None, 'c', exclude_max=True))\n [1, 2, 3, 5, 6]\n\nYou can chain set queries:\n\n >>> displayQuery(set.AnyOf(f1, ['a']) & Eq(f2, 1))\n [1, 2]\n\nThe ``set` module also supports ``zc.catalog`` extents. The first query is\n``ExtentAny``, which returns all douments matching the extent. If the the\nextent is ``None``, all document ids are returned:\n\n >>> displayQuery(set.ExtentAny(f1, None))\n [1, 2, 3, 4, 5, 6, 7]\n\nIf we now create an extent that is only in the scope of the first four\ndocuments,\n\n >>> from zc.catalog.extentcatalog import FilterExtent\n >>> extent = FilterExtent(lambda extent, uid, obj: True)\n >>> for i in range(4):\n ... extent.add(i, i)\n\nthen only the first four are returned:\n\n >>> displayQuery(set.ExtentAny(f1, extent))\n [1, 2, 3, 4]\n\nThe opposite query is the ``ExtentNone`` query, which returns all ids in the\nextent that are *not* in the index:\n\n >>> id = intid.register(Content(9, 'b'))\n >>> id = intid.register(Content(10, 'c'))\n >>> id = intid.register(Content(11, 'a'))\n\n >>> extent = FilterExtent(lambda extent, uid, obj: True)\n >>> for i in range(11):\n ... extent.add(i, i)\n\n >>> displayQuery(set.ExtentNone(f1, extent))\n [8, 9, 10, 11]\n\n\nValueIndex queries\n------------------\n\nThe ``ValueIndex`` is defined in ``zc.catalog`` and provides a generalization\nof the standard field index.\n\n >>> from hurry.query import value\n\nLet's set up a catalog that uses this index. The ``ValueIndex`` is defined in\n``zc.catalog``. Let's make a catalog which uses it:\n\n >>> intid = DummyIntId()\n >>> provideUtility(intid, zope.intid.interfaces.IIntIds)\n\n >>> from zope.catalog.interfaces import ICatalog\n >>> from zope.catalog.catalog import Catalog\n >>> catalog = Catalog()\n >>> provideUtility(catalog, ICatalog, 'catalog1')\n\n >>> from zc.catalog.catalogindex import ValueIndex\n >>> catalog['f1'] = ValueIndex('f1', IContent)\n\nNext we set up some content data to fill the indices:\n\n >>> content = [\n ... Content(1, 'a'),\n ... Content(2, 'b'),\n ... Content(3, 'c'),\n ... Content(4, 'd'),\n ... Content(5, 'c'),\n ... Content(6, 'a')]\n\nAnd catalog them now:\n\n >>> for entry in content:\n ... catalog.index_doc(intid.register(entry), entry)\n\nWe query for all indexes objects::\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayQuery(value.All(f1))\n [1, 2, 3, 4, 5, 6]\n\nLet's now query for all objects where ``f1`` equals 'a':\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayQuery(value.Eq(f1, 'a'))\n [1, 6]\n\nNext, let's find all objects where ``f1`` does not equal 'a'; this is more\nefficient than the generic ``~`` operator:\n\n >>> displayQuery(value.NotEq(f1, 'a'))\n [2, 3, 4, 5]\n\nIf all the items in the catalog satisfy the NotEq condition, the query\ndoes not crash.\n\n >>> displayQuery(value.NotEq(f1, 'z'))\n [1, 2, 3, 4, 5, 6]\n\nYou can also query for all objects where the value of ``f1`` is in a set of\nvalues:\n\n >>> displayQuery(value.In(f1, ['a', 'd']))\n [1, 4, 6]\n\nThe next interesting set of queries allows you to make evaluations of the\nvalues. For example, you can ask for all objects between a certain set of\nvalues:\n\n >>> displayQuery(value.Between(f1, 'a', 'c'))\n [1, 2, 3, 5, 6]\n\n >>> displayQuery(value.Between(f1, 'a', 'c', exclude_min=True))\n [2, 3, 5]\n\n >>> displayQuery(value.Between(f1, 'a', 'c', exclude_max=True))\n [1, 2, 6]\n\n >>> displayQuery(value.Between(f1, 'a', 'c',\n ... exclude_min=True, exclude_max=True))\n [2]\n\nYou can also leave out one end of the range:\n\n >>> displayQuery(value.Between(f1, 'c', None))\n [3, 4, 5]\n >>> displayQuery(value.Between(f1, None, 'c'))\n [1, 2, 3, 5, 6]\n\nYou can also use greater-equals and lesser-equals for the same purpose:\n\n >>> displayQuery(value.Ge(f1, 'c'))\n [3, 4, 5]\n >>> displayQuery(value.Le(f1, 'c'))\n [1, 2, 3, 5, 6]\n\nYou can chain value queries:\n\n >>> displayQuery(value.Ge(f1, 'c') & value.Le(f1, 'c'))\n [3, 5]\n\nThe ``value`` module also supports ``zc.catalog`` extents. The first query is\n``ExtentAny``, which returns all douments matching the extent. If the the\nextent is ``None``, all document ids are returned:\n\n >>> displayQuery(value.ExtentAny(f1, None))\n [1, 2, 3, 4, 5, 6]\n\nIf we now create an extent that is only in the scope of the first four\ndocuments,\n\n >>> from zc.catalog.extentcatalog import FilterExtent\n >>> extent = FilterExtent(lambda extent, uid, obj: True)\n >>> for i in range(4):\n ... extent.add(i, i)\n\nthen only the first four are returned:\n\n >>> displayQuery(value.ExtentAny(f1, extent))\n [1, 2, 3, 4]\n\nThe opposite query is the ``ExtentNone`` query, which returns all ids in the\nextent that are *not* in the index:\n\n >>> id = intid.register(Content(7, 'b'))\n >>> id = intid.register(Content(8, 'c'))\n >>> id = intid.register(Content(9, 'a'))\n\n >>> extent = FilterExtent(lambda extent, uid, obj: True)\n >>> for i in range(9):\n ... extent.add(i, i)\n\n >>> displayQuery(value.ExtentNone(f1, extent))\n [7, 8, 9]\n\n\nQuerying different indexes\n--------------------------\n\nIt's possible to specify the context when creating a query. This context\ndetermines which index will be searched.\n\nFirst setup a second registry and second catalog and populate it.\n\n >>> catalog2 = Catalog()\n >>> from zope.component.registry import Components\n >>> import zope.component.interfaces\n >>> import zope.interface\n >>> intid1 = DummyIntId()\n >>> @zope.interface.implementer(zope.component.interfaces.IComponentLookup)\n ... class MockSite(object):\n ... def __init__(self):\n ... self.registry = Components('components')\n ... def queryUtility(self, interface, name='', default=None):\n ... if name == '': return intid1\n ... else: return catalog2\n ... def getSiteManager(self):\n ... return self.registry\n >>> from zope.component.hooks import setSite\n >>> site1 = MockSite()\n >>> setSite(site1)\n >>> catalog2['f1'] = FieldIndex('f1', IContent)\n >>> content = [\n ... Content(1,'A'),\n ... Content(2,'B'),]\n >>> for entry in content:\n ... catalog2.index_doc(intid1.register(entry), entry)\n\nNow we can query this catalog by specifying the context:\n\n >>> query = getUtility(IQuery)\n >>> displayQuery(Eq(f1, 'A'), context=site1)\n [1]\n\n >>> displayQuery(In(f1, ['A', 'B']), context=site1)\n [1, 2]\n\nSorting and limiting the results\n--------------------------------\n\nIt's possible to have the resultset sorted on one of the fields in the query.\n\n >>> catalog = Catalog()\n >>> provideUtility(catalog, ICatalog, 'catalog1')\n >>> catalog['f1'] = FieldIndex('f1', IContent)\n >>> catalog['f2'] = FieldIndex('f2', IContent)\n >>> catalog['t'] = TextIndex('t1', IContent)\n\nFirst let's set up some new data::\n\n >>> content = [\n ... Content(1, 'a', 2, t1='Beautiful is better than ugly.'),\n ... Content(2, 'a', 3, t1='Explicit is better than implicit'),\n ... Content(3, 'b', 9, t1='Simple is better than complex'),\n ... Content(4, 'c', 8, t1='Complex is better than complicated'),\n ... Content(5, 'c', 7, t1='Readability counts'),\n ... Content(6, 'a', 1, t1='Although practicality beats purity')]\n\nAnd catalog them now::\n\n >>> for entry in content:\n ... catalog.index_doc(intid.register(entry), entry)\n\nDefine a convenience function for quickly displaying a result set without\nperforming any sorting here ourselves.\n\n >>> def displayResult(q, context=None, **kw):\n ... query = getUtility(IQuery)\n ... r = query.searchResults(q, context, **kw)\n ... return [e for e in r]\n\nWithout using sorting in the query itself, the resultset has an undefined\norder. We "manually" sort the results here to have something testable.\n\n >>> f1 = ('catalog1', 'f1')\n >>> [r for r in sorted(displayResult(Eq(f1, 'a')))]\n [<Content "1">, <Content "2">, <Content "6">]\n\nNow we sort on the f2 index.\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayResult(Eq(f1, 'a'), sort_field=('catalog1', 'f2'))\n [<Content "6">, <Content "1">, <Content "2">]\n\nReverse the order.\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayResult(Eq(f1, 'a'), sort_field=('catalog1', 'f2'), reverse=True)\n [<Content "2">, <Content "1">, <Content "6">]\n\nWe can limit the amount of found items.\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayResult(Eq(f1, 'a'), sort_field=('catalog1', 'f2'), limit=2)\n [<Content "6">, <Content "1">]\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayResult(Eq(f1, 'a'), sort_field=('catalog1', 'f2'), limit=2, start=1)\n [<Content "1">, <Content "2">]\n\nWe can limit the reversed resultset too.\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayResult(\n ... Eq(f1, 'a'), sort_field=('catalog1', 'f2'), limit=2, reverse=True)\n [<Content "2">, <Content "1">]\n\nYou can directly pass the index as a sort field instead of a tuple:\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayResult(Eq(f1, 'a'), sort_field=catalog['f2'])\n [<Content "6">, <Content "1">, <Content "2">]\n\nWhenever a field is used for sorting that does not support is, an error is\nraised.\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayResult(Eq(f1, 'a'), sort_field=('catalog1', 't'))\n Traceback (most recent call last):\n ...\n ValueError: Index t in catalog catalog1 does not support sorting.\n\nThe resultset can still be reversed and limited even if there's no sort_field\ngiven (Note that the actual order of the result set when not using explicit\nsorting is not defined. In this test it is assumed that the natural order of\nthe tested index is deterministic enough to be used as a proper test).\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayResult(Eq(f1, 'a'), limit=2)\n [<Content "1">, <Content "2">]\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayResult(Eq(f1, 'a'), start=1)\n [<Content "2">, <Content "6">]\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayResult(Eq(f1, 'a'), start=1, limit=1)\n [<Content "2">]\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayResult(Eq(f1, 'a'), limit=2, reverse=True)\n [<Content "6">, <Content "2">]\n\nResult counters\n---------------\n\nResult objects provide metadata about the result.\n\nDefine a convenience function for obtaining a result.\n\n >>> def getResult(q, context=None, **kw):\n ... query = getUtility(IQuery)\n ... return query.searchResults(q, context, **kw)\n\nPerforming a query with a sort_field gives a well-defined result:\n\n >>> f1 = ('catalog1', 'f1')\n >>> result = getResult(Eq(f1, 'a'), sort_field=catalog['f1'])\n >>> [e for e in result]\n [<Content "1">, <Content "2">, <Content "6">]\n\nWe can access 'total' and 'count' properties, and 'first()' on the result:\n\n >>> result.total\n 3\n >>> result.count\n 3\n >>> result.first()\n <Content "1">\n\nChanging 'start' is reflected in the returned data:\n\n>>> result = getResult(Eq(f1, 'a'), sort_field=catalog['f1'], start=1)\n >>> [e for e in result]\n [<Content "2">, <Content "6">]\n\nIt also changes 'count' and 'first()':\n\n >>> result.count\n 2\n >>> result.first()\n <Content "2">\n\nBut 'total' still reflects all matches, including the hidden first one:\n\n >>> result.total\n 3\n\nAdding a limit:\n\n >>> result = getResult(Eq(f1, 'a'), sort_field=catalog['f1'], start=1,\n ... limit=1)\n >>> [e for e in result]\n [<Content "2">]\n >>> result.total\n 3\n >>> result.count\n 1\n >>> result.first()\n <Content "2">\n\nThe same accessors are available on an empty result:\n\n >>> result = getResult(Eq(f1, 'foo'), sort_field=catalog['f1'])\n >>> [e for e in result]\n []\n >>> result.total\n 0\n >>> result.count\n 0\n >>> result.first() is None\n True\n\nWrapper\n-------\n\nYou can define a wrapper to be called on each result:\n\n >>> from zope.location import Location\n >>> class Wrapper(Location):\n ... def __init__(self, parent):\n ... self.parent = parent\n ... def __repr__(self):\n ... return '<Wrapper "{}">'.format(self.parent.id)\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayResult(Eq(f1, 'a'), wrapper=Wrapper)\n [<Wrapper "1">, <Wrapper "2">, <Wrapper "6">]\n\nLocate to\n---------\n\nYou can define a location where the results should be located with a proxy:\n\n >>> def displayParent(q, context=None, **kw):\n ... query = getUtility(IQuery)\n ... r = query.searchResults(q, context, **kw)\n ... return [(e.__parent__, e) or None for e in r]\n\n >>> f1 = ('catalog1', 'f1')\n >>> displayParent(Eq(f1, 'a'), limit=2)\n [(None, <Content "1">), (None, <Content "2">)]\n\n >>> parent = Content('parent')\n >>> displayParent(Eq(f1, 'a'), limit=2, locate_to=parent)\n [(<Content "parent">, <Content "1">), (<Content "parent">, <Content "2">)]\n\nThis can be used with a wrapper:\n\n >>> displayParent(Eq(f1, 'a'), limit=2, wrapper=Wrapper, locate_to=parent)\n [(<Content "parent">, <Wrapper "1">), (<Content "parent">, <Wrapper "2">)]\n\nText index\n----------\n\nYou can search on text, here all the items that contains better::\n\n >>> from hurry.query import Text\n >>> t1 = ('catalog1', 't')\n >>> displayResult(Text(t1, 'better'))\n [<Content "1">, <Content "2">, <Content "3">, <Content "4">]\n\nInvalid text query returns an empty results::\n\n >>> displayResult(Text(t1, '?*'))\n []\n\n\nOther terms\n-----------\n\nYou can do differences, here all the items that contains better but do\nhave a as f1::\n\n >>> from hurry.query import Difference\n >>> displayResult(Difference(Text(t1, 'better'), Eq(f1, 'a')))\n [<Content "3">, <Content "4">]\n\n\nThere is a special term that allows to mix objects with catalog\nqueries::\n\n >>> from hurry.query import Objects\n >>> displayResult(Objects(content))\n [<Content "1">, <Content "2">, <Content "3">, <Content "4">, <Content "5">, <Content "6">]\n\nThere is a special term that allows querying objects by intid::\n\n >>> from hurry.query import Ids\n >>> displayResult(Ids())\n []\n\n >>> all_intids = [intid.getId(x) for x in content]\n >>> displayResult(Ids(*all_intids))\n [<Content "1">, <Content "2">, <Content "3">, <Content "4">, <Content "5">, <Content "6">]\n\n >>> odd_intids = [intid.getId(x) for x in content if x.id % 2]\n >>> displayResult(Ids(*odd_intids))\n [<Content "1">, <Content "3">, <Content "5">]\n\n\nCHANGES\n=======\n\n3.1 (2018-08-08)\n----------------\n\n- Add ``Ids`` term that include already known intids in a query.\n\n3.0.0 (2018-01-19)\n------------------\n\n- Support for python 3.4, 3.5 and 3.6 in addition to python 2.7\n\n- Cleanup in preparation for python3 support:\n\n Bugfixes:\n o API change: fix And(weighted=) keyword argument typo\n o API change: remove utterly broken ``include_minimum`` and ``include_maximum``\n arguments to SetBetween(), provide ``exclude_min`` and ``exclude_max`` instead.\n o API change: fix broken SetBetween.apply(): introduce ``cache`` arg\n o Fix ExtentNone() super delegation bug\n o Fix TimingAwareCaching.report() edge condition bug\n\n Major:\n o Remove unsupported transaction_cache\n\n Minor:\n o Clarify HURRY_QUERY_TIMING environment and searchResults(timing=) type\n o Fix TimingAwareCaching.report() output typo\n o Clarify Query.searchResults(caching=) argument type\n o Remove unreachable code path from And()\n\n Dev:\n o Maximize test coverage\n o Add Travis and Tox testing configurations\n o Bypass bootstrap.py\n o Various python3 compatibility preparations\n\n\n2.6 (2018-01-10)\n----------------\n\n- Update dependencies not to rely on ZODB3 anymore.\n\n2.5 (2017-07-17)\n----------------\n\n- `sort_field` can be a index name or an object providing `IIndexSort` itself.\n\n- `searchResults()` accepts optional parameter `locate_to` and `wrapper`. The\n `locate_to` is used as the `__parent__` for the location proxy put arround\n the resulting objects. The `wrapper` is a callable callback that should\n accept one argument for its parameter.\n\n2.4 (2017-06-22)\n----------------\n\n- Don't throw a TypeError slicing unsorted results, fixes #6\n\n2.3 (2017-04-26)\n----------------\n\n- Define a "no result" result object, useful for case where application code\n has an custom API for building query terms, but this application code\n decides there is no query. Callers might still expect a result-like\n object.\n\n2.2 (2017-04-26)\n----------------\n\n- The caching option to searchResults now accepts a dict-like value and it\n will use that to allow for caching results over multiple searchResults()\n calls. The cache invalidation then is the responsibility of the caller.\n\n2.1 (2017-02-07)\n----------------\n\n- Add the possibility to time how long a query takes. It can be\n controlled with the new ``timing`` option to ``searchResults`` or\n the ``HURRY_QUERY_TIMING`` environment variable.\n\n2.0.1 (2016-09-08)\n------------------\n\n- Fix log line in Text term for invalid text search.\n\n2.0 (2016-09-07)\n----------------\n\n- Add new term: Difference. It does a difference between the first and\n the following terms passed as arguments.\n\n- Add new term: Objects. It creates a result out of the objects passed\n in arguments. It let you mix real objects with existing catalog\n queries (with And, Or or Difference for instance).\n\n- Add an option start to searchResult to skip the first results in the\n results set.\n\n- Extend the result from searchResult. You have addition information\n on the result, including the total number of results without\n start/limit restriction. A method called first() return only the\n first result if available or none.\n\n- Add an option caching to searchResult to cache the result of each\n terms within a Zope transaction, speeding similar queries. If\n disabled, terms will still be cached within the same query.\n\n\n1.2 (2015-12-16)\n----------------\n\n* Add support for an All query.\n\n1.1.1 (2012-06-22)\n------------------\n\n* ExtentNone in set.py missed a parameter ``index_id``. Thanks to Danilo\n Botelho for the bug report.\n\n1.1.0 (2010-07-12)\n------------------\n\n* Allow the searchResults method of a Query to take an additional keyword\n argument `sort_field` that defines that defines (catalog_name, index_name) to\n sort on. That index in that catalog should implement IIndexSort.\n\n In addition to this keyword argument, `limit` and `reverse` keyword arguments\n can be passed too, that will limit the sorted resultset and/or reverse its\n order.\n\n* Allow the searchResults method of a Query object to take an additional\n optional context argument. This context will determine which catalog\n the search is performed on.\n\n1.0.0 (2009-11-30)\n------------------\n\n* Refresh dependencies. Use zope.catalog and zope.intid instead of\n zope.app.catalog and zope.app.intid respectively. Don't zope.app.zapi.\n\n* Make package description more modern.\n\n* Clean up the code style.\n\n0.9.3 (2008-09-29)\n------------------\n\n* BUG: NotEq query no longer fails when all values in the index\n satisfy the NotEq condition.\n\n0.9.2 (2006-09-22)\n------------------\n\n* First release on the cheeseshop.\n\n0.9.1 (2006-06-16)\n------------------\n\n* Make zc.catalog a dependency of hurry.query.\n\n0.9 (2006-05-16)\n----------------\n\n* Separate hurry.query from the other hurry packages. Eggification work.\n\n* Support for ValueIndex from zc.catalog.\n\n0.8 (2006-05-01)\n----------------\n\nInitial public release.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/hurry.query", "keywords": "zope zope3 catalog index query", "license": "ZPL 2.1", "maintainer": "", "maintainer_email": "", "name": "hurry.query", "package_url": "https://pypi.org/project/hurry.query/", "platform": "", "project_url": "https://pypi.org/project/hurry.query/", "project_urls": { "Homepage": "http://pypi.python.org/pypi/hurry.query" }, "release_url": "https://pypi.org/project/hurry.query/3.1/", "requires_dist": null, "requires_python": "", "summary": "Higher level query system for the zope.catalog", "version": "3.1" }, "last_serial": 4149306, "releases": { "0.9.2": [ { "comment_text": "", "digests": { "md5": "1a65812bdd91b61df08993028693edd5", "sha256": "23acd85a4c90f171482687dd0814eff273d586b2e3d53ba4e866a30c64f20ba3" }, "downloads": -1, "filename": "hurry.query-0.9.2-py2.4.egg", "has_sig": false, "md5_digest": "1a65812bdd91b61df08993028693edd5", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 15009, "upload_time": "2006-09-22T16:30:24", "url": "https://files.pythonhosted.org/packages/0b/45/9bf61bf0509ddb3f49feea1a32739d080e91ad3ddee042d4402b56c7a219/hurry.query-0.9.2-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "bf415b239fbe370eab368c604a2f4a96", "sha256": "bc55ca80504a1bee85dc7323a8837bf01fa1dbedc42a1b35db1c716ddd2fc501" }, "downloads": -1, "filename": "hurry.query-0.9.2.tar.gz", "has_sig": false, "md5_digest": "bf415b239fbe370eab368c604a2f4a96", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7713, "upload_time": "2006-09-22T16:30:18", "url": "https://files.pythonhosted.org/packages/3e/82/8e95ed2c47f772323ccdacd43ab310f46a848d0bbed49f6acd8c727510db/hurry.query-0.9.2.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "6376819e6a1aff315d1bbca7b5e63790", "sha256": "07b944ddc05774e6171b3632fed967ac1a90fadff6c2c11cb2be5e464f30a1ae" }, "downloads": -1, "filename": "hurry.query-1.0.0.tar.gz", "has_sig": false, "md5_digest": "6376819e6a1aff315d1bbca7b5e63790", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12699, "upload_time": "2009-11-30T17:08:17", "url": "https://files.pythonhosted.org/packages/5f/9d/459d6011a6fa91a8fd93b4447cca8851a5fb1d5d7606d552183e0420f17b/hurry.query-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "e5acf63d8e1ecccc7a9c02a957f05b3f", "sha256": "eff5b70c23038b4d8712268fb4732c9367a380f6a2721508bd1b9d106763327b" }, "downloads": -1, "filename": "hurry.query-1.1.0.tar.gz", "has_sig": false, "md5_digest": "e5acf63d8e1ecccc7a9c02a957f05b3f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17595, "upload_time": "2010-07-12T08:21:24", "url": "https://files.pythonhosted.org/packages/1f/a1/5b8411d1fa14d9a634988d6fbb88d31daafc27fd95ed43be8f9f6ba19027/hurry.query-1.1.0.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "be22c3a1b5247a3536355d084c080a62", "sha256": "8d3742430c51e3d5bf7b4e13c77629f9c23c51aef0cb68d9b71a00ca14ca05f6" }, "downloads": -1, "filename": "hurry.query-1.1.1.tar.gz", "has_sig": false, "md5_digest": "be22c3a1b5247a3536355d084c080a62", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24129, "upload_time": "2012-06-22T15:19:17", "url": "https://files.pythonhosted.org/packages/bf/7c/2bc6f343734a3759b9bcee494941cfce5a8120b37d2b1ee22c7a8422a686/hurry.query-1.1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "9fad10d1f6862f398b971cafe63bc4a7", "sha256": "bdf74ed71b5d2b4950592ed3ed620e621509ac1dd77591ffb88ae1e430761962" }, "downloads": -1, "filename": "hurry.query-1.2.tar.gz", "has_sig": false, "md5_digest": "9fad10d1f6862f398b971cafe63bc4a7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22053, "upload_time": "2015-12-16T16:27:03", "url": "https://files.pythonhosted.org/packages/07/b5/52b869476ba399a972f28cfb492fbb71ea9c424389019fc80da0b78f06fd/hurry.query-1.2.tar.gz" } ], "2.0": [ { "comment_text": "", "digests": { "md5": "161f4dc8348cf7f9ce6b74935e673052", "sha256": "84efbadfd69e2fc029ed8452bc74d91aea792894d680d64df76018f7735adc25" }, "downloads": -1, "filename": "hurry.query-2.0.tar.gz", "has_sig": false, "md5_digest": "161f4dc8348cf7f9ce6b74935e673052", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25219, "upload_time": "2016-09-07T15:00:11", "url": "https://files.pythonhosted.org/packages/73/17/37db379837a160e37771ae43e41aac3d9ac4ce8cb8c48542df1f500f8a2c/hurry.query-2.0.tar.gz" } ], "2.0.1": [ { "comment_text": "", "digests": { "md5": "d526b524610e99fbe59c9de7f8dcf2cd", "sha256": "7d8340f656f2222e0bbfa74d43cbe9c03b2ff3d1dacb0ff754345c012eee3cb8" }, "downloads": -1, "filename": "hurry.query-2.0.1.tar.gz", "has_sig": false, "md5_digest": "d526b524610e99fbe59c9de7f8dcf2cd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25473, "upload_time": "2016-09-08T07:13:58", "url": "https://files.pythonhosted.org/packages/b1/8b/f6c91e7a4c449670cb7ca270af691d80061858c77411085029bc499a2d9c/hurry.query-2.0.1.tar.gz" } ], "2.1": [ { "comment_text": "", "digests": { "md5": "89f5de37268064909b744f4ab1f19c65", "sha256": "7a657accaba74c614d2f1bf7983ad2a21c7282691928af52ebb1e8c3aeff4d95" }, "downloads": -1, "filename": "hurry.query-2.1.tar.gz", "has_sig": false, "md5_digest": "89f5de37268064909b744f4ab1f19c65", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27002, "upload_time": "2017-02-07T08:39:47", "url": "https://files.pythonhosted.org/packages/cb/98/45bc67d0ad110cb038d2285ca0552a725b9e63333e7ee9b09d6d0fdfded8/hurry.query-2.1.tar.gz" } ], "2.2": [ { "comment_text": "", "digests": { "md5": "43d6ab56c1ba063d3c96c03c30791470", "sha256": "13563a2ea8c70cd837007aba7120726b3c0e462597a99245680517ebbb1f103e" }, "downloads": -1, "filename": "hurry.query-2.2.tar.gz", "has_sig": false, "md5_digest": "43d6ab56c1ba063d3c96c03c30791470", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25568, "upload_time": "2017-04-26T09:15:12", "url": "https://files.pythonhosted.org/packages/eb/47/e5596a0db5e5b85ea6f8e8d734719bf6ecec058eccd2fd0f985e9a43cb11/hurry.query-2.2.tar.gz" } ], "2.3": [ { "comment_text": "", "digests": { "md5": "22cf4400a74dd16bc1a3c97572fb363a", "sha256": "07d129ea107ddd7b68b45f248ec64bcad278d3c121d32fb8e96eb716d0016f00" }, "downloads": -1, "filename": "hurry.query-2.3.tar.gz", "has_sig": false, "md5_digest": "22cf4400a74dd16bc1a3c97572fb363a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 26388, "upload_time": "2017-04-26T09:59:22", "url": "https://files.pythonhosted.org/packages/0f/c3/3276944dc439795d8f711b403cab9bd3c1c729117e6b4ed7b7ca190b8154/hurry.query-2.3.tar.gz" } ], "2.4": [ { "comment_text": "", "digests": { "md5": "b5fb3a87a4054c2a9b20c94a47abbeef", "sha256": "9ba2591cd745f3ed309a4a587fe8a872fb99e68fc0d3f473226c86ead1b49c8c" }, "downloads": -1, "filename": "hurry.query-2.4.tar.gz", "has_sig": false, "md5_digest": "b5fb3a87a4054c2a9b20c94a47abbeef", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 26577, "upload_time": "2017-06-22T07:07:29", "url": "https://files.pythonhosted.org/packages/bc/af/edc639cdea624338a75b64e191a29bbc75583efe2a740c63c8972cbfe88e/hurry.query-2.4.tar.gz" } ], "2.5": [ { "comment_text": "", "digests": { "md5": "c459c20cdf355b9c5a6413d06a7f82cd", "sha256": "c28430f7c980f79f36ba0942ecc16335d627203b9ea6d544961bc0eca84ab234" }, "downloads": -1, "filename": "hurry.query-2.5.tar.gz", "has_sig": false, "md5_digest": "c459c20cdf355b9c5a6413d06a7f82cd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29922, "upload_time": "2017-07-17T14:20:46", "url": "https://files.pythonhosted.org/packages/5b/9a/ec686933b6fab0c27dbdbc2a73a481a336d276969ab4dd249ea9f870ee8e/hurry.query-2.5.tar.gz" } ], "2.6": [ { "comment_text": "", "digests": { "md5": "ea8528f500fe9cf7b72b78a3a8b64f39", "sha256": "e04fee7de69b232a098e8d132f62c355410705034fe14412be6e7a152f92e8e8" }, "downloads": -1, "filename": "hurry.query-2.6.tar.gz", "has_sig": false, "md5_digest": "ea8528f500fe9cf7b72b78a3a8b64f39", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 31004, "upload_time": "2018-01-10T13:29:57", "url": "https://files.pythonhosted.org/packages/46/aa/56f3717baa427477e4f7a3bbea5f86a655356aeb2818da4af6f373c7d782/hurry.query-2.6.tar.gz" } ], "3.0.0": [ { "comment_text": "", "digests": { "md5": "e44281fb4174bf681636ed64d9f9b8e0", "sha256": "a7c1a6b2c65e9f3936306630c519b9094291ab16eda9947d1e91d6656376c3c9" }, "downloads": -1, "filename": "hurry.query-3.0.0.tar.gz", "has_sig": false, "md5_digest": "e44281fb4174bf681636ed64d9f9b8e0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 36438, "upload_time": "2018-01-19T12:04:45", "url": "https://files.pythonhosted.org/packages/78/05/7b805e0b6695208c9393f6ec990fed3f4227f9482986522f501f367c02a3/hurry.query-3.0.0.tar.gz" } ], "3.1": [ { "comment_text": "", "digests": { "md5": "193f8d7ab9efbddfddbe6e1ff422d17a", "sha256": "b854d600a054f3071cf9b8eed2f2fd2f91649acaa083a3f02e9f6afaa95ef23f" }, "downloads": -1, "filename": "hurry.query-3.1.tar.gz", "has_sig": false, "md5_digest": "193f8d7ab9efbddfddbe6e1ff422d17a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 35268, "upload_time": "2018-08-08T14:56:25", "url": "https://files.pythonhosted.org/packages/11/d6/d74dce51bfc81a48fc6075b183c49439a5945ebc0a3633f36728b90d169b/hurry.query-3.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "193f8d7ab9efbddfddbe6e1ff422d17a", "sha256": "b854d600a054f3071cf9b8eed2f2fd2f91649acaa083a3f02e9f6afaa95ef23f" }, "downloads": -1, "filename": "hurry.query-3.1.tar.gz", "has_sig": false, "md5_digest": "193f8d7ab9efbddfddbe6e1ff422d17a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 35268, "upload_time": "2018-08-08T14:56:25", "url": "https://files.pythonhosted.org/packages/11/d6/d74dce51bfc81a48fc6075b183c49439a5945ebc0a3633f36728b90d169b/hurry.query-3.1.tar.gz" } ] }