Permalink
Browse files

add `include_deleted` option to a view

add the possibility to index deleted documents in a view.
  • Loading branch information...
1 parent fd7037d commit d1850f225261e2a5fc22c3e397fa9bff04fcb49c @benoitc benoitc committed Jun 18, 2012
View
3 apps/couch_index/src/couch_index_updater.erl
@@ -120,6 +120,7 @@ update(Idx, Mod, IdxState) ->
UpdateOpts = Mod:get(update_options, IdxState),
CommittedOnly = lists:member(committed_only, UpdateOpts),
IncludeDesign = lists:member(include_design, UpdateOpts),
+ IncludeDeleted = lists:member(include_deleted, UpdateOpts),
DocOpts = case lists:member(local_seq, UpdateOpts) of
true -> [conflicts, deleted_conflicts, local_seq];
_ -> [conflicts, deleted_conflicts]
@@ -146,7 +147,7 @@ update(Idx, Mod, IdxState) ->
case {IncludeDesign, DocId} of
{false, <<"_design/", _/binary>>} ->
{nil, Seq};
- _ when Deleted ->
+ _ when Deleted, IncludeDeleted /= true ->
{#doc{id=DocId, deleted=true}, Seq};
_ ->
{ok, Doc} = couch_db:open_doc_int(Db, DocInfo, DocOpts),
View
1 apps/couch_mrview/include/couch_mrview.hrl
@@ -18,6 +18,7 @@
idx_name,
language,
design_opts=[],
+ include_deleted=false,
lib,
views,
id_btree=nil,
View
6 apps/couch_mrview/src/couch_mrview_index.erl
@@ -38,8 +38,12 @@ get(Property, State) ->
Opts = State#mrst.design_opts,
IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
+ IncludeDeleted = couch_util:get_value(<<"include_deleted">>,
+ Opts, false),
+
if IncDesign -> [include_design]; true -> [] end
- ++ if LocalSeq -> [local_seq]; true -> [] end;
+ ++ if LocalSeq -> [local_seq]; true -> [] end
+ ++ if IncludeDeleted -> [include_deleted]; true -> [] end;
info ->
#mrst{
fd = Fd,
View
3 apps/couch_mrview/src/couch_mrview_updater.erl
@@ -99,7 +99,8 @@ process_doc(Doc, Seq, #mrst{doc_acc=Acc}=State) when length(Acc) > 100 ->
process_doc(Doc, Seq, State#mrst{doc_acc=[]});
process_doc(nil, Seq, #mrst{doc_acc=Acc}=State) ->
{ok, State#mrst{doc_acc=[{nil, Seq, nil} | Acc]}};
-process_doc(#doc{id=Id, deleted=true}, Seq, #mrst{doc_acc=Acc}=State) ->
+process_doc(#doc{id=Id, deleted=true}, Seq,
+ #mrst{doc_acc=Acc, include_deleted=false}=State)->
{ok, State#mrst{doc_acc=[{Id, Seq, deleted} | Acc]}};
process_doc(#doc{id=Id}=Doc, Seq, #mrst{doc_acc=Acc}=State) ->
{ok, State#mrst{doc_acc=[{Id, Seq, Doc} | Acc]}}.
View
7 apps/couch_mrview/src/couch_mrview_util.erl
@@ -93,14 +93,17 @@ ddoc_to_mrst(DbName, #doc{id=Id, body={Fields}}) ->
{DesignOpts} = couch_util:get_value(<<"options">>, Fields, {[]}),
{RawViews} = couch_util:get_value(<<"views">>, Fields, {[]}),
Lib = couch_util:get_value(<<"lib">>, RawViews, {[]}),
+ IncludeDeleted = couch_util:get_value(<<"include_deleted">>, DesignOpts,
+ false),
IdxState = #mrst{
db_name=DbName,
idx_name=Id,
lib=Lib,
views=Views,
language=Language,
- design_opts=DesignOpts
+ design_opts=DesignOpts,
+ include_deleted=IncludeDeleted
},
SigInfo = {Views, Language, DesignOpts, couch_index_util:sort_lib(Lib)},
{ok, IdxState#mrst{sig=couch_util:md5(term_to_binary(SigInfo))}}.
@@ -530,7 +533,7 @@ delete_index_file(DbName, Sig) ->
delete_compaction_file(DbName, Sig) ->
delete_file(compaction_file(DbName, Sig)).
-
+
delete_file(FName) ->
case filelib:is_file(FName) of

0 comments on commit d1850f2

Please sign in to comment.