Skip to content
This repository has been archived by the owner on Sep 19, 2019. It is now read-only.

Fix comparison operators #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/mango_selector_text.erl
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,26 @@ make_field(Path, Arg) ->


range(lt, Arg) ->
[<<"[-Infinity TO ">>, value_str(Arg), <<"}">>];
Min = get_range(min, Arg),
[<<"[", Min/binary, " TO ">>, value_str(Arg), <<"}">>];
range(lte, Arg) ->
[<<"[-Infinity TO ">>, value_str(Arg), <<"]">>];
Min = get_range(min, Arg),
[<<"[", Min/binary, " TO ">>, value_str(Arg), <<"]">>];
range(gte, Arg) ->
[<<"[">>, value_str(Arg), <<" TO Infinity]">>];
Max = get_range(max, Arg),
[<<"[">>, value_str(Arg), <<" TO ", Max/binary, "]">>];
range(gt, Arg) ->
[<<"{">>, value_str(Arg), <<" TO Infinity]">>].
Max = get_range(max, Arg),
[<<"{">>, value_str(Arg), <<" TO ", Max/binary, "]">>].

get_range(min, Arg) when is_number(Arg) ->
<<"-Infinity">>;
get_range(min, _Arg) ->
<<"\"\"">>;
get_range(max, Arg) when is_number(Arg) ->
<<"Infinity">>;
get_range(max, _Arg) ->
<<"\u0x10FFFF">>.


field_exists_query(Path) ->
Expand Down
16 changes: 16 additions & 0 deletions test/06-basic-text-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def test_lt(self):
for d in docs:
assert d["user_id"] in (1, 7, 9)

docs = self.db.find({"company": {"$lt": "Dreamia"}})
assert len(docs) == 1
assert docs[0]["company"] == "Affluex"

def test_lte(self):
docs = self.db.find({"age": {"$lte": 21}})
assert len(docs) == 0
Expand All @@ -92,6 +96,11 @@ def test_lte(self):
for d in docs:
assert d["user_id"] in (1, 7, 9)

docs = self.db.find({"company": {"$lte": "Dreamia"}})
assert len(docs) == 2
for d in docs:
assert d["user_id"] in (0, 11)

def test_eq(self):
docs = self.db.find({"age": 21})
assert len(docs) == 0
Expand Down Expand Up @@ -132,6 +141,9 @@ def test_gt(self):
docs = self.db.find({"age": {"$gt": 79}})
assert len(docs) == 0

docs = self.db.find({"company": {"$gt": "Zialactic"}})
assert len(docs) == 0

def test_gte(self):
docs = self.db.find({"age": {"$gte": 77}})
assert len(docs) == 2
Expand All @@ -150,6 +162,10 @@ def test_gte(self):
docs = self.db.find({"age": {"$gte": 80}})
assert len(docs) == 0

docs = self.db.find({"company": {"$gte": "Zialactic"}})
assert len(docs) == 1
assert docs[0]["company"] == "Zialactic"

def test_and(self):
docs = self.db.find({"age": 22, "manager": True})
assert len(docs) == 1
Expand Down