diff options
author | Tony Sun <tony.sun427@gmail.com> | 2020-01-27 10:55:08 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-27 10:55:08 -0800 |
commit | d59d84ac78e596a97d8ae014d7d84e7b306495d0 (patch) | |
tree | 86d3e1e89053ccee024054c2510d74cf2247cf56 | |
parent | 866a83618496846b29b794a42b2e7cd0f49f347a (diff) | |
download | couchdb-d59d84ac78e596a97d8ae014d7d84e7b306495d0.tar.gz |
quote strings for all text values (#2486)
When a user issues a range query $lt, $lte, $gt, $gte for text indexes,
the query is translated into a MIN, MAX range query against clouseau.
If not quoted, an error occurs:
{"error":"text_search_error","reason":"Cannot parse
'(a_3astring:[\"\" TO string\\ containing\\ space})'..}
This is because the string is broken up into 3 tokens which the parser
cannot parse. If we add quotes to the string, the the range query works
correctly.
-rw-r--r-- | src/mango/src/mango_selector_text.erl | 3 | ||||
-rw-r--r-- | src/mango/test/06-basic-text-test.py | 18 | ||||
-rw-r--r-- | src/mango/test/user_docs.py | 1 |
3 files changed, 21 insertions, 1 deletions
diff --git a/src/mango/src/mango_selector_text.erl b/src/mango/src/mango_selector_text.erl index 9e1116de6..b3b61ff26 100644 --- a/src/mango/src/mango_selector_text.erl +++ b/src/mango/src/mango_selector_text.erl @@ -366,7 +366,8 @@ value_str(Value) when is_binary(Value) -> true -> <<"\"", Value/binary, "\"">>; false -> - mango_util:lucene_escape_query_value(Value) + Escaped = mango_util:lucene_escape_query_value(Value), + <<"\"", Escaped/binary, "\"">> end; value_str(Value) when is_integer(Value) -> list_to_binary(integer_to_list(Value)); diff --git a/src/mango/test/06-basic-text-test.py b/src/mango/test/06-basic-text-test.py index db7cf32cb..a3fe383d6 100644 --- a/src/mango/test/06-basic-text-test.py +++ b/src/mango/test/06-basic-text-test.py @@ -95,6 +95,9 @@ class BasicTextTests(mango.UserDocsTextTests): assert len(docs) == 1 assert docs[0]["company"] == "Affluex" + docs = self.db.find({"foo": {"$lt": "bar car apple"}}) + assert len(docs) == 0 + def test_lte(self): docs = self.db.find({"age": {"$lte": 21}}) assert len(docs) == 0 @@ -113,6 +116,10 @@ class BasicTextTests(mango.UserDocsTextTests): for d in docs: assert d["user_id"] in (0, 11) + docs = self.db.find({"foo": {"$lte": "bar car apple"}}) + assert len(docs) == 1 + assert docs[0]["user_id"] == 14 + def test_eq(self): docs = self.db.find({"age": 21}) assert len(docs) == 0 @@ -156,6 +163,13 @@ class BasicTextTests(mango.UserDocsTextTests): docs = self.db.find({"company": {"$gt": "Zialactic"}}) assert len(docs) == 0 + docs = self.db.find({"foo": {"$gt": "bar car apple"}}) + assert len(docs) == 0 + + docs = self.db.find({"foo": {"$gt": "bar car"}}) + assert len(docs) == 1 + assert docs[0]["user_id"] == 14 + def test_gte(self): docs = self.db.find({"age": {"$gte": 77}}) assert len(docs) == 2 @@ -178,6 +192,10 @@ class BasicTextTests(mango.UserDocsTextTests): assert len(docs) == 1 assert docs[0]["company"] == "Zialactic" + docs = self.db.find({"foo": {"$gte": "bar car apple"}}) + assert len(docs) == 1 + assert docs[0]["user_id"] == 14 + def test_and(self): docs = self.db.find({"age": 22, "manager": True}) assert len(docs) == 1 diff --git a/src/mango/test/user_docs.py b/src/mango/test/user_docs.py index e0495353b..f6a33960e 100644 --- a/src/mango/test/user_docs.py +++ b/src/mango/test/user_docs.py @@ -343,6 +343,7 @@ DOCS = [ "city": "Axis", "address": {"street": "Brightwater Avenue", "number": 1106}, }, + "foo" : "bar car apple", "company": "Pharmex", "email": "faithhess@pharmex.com", "favorites": ["Erlang", "Python", "Lisp"], |