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
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 @@
% 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 @@
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 @@
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
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 @@
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