diff options
-rw-r--r-- | src/mango/src/mango_cursor_view.erl | 45 | ||||
-rw-r--r-- | src/mango/test/02-basic-find-test.py | 13 |
2 files changed, 38 insertions, 20 deletions
diff --git a/src/mango/src/mango_cursor_view.erl b/src/mango/src/mango_cursor_view.erl index 2dcf1c71b..b292704c3 100644 --- a/src/mango/src/mango_cursor_view.erl +++ b/src/mango/src/mango_cursor_view.erl @@ -56,18 +56,31 @@ create(Db, Indexes, Selector, Opts) -> explain(Cursor) -> #cursor{ - index = Idx, - ranges = Ranges + opts = Opts } = Cursor, - case Ranges of - [empty] -> - [{range, empty}]; - _ -> - [{range, {[ - {start_key, mango_idx:start_key(Idx, Ranges)}, - {end_key, mango_idx:end_key(Idx, Ranges)} - ]}}] - end. + + BaseArgs = base_args(Cursor), + Args = apply_opts(Opts, BaseArgs), + [{mrargs, {[ + {include_docs, Args#mrargs.include_docs}, + {view_type, Args#mrargs.view_type}, + {reduce, Args#mrargs.reduce}, + {start_key, Args#mrargs.start_key}, + {end_key, Args#mrargs.end_key}, + {direction, Args#mrargs.direction}, + {stable, Args#mrargs.stable}, + {update, Args#mrargs.update} + ]}}]. + + +base_args(#cursor{index = Idx} = Cursor) -> + #mrargs{ + view_type = map, + reduce = false, + start_key = mango_idx:start_key(Idx, Cursor#cursor.ranges), + end_key = mango_idx:end_key(Idx, Cursor#cursor.ranges), + include_docs = true + }. execute(#cursor{db = Db, index = Idx, execution_stats = Stats} = Cursor0, UserFun, UserAcc) -> @@ -81,16 +94,10 @@ execute(#cursor{db = Db, index = Idx, execution_stats = Stats} = Cursor0, UserFu % empty indicates unsatisfiable ranges, so don't perform search {ok, UserAcc}; _ -> - BaseArgs = #mrargs{ - view_type = map, - reduce = false, - start_key = mango_idx:start_key(Idx, Cursor#cursor.ranges), - end_key = mango_idx:end_key(Idx, Cursor#cursor.ranges), - include_docs = true - }, + BaseArgs = base_args(Cursor), #cursor{opts = Opts, bookmark = Bookmark} = Cursor, Args0 = apply_opts(Opts, BaseArgs), - Args = mango_json_bookmark:update_args(Bookmark, Args0), + Args = mango_json_bookmark:update_args(Bookmark, Args0), UserCtx = couch_util:get_value(user_ctx, Opts, #user_ctx{}), DbOpts = [{user_ctx, UserCtx}], Result = case mango_idx:def(Idx) of diff --git a/src/mango/test/02-basic-find-test.py b/src/mango/test/02-basic-find-test.py index e634ce9fe..699166e28 100644 --- a/src/mango/test/02-basic-find-test.py +++ b/src/mango/test/02-basic-find-test.py @@ -14,7 +14,6 @@ import mango - class BasicFindTests(mango.UserDocsTests): def test_bad_selector(self): @@ -264,3 +263,15 @@ class BasicFindTests(mango.UserDocsTests): ] }) assert len(docs) == 0 + + def test_explain_view_args(self): + explain = self.db.find({ + "age":{"$gt": 0} + }, fields=["manager"], + explain=True) + assert explain["mrargs"]["stable"] == False + assert explain["mrargs"]["update"] == True + assert explain["mrargs"]["reduce"] == False + assert explain["mrargs"]["start_key"] == [0] + assert explain["mrargs"]["end_key"] == [{}] + assert explain["mrargs"]["include_docs"] == True |