Skip to content

Commit

Permalink
Merge 84c6e3b into 6b5c42d
Browse files Browse the repository at this point in the history
  • Loading branch information
JD Cumpson committed Aug 1, 2016
2 parents 6b5c42d + 84c6e3b commit 704a58d
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions txmongo/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ def GEOHAYSTACK(keys):
return _direction(keys, "geoHaystack")


def TEXT(keys):
"""
Text-based index
https://docs.mongodb.com/manual/core/index-text/
"""
return _direction(keys, "text")


class _QueryFilter(defaultdict):

ALLOWED_DIRECTIONS = (1, -1, '2d', '2dsphere', 'geoHaystack', 'text',)

def __init__(self):
defaultdict.__init__(self, lambda: ())

Expand All @@ -68,12 +79,15 @@ def _index_document(self, operation, index_list):
assert isinstance(index_list, (list, tuple))
for key, direction in index_list:
if not isinstance(key, (bytes, unicode)):
raise TypeError("TxMongo: invalid {0}ing key '{1}'".format(name, repr(key)))
if direction not in (1, -1, "2d", "2dsphere", "geoHaystack"):
raise TypeError("TxMongo invalid {0}ing direction '{1}'".format(name, direction))
raise TypeError("TxMongo: invalid {0}ing key '{1}'"
.format(name, repr(key)))
if direction not in self.__class__.ALLOWED_DIRECTIONS:
raise TypeError("TxMongo invalid {0}ing direction '{1}'"
.format(name, direction))
self[operation] += tuple(((key, direction),))
except Exception:
raise TypeError("TxMongo: invalid list of keys for {0}, {1}".format(name, repr(index_list)))
raise TypeError("TxMongo: invalid list of keys for {0}, {1}"
.format(name, repr(index_list)))

def __repr__(self):
return "<mongodb QueryFilter: %s>" % dict.__repr__(self)
Expand Down

0 comments on commit 704a58d

Please sign in to comment.