@@ -285,6 +285,31 @@ select({#db{}=Db0, Design, View}, StartKey, EndKey, Options)
285
285
{not_found , missing_named_view } -> {error , view_not_found }
286
286
catch
287
287
_ :{not_found , missing } -> {error , design_not_found }
288
+ end ;
289
+
290
+ select ({# db {}= Db0 , Design , ReduceView , GroupLevel }, StartKey , EndKey , Options )
291
+ when is_list (Design ), is_list (ReduceView ) ->
292
+ Db = reopen (Db0 ),
293
+ BaseArgs = view_query_base_args (Options ),
294
+ # view_query_args {stale = Stale ,
295
+ limit = Limit ,
296
+ skip = Skip } = BaseArgs ,
297
+ Args = BaseArgs # view_query_args {start_key = StartKey , end_key = EndKey },
298
+ try couch_view :get_reduce_view (Db , design_id (Design ),
299
+ list_to_binary (ReduceView ), Stale ) of
300
+ {ok , Reduce , Group } ->
301
+ {ok , GroupRowsFun , RespFun } = fold_reduce_view_acc_fun (Db , Group , GroupLevel ),
302
+ case couch_view :fold_reduce (Reduce , RespFun ,
303
+ {Limit , Skip , undefined , []},
304
+ [{key_group_fun , GroupRowsFun }|fold_view_options (Args )]) of
305
+ {ok , {_ ,_ ,_ ,Rows }} ->
306
+ {ok , Rows };
307
+ Error ->
308
+ {error , Error }
309
+ end ;
310
+ {not_found , missing_named_view } -> {error , view_not_found }
311
+ catch
312
+ _ :{not_found , missing } -> {error , design_not_found }
288
313
end .
289
314
290
315
% % ---------------------------------------------------------------------------
@@ -446,6 +471,9 @@ enum_db_acc_fun(Db, DocCount, #view_query_args{}=Args) ->
446
471
% % Preserves the initial offset and provides an empty list for acc.
447
472
% % ---------------------------------------------------------------------------
448
473
474
+ doc_fold_reduce_start_response (_Req , _Etag , _Acc , _UpdateSeq ) ->
475
+ {ok , nil , []}.
476
+
449
477
doc_fold_start_response (_Req , _Etag , _RowCount , Offset , _Acc , _UpdateSeq ) ->
450
478
{ok , nil , {Offset , []}}.
451
479
@@ -458,6 +486,9 @@ doc_fold_start_response(_Req, _Etag, _RowCount, Offset, _Acc, _UpdateSeq) ->
458
486
% % Removes the outer tuple for "objects" to present them as tuple lists.
459
487
% % ---------------------------------------------------------------------------
460
488
489
+ doc_fold_reduce_send_row (_Resp , {Key , Value }, Acc ) ->
490
+ {ok , [{Key , Value }|Acc ]}.
491
+
461
492
doc_fold_send_row (_Resp , Db , Doc , IncludeDocs , {Offset , Acc }) ->
462
493
{Row } = couch_httpd_view :view_row_obj (Db , Doc , IncludeDocs ),
463
494
{ok , {Offset , [lists :map (fun format_row_item /1 , Row )|Acc ]}}.
@@ -489,6 +520,16 @@ enum_db_options(#view_query_args{start_docid=StartId,
489
520
% % It borrows from hovercraft.
490
521
% % ---------------------------------------------------------------------------
491
522
523
+ fold_reduce_view_acc_fun (Db , Group , GroupLevel ) ->
524
+ UpdateSeq = couch_db :get_update_seq (Db ),
525
+ CurrentEtag = couch_httpd_view :view_group_etag (Group , Db ),
526
+ Helpers = # reduce_fold_helper_funs {
527
+ % %reduce_count=fun couch_view:reduce_to_count/1,
528
+ start_response = fun doc_fold_reduce_start_response /4 ,
529
+ send_row = fun doc_fold_reduce_send_row /3 },
530
+ couch_httpd_view :make_reduce_fold_funs (
531
+ nil , GroupLevel , undefined , CurrentEtag , UpdateSeq , Helpers ).
532
+
492
533
fold_view_acc_fun (Db , RowCount , Args ) ->
493
534
UpdateSeq = couch_db :get_update_seq (Db ),
494
535
Helpers = # view_fold_helper_funs {
0 commit comments