Created
October 1, 2014 20:04
-
-
Save tonysun83/dd853016a548a0bf42bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
search_all(DbName, DDoc, IndexName, HttpResp, QueryArgs) -> | |
call(search_all, DbName, DDoc, IndexName, HttpResp, QueryArgs). | |
call(Fun, DbName, DDoc, IndexName,HttpResp, QueryArgs0) -> | |
QueryArgs = dreyfus_util:upgrade(QueryArgs0), | |
erlang:put(io_priority, {interactive, DbName}), | |
check_interactive_mode(), | |
{ok, Db} = get_or_create_db(DbName, []), | |
#index_query_args{ | |
stale = Stale | |
} = QueryArgs, | |
{_LastSeq, MinSeq} = calculate_seqs(Db, Stale), | |
case dreyfus_index:design_doc_to_index(DDoc, IndexName) of | |
{ok, Index} -> | |
case dreyfus_index_manager:get_index(DbName, Index) of | |
{ok, Pid} -> | |
case dreyfus_index:await(Pid, MinSeq) of | |
% obsolete clause, remove after upgrade | |
ok -> | |
Reply = dreyfus_index:Fun(Pid, HttpResp, QueryArgs), | |
rexi:stream2(Reply), | |
get_stream_hits(Pid); | |
{ok, _Seq} -> | |
Reply = dreyfus_index:Fun(Pid, HttpResp, QueryArgs), | |
rexi:stream2(Reply), | |
get_stream_hits(Pid); | |
Error -> | |
rexi:stream_last(Error) | |
end; | |
Error -> | |
rexi:stream_last(Error) | |
end; | |
Error -> | |
rexi:stream_last(Error) | |
end. | |
get_stream_hits(Pid) -> | |
case dreyfus_index:get_hits(Pid) of | |
{complete,Hits} -> | |
twig:log(notice, "Complete streaming with hit: ~p", [Hits]), | |
lists:foreach(fun(H) -> rexi:stream2({ok, {hits,H}}) end ,Hits), | |
rexi:stream_last(complete); | |
complete -> | |
twig:log(notice, "Complete streaming: ~p", [Pid]), | |
rexi:stream_last(complete); | |
not_complete-> | |
get_stream_hits(Pid); | |
Hits -> | |
twig:log(notice, "Stream a hit: ~p", [Hits]), | |
lists:foreach(fun(H) -> rexi:stream2({ok, {hits,H}}) end ,Hits), | |
get_stream_hits(Pid) | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment