You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by to...@apache.org on 2015/09/11 20:37:20 UTC

couchdb-mango git commit: Also append quotes for specific numeric string field

Repository: couchdb-mango
Updated Branches:
  refs/heads/2806-numeric-string-field [created] 257a9e8a7


Also append quotes for specific numeric string field

We appended quotes for numeric_strings for $text. However, we did not
do this for specific fields. Note that we don't escape the field value
when it's a numeric string because that provides an incorrect string
value for clouseau.

COUCHDB-2806


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

Branch: refs/heads/2806-numeric-string-field
Commit: 257a9e8a7c9589b825731576a4590770eced1176
Parents: 87faac1
Author: Tony Sun <to...@cloudant.com>
Authored: Thu Sep 10 14:44:57 2015 -0700
Committer: Tony Sun <to...@cloudant.com>
Committed: Fri Sep 11 11:38:39 2015 -0700

----------------------------------------------------------------------
 src/mango_selector_text.erl | 19 +++++++------------
 test/06-basic-text-test.py  |  6 ++++++
 2 files changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/257a9e8a/src/mango_selector_text.erl
----------------------------------------------------------------------
diff --git a/src/mango_selector_text.erl b/src/mango_selector_text.erl
index 08aa6ee..9450dfe 100644
--- a/src/mango_selector_text.erl
+++ b/src/mango_selector_text.erl
@@ -49,8 +49,7 @@ convert(Path, {[{<<"$default">>, Arg}]}) ->
 % The $text operator specifies a Lucene syntax query
 % so we just pull it in directly.
 convert(Path, {[{<<"$text">>, Query}]}) when is_binary(Query) ->
-    Value = maybe_append_quotes(value_str(Query)),
-    {op_field, {make_field(Path, Query), Value}};
+    {op_field, {make_field(Path, Query), value_str(Query)}};
 
 % The MongoDB docs for $all are super confusing and read more
 % like they screwed up the implementation of this operator
@@ -326,7 +325,12 @@ type_str(null) ->
 
 
 value_str(Value) when is_binary(Value) ->
-    mango_util:lucene_escape_query_value(Value);
+    case mango_util:is_number_string(Value) of
+        true ->
+            <<"\"", Value/binary, "\"">>;
+        false ->
+            mango_util:lucene_escape_query_value(Value)
+    end;
 value_str(Value) when is_integer(Value) ->
     list_to_binary(integer_to_list(Value));
 value_str(Value) when is_float(Value) ->
@@ -354,15 +358,6 @@ append_sort_type(RawSortField, Selector) ->
     end.
 
 
-maybe_append_quotes(TextValue) ->
-    case mango_util:is_number_string(TextValue) of
-        true ->
-            <<"\"", TextValue/binary, "\"">>;
-        false ->
-            TextValue
-    end.
-
-
 get_sort_type(Field, Selector) ->
     Types = get_sort_types(Field, Selector, []),
     case lists:usort(Types) of

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/257a9e8a/test/06-basic-text-test.py
----------------------------------------------------------------------
diff --git a/test/06-basic-text-test.py b/test/06-basic-text-test.py
index 28c495a..92f60ee 100644
--- a/test/06-basic-text-test.py
+++ b/test/06-basic-text-test.py
@@ -585,3 +585,9 @@ class NumStringTests(mango.DbPerClass):
         if len(docs) == 2:
             if docs[0]["number_string"] != f:
                 assert docs[1]["number_string"] == f
+        q = {"number_string": f}
+        if len(docs) == 1:
+            assert docs[0]["number_string"] == f
+        if len(docs) == 2:
+            if docs[0]["number_string"] != f:
+                assert docs[1]["number_string"] == f