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/10 02:34:08 UTC

[06/26] couchdb-mango git commit: Fix field_exists_query

Fix field_exists_query

The mango_selector:field_exists_query/2 was incorrectly returning
the query. This change fixes this issue and consequently fixes operators
that depended on this function such as $regex, $mod, and $type.

BugzId:45970


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

Branch: refs/heads/master
Commit: 5df74ffdc398502a7c097c709fa86d056a99b5ab
Parents: 4f05552
Author: Tony Sun <to...@cloudant.com>
Authored: Tue Aug 25 12:04:49 2015 -0700
Committer: Tony Sun <to...@cloudant.com>
Committed: Tue Aug 25 13:24:03 2015 -0700

----------------------------------------------------------------------
 src/mango_selector_text.erl | 6 +++++-
 test/06-basic-text-test.py  | 9 +++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/5df74ffd/src/mango_selector_text.erl
----------------------------------------------------------------------
diff --git a/src/mango_selector_text.erl b/src/mango_selector_text.erl
index 24d4ad1..9402cc2 100644
--- a/src/mango_selector_text.erl
+++ b/src/mango_selector_text.erl
@@ -143,6 +143,10 @@ convert(Path, {[{<<"$type">>, _}]}) ->
 convert(Path, {[{<<"$mod">>, _}]}) ->
     field_exists_query(Path, "number");
 
+% The lucene regular expression engine does not use java's regex engine but
+% instead a custom implementation. The syntax is therefore different, so we do
+% would get different behavior than our view indexes. To be consistent, we will
+% simply return docs for fields that exist and then run our match filter.
 convert(Path, {[{<<"$regex">>, _}]}) ->
     field_exists_query(Path, "string");
 
@@ -260,7 +264,7 @@ field_exists_query(Path) ->
 
 
 field_exists_query(Path, Type) ->
-    {op_fieldname, [path_str(Path), ":", Type]}.
+    {op_fieldname, {[path_str(Path), ":"], Type}}.
 
 
 path_str(Path) ->

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/5df74ffd/test/06-basic-text-test.py
----------------------------------------------------------------------
diff --git a/test/06-basic-text-test.py b/test/06-basic-text-test.py
index 670fad5..28538ad 100644
--- a/test/06-basic-text-test.py
+++ b/test/06-basic-text-test.py
@@ -395,6 +395,15 @@ class BasicTextTests(mango.UserDocsTextTests):
         docs = self.db.find(q)
         assert len(docs) == 1
 
+    def test_regex(self):
+        docs = self.db.find({
+                "age": {"$gt": 40},
+                "location.state": {"$regex": "(?i)new.*"}
+            })
+        assert len(docs) == 2
+        assert docs[0]["user_id"] == 2
+        assert docs[1]["user_id"] == 10
+
     # test lucene syntax in $text