nickva commented on a change in pull request #775: Add selector support to json 
indexes
URL: https://github.com/apache/couchdb/pull/775#discussion_r135285709
 
 

 ##########
 File path: src/mango/src/mango_selector.erl
 ##########
 @@ -566,3 +567,16 @@ match({[{Field, Cond}]}, Value, Cmp) ->
 
 match({[_, _ | _] = _Props} = Sel, _Value, _Cmp) ->
     erlang:error({unnormalized_selector, Sel}).
+
+
+% We could get fancier here later with checking what kind of subset it is
+% e.g. if a selector is {age: {"$gte": 5}} and a query is
+% {age: {"$gte": 10}} we could say that is is a subset
+is_subset({[{<<"$and">>, Args}]}, Selector2) ->
+    Pred = fun(Selector1) -> is_subset(Selector1, Selector2) end,
+    lists:all(Pred, Args);
+is_subset(Selector1, {[{<<"$and">>, Args}]}) ->
+    Pred = fun(Selector2) -> is_subset(Selector1, Selector2) end,
+    lists:any(Pred, Args);
+is_subset({Selector1}, {Selector2}) ->    
+    sets:is_subset(sets:from_list(Selector1), sets:from_list(Selector2)).
 
 Review comment:
   Nice use of sets here ? 
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to