couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject [14/50] [abbrv] couchdb-mango git commit: Add Array Support For $in Operator
Date Tue, 03 Feb 2015 15:13:21 GMT
Add Array Support For $in Operator

- Compare elements correctly when field value is an array.
- 38863-in-operator-arrays


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mango/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mango/commit/2d0cd0cf
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mango/tree/2d0cd0cf
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mango/diff/2d0cd0cf

Branch: refs/heads/master
Commit: 2d0cd0cf36324739acbd93cd00e17f5c95e40521
Parents: 3bcd514
Author: Tony Sun <llamage@Tonys-MacBook-Pro.local>
Authored: Tue Nov 4 15:55:28 2014 -0800
Committer: Tony Sun <llamage@Tonys-MacBook-Pro.local>
Committed: Tue Nov 4 16:00:01 2014 -0800

----------------------------------------------------------------------
 src/mango_selector.erl | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/2d0cd0cf/src/mango_selector.erl
----------------------------------------------------------------------
diff --git a/src/mango_selector.erl b/src/mango_selector.erl
index 06c3550..d392abe 100644
--- a/src/mango_selector.erl
+++ b/src/mango_selector.erl
@@ -651,6 +651,11 @@ match({[{<<"$gte">>, Arg}]}, Value, Cmp) ->
 match({[{<<"$gt">>, Arg}]}, Value, Cmp) ->
     Cmp(Value, Arg) > 0;
 
+match({[{<<"$in">>, Args}]}, Values, Cmp) when is_list(Values)->
+    Pred = fun(Arg) -> lists:foldl(fun(Value,Match) ->
+        (Cmp(Value, Arg) == 0) or Match end, false, Values)
+    end,
+    lists:any(Pred, Args);
 match({[{<<"$in">>, Args}]}, Value, Cmp) ->
     Pred = fun(Arg) -> Cmp(Value, Arg) == 0 end,
     lists:any(Pred, Args);


Mime
View raw message