This is an automated email from the ASF dual-hosted git repository. tonysun83 pushed a commit to branch fix-explicit-exists-operator in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 763c579dc37051c5b0025e092cea26c569db1fa7 Author: Tony Sun <[email protected]> AuthorDate: Tue Oct 3 17:40:24 2017 -0700 fix exists false when field is explicitly defined When users explicitly defined a text index's fields, and used $exists with false, we tag false when constructing the query. This led to a function clause for indexable_fields since we did not account for it. This fix patches that up, but note that we don't care about the false value itself since we only care about fields. --- src/mango/src/mango_idx_text.erl | 2 ++ src/mango/test/07-text-custom-field-list-test.py | 38 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/mango/src/mango_idx_text.erl b/src/mango/src/mango_idx_text.erl index 1d5ae9b..d81905f 100644 --- a/src/mango/src/mango_idx_text.erl +++ b/src/mango/src/mango_idx_text.erl @@ -329,6 +329,8 @@ indexable_fields(Fields, {op_or, Args}) when is_list(Args) -> indexable_fields(Fields, {op_not, {ExistsQuery, Arg}}) when is_tuple(Arg) -> Fields0 = indexable_fields(Fields, ExistsQuery), indexable_fields(Fields0, Arg); +indexable_fields(Fields, {op_not, {ExistsQuery, false}}) -> + indexable_fields(Fields, ExistsQuery); indexable_fields(Fields, {op_insert, Arg}) when is_binary(Arg) -> Fields; diff --git a/src/mango/test/07-text-custom-field-list-test.py b/src/mango/test/07-text-custom-field-list-test.py index a43e330..5b65d8d 100644 --- a/src/mango/test/07-text-custom-field-list-test.py +++ b/src/mango/test/07-text-custom-field-list-test.py @@ -12,6 +12,7 @@ import mango import unittest +import user_docs @unittest.skipUnless(mango.has_text_service(), "requires text service") @@ -28,7 +29,10 @@ class CustomFieldsTest(mango.UserDocsTextTests): "name": "location.address.street", "type": "string" }, - {"name": "name\\.first", "type": "string"} + {"name": "name\\.first", "type": "string"}, + {"name": "exists_field", "type": "string"}, + {"name": "exists_array.[]", "type": "string"}, + {"name": "exists_object.should", "type": "string"} ] def test_basic(self): @@ -160,3 +164,35 @@ class CustomFieldsTest(mango.UserDocsTextTests): }) assert len(docs) == 1 assert docs[0]["user_id"] == 10 + + def test_exists_field(self): + docs = self.db.find({"exists_field": {"$exists": True}}) + assert len(docs) == 2 + for d in docs: + assert d["user_id"] in (7, 8) + + docs = self.db.find({"exists_field": {"$exists": False}}) + assert len(docs) == len(user_docs.DOCS) - 2 + for d in docs: + assert d["user_id"] not in (7, 8) + + def test_exists_array(self): + docs = self.db.find({"exists_array": {"$exists": True}}) + assert len(docs) == 2 + for d in docs: + assert d["user_id"] in (9, 10) + + docs = self.db.find({"exists_array": {"$exists": False}}) + assert len(docs) == len(user_docs.DOCS) - 2 + for d in docs: + assert d["user_id"] not in (9, 10) + + def test_exists_object(self): + docs = self.db.find({"exists_object.should": {"$exists": True}}) + assert len(docs) == 1 + assert docs[0]["user_id"] == 11 + + docs = self.db.find({"exists_object.should": {"$exists": False}}) + assert len(docs) == len(user_docs.DOCS) - 1 + for d in docs: + assert d["user_id"] !=11 -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
