Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

NarySetOp -> BoolOp

  • Loading branch information...
commit 12b0052fa6057bb3d5d389d631d4b21bbfcf852c 1 parent 85f2325
Chris Rossi authored
View
6 benchmark/intersection.py
@@ -56,12 +56,12 @@
from repoze.catalog.catalog import FileStorageCatalogFactory
from repoze.catalog.indexes.field import CatalogFieldIndex
from repoze.catalog.query import Eq
-from repoze.catalog.query import SetOp
+from repoze.catalog.query import BoolOp
_marker = object()
random.seed()
-class Intersection1(SetOp):
+class Intersection1(BoolOp):
"""
Total cost: O(log(nk2, oob) + max(n1, nd2/nk2))
"""
@@ -77,7 +77,7 @@ def apply(self, catalog):
_, results = self.family.IF.weightedIntersection(left, right)
return results
-class Intersection2(SetOp):
+class Intersection2(BoolOp):
"""
Implements algorithm2 above. In real life we wouldn't do this in the
Intersection operator--we'd do it in the apply_intersection() of the index
View
3  docs/overview.rst
@@ -138,8 +138,7 @@ a generator) is a sequence of document ids that match the query.
You can combine search parameters to further limit a query::
from repoze.catalog.query import Contains, Eq, Intersection
- catalog.query(Intersection(Eq('flavor', 'peach'),
- Contains('description', 'nuts')))
+ catalog.query(Eq('flavor', 'peach') & Contains('description', 'nuts'))
This would return a result representing all the documents indexed
within the catalog with the flavor of peach and a description of nuts.
View
24 docs/usage.rst
@@ -35,7 +35,7 @@ index, ``text``, is a :term:`text index`.
.. literalinclude:: code/index_attributes.py
:linenos:
:language: python
-
+
Here's a more complicated example. It uses callbacks to adapt
cataloged objects to values rather than directly inspecting attributes
of the content object. We use the same types of indexes as the
@@ -47,7 +47,7 @@ have attributes that match exactly what you want to index:
.. literalinclude:: code/index_callbacks.py
:linenos:
:language: python
-
+
Searching
---------
@@ -69,11 +69,11 @@ number of arguments:
The name of the index used to sort the results.
``limit``
- Limit the number of results returned to this argument, which should be
+ Limit the number of results returned to this argument, which should be
an integer. This is only used if ``sort_index`` is also specified.
``reverse``
- Reverse the order of the result sequence if this is ``True``. Only used
+ Reverse the order of the result sequence if this is ``True``. Only used
if ``sort_index`` is also specified.
For example::
@@ -90,7 +90,7 @@ For example::
The results of the above search will search the corpus for documents
which have a result in the ``flavor`` index that matches the value
-``peach``.
+``peach``.
The :meth:`repoze.catalog.Catalog.query` method will return a
two-tuple, with the first element in the sequence being the length of
@@ -111,7 +111,7 @@ to its constituent content.
will always be of a particular type, and *not* always sliceable;
for example it may be a generator.
-You can also combine query objects, using set operations, to search
+You can also combine query objects, using boolean operations, to search
multiple indexes:
.. code-block:: python
@@ -124,7 +124,7 @@ multiple indexes:
manager = ConnectionManager()
catalog = factory(manager)
numdocs, results = catalog.query(
- Intersection(Eq('flavors', 'peach'), Eq('texts', 'nutty')))
+ Eq('flavors', 'peach') & Eq('texts', 'nutty'))
print (numdocs, [ x for x in results ])
The results of the above search will return the following::
@@ -141,7 +141,7 @@ used as a sort index::
from repoze.catalog.query import Range
numdocs, results = catalog.query(
- Range('flavors', 'peach', 'pistachio'),
+ Range('flavors', 'peach', 'pistachio'),
sort_index='flavors')
print (numdocs, [ x for x in results ])
@@ -155,7 +155,7 @@ The default sort order is ascending. You can reverse the sort using
from repoze.catalog.query import Range
numdocs, results = catalog.query(
- Range('flavors', 'peach', 'pistachio'),
+ Range('flavors', 'peach', 'pistachio'),
sort_index='flavors',
reverse=True)
print (numdocs, [ x for x in results ])
@@ -240,7 +240,7 @@ resolved using a dict passed into
author = request.params.get("author")
word = request.params.get("search_term")
- query = mycatalog.query("author == author and word in body",
+ query = mycatalog.query("author == author and word in body",
names=locals())
Unlike true Python expressions, ordering of the terms in a CQE
@@ -513,7 +513,7 @@ The default sort order is ascending. You can reverse the sort using
``reverse``::
numdocs, results = catalog.search(flavors=('peach', 'pistachio'),
- sort_index='flavors',
+ sort_index='flavors',
reverse=True)
print (numdocs, [ x for x in results ])
(2, [2, 1])
@@ -524,7 +524,7 @@ number of results you want. Note that this parameter has no effect if
you do not supply a ``sort_index``::
numdocs, results = catalog.search(flavors=('peach', 'pistachio'),
- sort_index='flavors',
+ sort_index='flavors',
limit=1)
print (numdocs, [ x for x in results ])
(1, [1])
View
10 repoze/catalog/query.py
@@ -345,7 +345,7 @@ def negate(self):
self.start_exclusive, self.end_exclusive)
-class NarySetOp(Query):
+class BoolOp(Query):
"""
Base class for Or and And operators which can have N arguments.
"""
@@ -420,7 +420,7 @@ def _optimize_not_eq(self):
return NotAny(index_name, values)
-class Or(NarySetOp):
+class Or(BoolOp):
"""Or of two result sets."""
def apply(self, catalog):
# XXX Try to figure out when we need weightedOr and when we can
@@ -440,7 +440,7 @@ def negate(self):
return And(*neg_args)
def _optimize(self):
- new_self = NarySetOp._optimize(self)
+ new_self = BoolOp._optimize(self)
if self is not new_self:
return new_self
@@ -483,7 +483,7 @@ def process_range(i_lower, arg_lower, i_upper, arg_upper):
return self
-class And(NarySetOp):
+class And(BoolOp):
"""And of two result sets."""
def apply(self, catalog):
# XXX Try to figure out when we need weightedIntersection and when we
@@ -505,7 +505,7 @@ def negate(self):
return Or(*neg_args)
def _optimize(self):
- new_self = NarySetOp._optimize(self)
+ new_self = BoolOp._optimize(self)
if self is not new_self:
return new_self
View
12 repoze/catalog/tests/test_query.py
@@ -450,14 +450,14 @@ def test_not_equal_to_another_type(self):
self.assertNotEqual(inst, object())
-class SetOpTestBase(unittest.TestCase):
+class BoolOpTestBase(unittest.TestCase):
def _makeOne(self, left, right):
return self._getTargetClass()(left, right)
-class TestNarySetOp(SetOpTestBase):
+class TestBoolOp(BoolOpTestBase):
def _getTargetClass(self):
- from repoze.catalog.query import NarySetOp as cls
+ from repoze.catalog.query import BoolOp as cls
return cls
def test_iter_children(self):
@@ -468,7 +468,7 @@ class Dummy(object):
self.assertEqual(list(o.iter_children()), [left, right])
-class TestOr(SetOpTestBase):
+class TestOr(BoolOpTestBase):
def _getTargetClass(self):
from repoze.catalog.query import Or as cls
return cls
@@ -519,7 +519,7 @@ def test_negate(self):
self.failUnless(right.negated)
-class TestAnd(SetOpTestBase):
+class TestAnd(BoolOpTestBase):
def _getTargetClass(self):
from repoze.catalog.query import And as cls
return cls
@@ -570,7 +570,7 @@ def test_negate(self):
self.failUnless(right.negated)
-class TestNot(SetOpTestBase):
+class TestNot(BoolOpTestBase):
def _makeOne(self, query):
from repoze.catalog.query import Not as cls
Please sign in to comment.
Something went wrong with that request. Please try again.