Skip to content

Commit

Permalink
Use set instead of btree. Do not pay attention to values.
Browse files Browse the repository at this point in the history
  • Loading branch information
thefunny42 committed Aug 26, 2016
1 parent f241223 commit 01c83c3
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/hurry/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"""
import itertools

from BTrees.IFBTree import weightedIntersection, union, difference, IFBTree
from BTrees.IFBTree import IFSet
from BTrees.IFBTree import weightedIntersection
from BTrees.IFBTree import union, difference, intersection
from zope.cachedescriptors.property import Lazy
from zope.catalog.field import IFieldIndex
from zope.catalog.interfaces import ICatalog
Expand Down Expand Up @@ -135,8 +137,9 @@ def __invert__(self):

class And(Term):

def __init__(self, *terms):
def __init__(self, *terms, **kwargs):
self.terms = terms
self.weighted = kwargs.get('weigthed', False)

def apply(self, context=None):
results = []
Expand All @@ -148,13 +151,16 @@ def apply(self, context=None):
results.append(r)

if not results:
return IFBTree()
return IFSet()

results.sort()

result = results.pop(0)
for r in results:
_, result = weightedIntersection(result, r)
if self.weighted:
_, result = weightedIntersection(result, r)
else:
result = intersection(result, r)
return result


Expand All @@ -173,7 +179,7 @@ def apply(self, context=None):
results.append(r)

if not results:
return IFBTree()
return IFSet()

result = results.pop(0)
for r in results:
Expand All @@ -198,7 +204,7 @@ def apply(self, context=None):
results.append(r)

if not results:
return IFBTree()
return IFSet()

result = results.pop(0)
for r in results:
Expand All @@ -218,11 +224,7 @@ def _all(self):
# XXX may not work well/be efficient with extentcatalog
# XXX not very efficient in general, better to use internal
# IntIds datastructure but that would break abstraction..
intids = getUtility(IIntIds)
result = IFBTree()
for uid in intids:
result.insert(uid, 0)
return result
return IFSet(uid for uid in getUtility(IIntIds))


class Objects(Term):
Expand All @@ -232,10 +234,7 @@ def __init__(self, objects):

def apply(self, context=None):
get_uid = getUtility(IIntIds, '', context).getId
result = IFBTree()
for uid in {get_uid(o) for o in self.objects}:
result.insert(uid, 0)
return result
return IFSet(get_uid(o) for o in self.objects)


class IndexTerm(Term):
Expand Down Expand Up @@ -346,7 +345,7 @@ def apply(self, context=None):

if not results:
# no applicable terms at all
return IFBTree()
return IFSet()

result = results.pop(0)
for r in results:
Expand Down

0 comments on commit 01c83c3

Please sign in to comment.