Commits

rzezeski  committed b639b31 Merge

Merge branch 'az442-better-lookup-range-error'

  • Participants
  • Parent commits c088dd7, 13175c6

Comments (0)

Files changed (5)

File apps/riak_search/src/merge_index_backend.erl

 
 iterate(eof, Sender) ->
     riak_search_backend:response_done(Sender);
+iterate({error, Reason}, Sender) ->
+    riak_search_backend:response_error(Sender, Reason);
 iterate({Results, Iter}, Sender) ->
     riak_search_backend:response_results(Sender, Results),
     iterate(Iter(), Sender).
+

File apps/riak_search/src/riak_search_backend.erl

 -export([
          response_results/2, 
          response_done/1,
+         response_error/2,
          info_response/2, 
          collect_info_response/3]).
 
 %% Send a response to a stream() request
 response_results(Sender, Results) ->
     riak_core_vnode:reply(Sender, {result_vec, Results}).
+
 response_done(Sender) ->
     riak_core_vnode:reply(Sender, done).
 
+response_error(Sender, Reason) ->
+    riak_core_vnode:reply(Sender, {error, Reason}).
+
 collect_info_response(0, _Ref, Acc) ->
     {ok, Acc};
 collect_info_response(RepliesRemaining, Ref, Acc) ->

File apps/riak_search/src/riak_search_client.erl

                         {NewAcc, NewAccCount}
                 end
         end,
-    {ok, SearchRef2, {Results, _}} = fold_results(SearchRef1, Timeout, F, {[], 0}),
 
-    case PresortBy of
-        key ->
-            SortedResults = sort_by_key(SearchRef2, Results);
-        _ ->
-            SortedResults = sort_by_score(SearchRef2, Results)
-    end,
-             
+    case fold_results(SearchRef1, Timeout, F, {[], 0}) of
+        {ok, SearchRef2, {Results, _}} ->
+            case PresortBy of
+                key ->
+                    SortedResults = sort_by_key(SearchRef2, Results);
+                _ ->
+                    SortedResults = sort_by_score(SearchRef2, Results)
+            end,
 
-    %% Dedup, and handle start and max results. Return matching
-    %% documents.
-    Results1 = truncate_list(QueryStart, QueryRows, SortedResults),
-    Length = length(SortedResults),
-    {Length, Results1}.
+            %% Dedup, and handle start and max results. Return matching
+            %% documents.
+            Results1 = truncate_list(QueryStart, QueryRows, SortedResults),
+            Length = length(SortedResults),
+            {Length, Results1};
+        {error, _} = Err ->
+            Err
+    end.
 
 %% Run the search query, fold results through function, return final
 %% accumulator.
 search_fold(IndexOrSchema, QueryOps, Fun, AccIn, Timeout) ->
     %% Execute the search, collect the results,.
     SearchRef = stream_search(IndexOrSchema, QueryOps),
-    {ok, _NewSearchRef, AccOut} = fold_results(SearchRef, Timeout, Fun, AccIn),
-    AccOut.
+    case fold_results(SearchRef, Timeout, Fun, AccIn) of
+        {ok, _NewSearchRef, AccOut} ->
+            AccOut;
+        {error, _} = Err ->
+            Err
+    end.
 
 search_doc(IndexOrSchema, QueryOps, QueryStart, QueryRows, Timeout) ->
     search_doc(IndexOrSchema, QueryOps, QueryStart, QueryRows, score, Timeout).
     case collect_result(SearchRef, Timeout) of
         {done, Ref} ->
             {ok, Ref, Acc};
-        {error, timeout} ->
-            {error, timeout};
+        {error, _} = Err ->
+            Err;
         {Results, Ref} ->
             NewAcc = Fun(Results, Acc),
             fold_results(Ref, Timeout, Fun, NewAcc)
         {results, Results, Id} ->
             {Results, SearchRef};
         {disconnect, Id} ->
-            {[], SearchRef#riak_search_ref{inputcount=InputCount - 1}}
+            {[], SearchRef#riak_search_ref{inputcount=InputCount - 1}};
+        {error, _} = Err ->
+            Err
         after Timeout ->
              {error, timeout}
     end.

File apps/riak_search/src/riak_search_cmd.erl

     io:format("~n :: Searching for '~s' in ~s...~n~n", [Query, DefaultIndex]),
     io:format("------------------------------~n~n"),
     case search:search(DefaultIndex, Query) of
+        {error, Reason} ->
+            io:format(" :: ERROR: ~p", [Reason]);
         {Length, Results} ->
             F = fun(X) ->
                 {Index, DocID, Props} = X,
                 io:format("~n------------------------------~n~n")
             end,
             [F(X) || X <- Results],
-            io:format(" :: Found ~p results.~n", [Length]);
-        Other ->
-            io:format(" :: ERROR: ~p", [Other])
+            io:format(" :: Found ~p results.~n", [Length])
     end.
 
 search_doc(DefaultIndex, Query) -> 
     io:format("~n :: Searching for '~s' in ~s...~n~n", [Query, DefaultIndex]),
     io:format("------------------------------~n~n"),
     case search:search_doc(DefaultIndex, Query) of
+        {error, Reason} ->
+            io:format("ERROR: ~p", [Reason]);
         {Length, MaxScore, Results} ->
             F = fun(X) ->
                 %% Index.
             end,
             [F(X) || X <- Results],
             io:format(" :: Found ~p results.~n", [Length]),
-            io:format(" :: Maximum score ~p.~n", [MaxScore]);
-        Other ->
-            io:format("ERROR: ~p", [Other])
+            io:format(" :: Maximum score ~p.~n", [MaxScore])
     end.
 
 explain(DefaultIndex, Query) -> 

File apps/riak_search/src/riak_search_op_utils.erl

             OutputPid!{results, ResultVec2, OutputRef},
             gather_stream_results(Ref, OutputPid, OutputRef, TransformFun);
 
+        {Ref, {error, _} = Err} ->
+            OutputPid ! Err;
+
         %% TODO: Check if this is dead code
         {Ref, {result, {DocID, Props}}} ->
             NewResult = TransformFun({DocID, Props}),