summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgarren smith <garren.smith@gmail.com>2017-11-01 17:45:32 +0200
committerGitHub <noreply@github.com>2017-11-01 17:45:32 +0200
commit2e49d7cf9b7fdcd597c8d806e5530047051f1250 (patch)
tree373933e57fcc9994446f5f75fa8c5fd8d39fab9a
parent96046e5996f110c616a5ad07b943e7bbba5c25ce (diff)
downloadcouchdb-2e49d7cf9b7fdcd597c8d806e5530047051f1250.tar.gz
Do not always return partial_filter_selector (#951)
For Get / _index only return the partial_filter_selector for an index if it is set to something other than default
-rw-r--r--src/mango/src/mango_idx_text.erl4
-rw-r--r--src/mango/src/mango_idx_view.erl4
-rw-r--r--src/mango/test/16-index-selectors-test.py13
3 files changed, 20 insertions, 1 deletions
diff --git a/src/mango/src/mango_idx_text.erl b/src/mango/src/mango_idx_text.erl
index e4ffc91db..1d5ae9bad 100644
--- a/src/mango/src/mango_idx_text.erl
+++ b/src/mango/src/mango_idx_text.erl
@@ -152,6 +152,10 @@ def_to_json([{fields, Fields} | Rest]) ->
[{<<"fields">>, fields_to_json(Fields)} | def_to_json(Rest)];
def_to_json([{<<"fields">>, Fields} | Rest]) ->
[{<<"fields">>, fields_to_json(Fields)} | def_to_json(Rest)];
+% Don't include partial_filter_selector in the json conversion
+% if its the default value
+def_to_json([{<<"partial_filter_selector">>, {[]}} | Rest]) ->
+ def_to_json(Rest);
def_to_json([{Key, Value} | Rest]) ->
[{Key, Value} | def_to_json(Rest)].
diff --git a/src/mango/src/mango_idx_view.erl b/src/mango/src/mango_idx_view.erl
index f1041bbaf..c9fe4c85d 100644
--- a/src/mango/src/mango_idx_view.erl
+++ b/src/mango/src/mango_idx_view.erl
@@ -195,6 +195,10 @@ def_to_json([{fields, Fields} | Rest]) ->
[{<<"fields">>, mango_sort:to_json(Fields)} | def_to_json(Rest)];
def_to_json([{<<"fields">>, Fields} | Rest]) ->
[{<<"fields">>, mango_sort:to_json(Fields)} | def_to_json(Rest)];
+% Don't include partial_filter_selector in the json conversion
+% if its the default value
+def_to_json([{<<"partial_filter_selector">>, {[]}} | Rest]) ->
+ def_to_json(Rest);
def_to_json([{Key, Value} | Rest]) ->
[{Key, Value} | def_to_json(Rest)].
diff --git a/src/mango/test/16-index-selectors-test.py b/src/mango/test/16-index-selectors-test.py
index 456b396c7..6d771cc4b 100644
--- a/src/mango/test/16-index-selectors-test.py
+++ b/src/mango/test/16-index-selectors-test.py
@@ -161,6 +161,11 @@ class IndexSelectorJson(mango.DbPerClass):
indexes = self.db.list_indexes()
self.assertEqual(indexes[1]["def"]["partial_filter_selector"], selector)
+ def test_partial_filter_only_in_return_if_not_default(self):
+ self.db.create_index(["location"])
+ index = self.db.list_indexes()[1]
+ self.assertEqual('partial_filter_selector' in index['def'], False)
+
def test_saves_selector_in_index_throws(self):
selector = {"location": {"$gte": "FRA"}}
try:
@@ -264,4 +269,10 @@ class IndexSelectorJson(mango.DbPerClass):
resp = self.db.find(selector, explain=True, use_index='oldschooltext')
self.assertEqual(resp["index"]["name"], "oldschooltext")
docs = self.db.find(selector, use_index='oldschooltext')
- self.assertEqual(len(docs), 3) \ No newline at end of file
+ self.assertEqual(len(docs), 3)
+
+ @unittest.skipUnless(mango.has_text_service(), "requires text service")
+ def test_text_partial_filter_only_in_return_if_not_default(self):
+ self.db.create_text_index(fields=[{"name":"location"}])
+ index = self.db.list_indexes()[1]
+ self.assertEqual('partial_filter_selector' in index['def'], False)