couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tonysu...@apache.org
Subject couchdb-mango git commit: Also append quotes for specific numeric string field
Date Tue, 15 Sep 2015 00:57:49 GMT
Repository: couchdb-mango
Updated Branches:
  refs/heads/master 87faac11d -> f92403294


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/f9240329
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mango/tree/f9240329
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mango/diff/f9240329

Branch: refs/heads/master
Commit: f92403294b30cf54fbf9577e26cf243c5634cb73
Parents: 87faac1
Author: Tony Sun <tony.sun@cloudant.com>
Authored: Thu Sep 10 14:44:57 2015 -0700
Committer: Tony Sun <tony.sun@cloudant.com>
Committed: Mon Sep 14 17:58:44 2015 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/f9240329/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/f9240329/test/06-basic-text-test.py
----------------------------------------------------------------------
diff --git a/test/06-basic-text-test.py b/test/06-basic-text-test.py
index 28c495a..c60779e 100644
--- a/test/06-basic-text-test.py
+++ b/test/06-basic-text-test.py
@@ -585,3 +585,10 @@ class NumStringTests(mango.DbPerClass):
         if len(docs) == 2:
             if docs[0]["number_string"] != f:
                 assert docs[1]["number_string"] == f
+        q = {"number_string": f}
+        docs = self.db.find(q)
+        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


Mime
View raw message