couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject [42/50] [abbrv] couchdb-mango git commit: Introduce the $text operator to mango_selector
Date Tue, 03 Feb 2015 15:13:49 GMT
Introduce the $text operator to mango_selector

This just allows us to handle the $text operator in a selector. There is
a bit of a subtlety in that we apply the $text operator against a field
called $default which looks like an operator. We do this becaus the
query syntax for $text doesn't include a field which confuses a bit of
our other logic which always expects a field name to be present.

BugzId: 33294


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

Branch: refs/heads/master
Commit: 8f3b355dc5ffac849aa458ef69aecfa0287c43c4
Parents: 1b0426a
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Fri Jan 9 15:49:36 2015 -0600
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Fri Jan 16 13:32:50 2015 -0600

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


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/8f3b355d/src/mango_selector.erl
----------------------------------------------------------------------
diff --git a/src/mango_selector.erl b/src/mango_selector.erl
index dd16bf5..4da394d 100644
--- a/src/mango_selector.erl
+++ b/src/mango_selector.erl
@@ -132,6 +132,19 @@ norm_ops({[{<<"$size">>, Arg}]}) when is_integer(Arg), Arg
>= 0 ->
 norm_ops({[{<<"$size">>, Arg}]}) ->
     ?MANGO_ERROR({bad_arg, '$size', Arg});
 
+norm_ops({[{<<"$text">>, Arg}]}) when is_binary(Arg); is_number(Arg);
+        is_boolean(Arg) ->
+    {[{<<"$default">>, {[{<<"$text">>, Arg}]}}]};
+norm_ops({[{<<"$text">>, Arg}]}) ->
+    ?MANGO_ERROR({bad_arg, '$text', Arg});
+
+% Not technically an operator but we pass it through here
+% so that this function accepts its own output. This exists
+% so that $text can have a field name value which simplifies
+% logic elsewhere.
+norm_ops({[{<<"$default">>, _}]} = Selector) ->
+    Selector;
+
 % Terminals where we can't perform any validation
 % on the value because any value is acceptable.
 norm_ops({[{<<"$lt">>, _}]} = Cond) ->
@@ -224,6 +237,17 @@ norm_fields({[{<<"$elemMatch">>, Arg}]}, Path) ->
     Cond = {[{<<"$elemMatch">>, norm_fields(Arg)}]},
     {[{Path, Cond}]};
 
+
+% The text operator operates against the internal
+% $default field. This also asserts that the $default
+% field is at the root as well as that it only has
+% a $text operator applied.
+norm_fields({[{<<"$default">>, {[{<<"$text">>, _Arg}]}}]}=Sel, <<>>)
->
+    Sel;
+norm_fields({[{<<"$default">>, _}]} = Selector, _) ->
+    ?MANGO_ERROR({bad_field, Selector});
+
+
 % Any other operator is a terminal below which no
 % field names should exist. Set the path to this
 % terminal and return it.
@@ -461,6 +485,11 @@ match({[{<<"$size">>, Arg}]}, Values, _Cmp) when is_list(Values)
->
 match({[{<<"$size">>, _}]}, _Value, _Cmp) ->
     false;
 
+% We don't have any choice but to believe that the text
+% index returned valid matches
+match({[{<<"$default">>, _}]}, _Value, _Cmp) ->
+    true;
+
 % All other operators are internal assertion errors for
 % matching because we either should've removed them during
 % normalization or something else broke.


Mime
View raw message