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 2020/01/27 18:55:18 UTC

[couchdb] branch master updated: quote strings for all text values (#2486)

This is an automated email from the ASF dual-hosted git repository.

tonysun83 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/master by this push:
     new d59d84a  quote strings for all text values (#2486)
d59d84a is described below

commit d59d84ac78e596a97d8ae014d7d84e7b306495d0
Author: Tony Sun <to...@gmail.com>
AuthorDate: Mon Jan 27 10:55:08 2020 -0800

    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.
---
 src/mango/src/mango_selector_text.erl |  3 ++-
 src/mango/test/06-basic-text-test.py  | 18 ++++++++++++++++++
 src/mango/test/user_docs.py           |  1 +
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/mango/src/mango_selector_text.erl b/src/mango/src/mango_selector_text.erl
index 9e1116d..b3b61ff 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 db7cf32..a3fe383 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 e049535..f6a3396 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"],