Commits

Daniel Reverri committed c468b29

Fix max_search_results count

Comments (0)

Files changed (1)

apps/riak_search/src/riak_search_client.erl

     index_doc/2,
     index_docs/1, index_docs/2,
     index_term/5, index_term/6,
-    index_terms/1, 
+    index_terms/1,
 
     %% Delete
     delete_docs/1,
 mapred(DefaultIndex, SearchQuery, MRQuery, ResultTransformer, Timeout) ->
     {ok, ReqID} = mapred_stream(DefaultIndex, SearchQuery, MRQuery, self(), ResultTransformer, Timeout),
     luke_flow:collect_output(ReqID, Timeout).
-        
+
 mapred_stream(DefaultIndex, SearchQuery, MRQuery, ClientPid, ResultTransformer, Timeout) ->
     InputDef = {modfun, riak_search, mapred_search, [DefaultIndex, SearchQuery]},
     {ok, {RId, FSM}} = RiakClient:mapred_stream(MRQuery, ClientPid, ResultTransformer, Timeout),
                   riak_search_utils:to_list(Query)),
     {ok, riak_search_op:preplan(Ops)}.
 
-    
-    
+
+
 %% Run the Query, return the list of keys.
 %% Timeout is in milliseconds.
 %% Return the {Length, Results}.
     MaxSearchResults = app_helper:get_env(riak_search, max_search_results),
     F = fun(Results, {Acc, AccCount}) ->
                 NewAcc = Results ++ Acc,
-                NewAccCount = AccCount + length(Acc),
+                NewAccCount = AccCount + length(Results),
                 case NewAccCount > MaxSearchResults of
                     true ->
                         throw({too_many_results, QueryOps});
                 IdxDoc = riak_indexed_doc:analyze(IdxDoc0, AnalyzerPid),
 
                 %% Get the terms to delete...
-                Index = riak_indexed_doc:index(IdxDoc), 
+                Index = riak_indexed_doc:index(IdxDoc),
                 DocId = riak_indexed_doc:id(IdxDoc),
                 case riak_indexed_doc:get_obj(RiakClient, Index, DocId) of
                     {ok, OldRiakObj} ->
                 %% Get the terms to index...
                 IndexTerms = riak_indexed_doc:postings(IdxDoc),
                 NewIndexAcc = [IndexTerms|IndexAccIn],
-                
+
                 %% Store the document...
                 RiakObj = riak_object:update_value(OldRiakObj, IdxDoc),
                 NewRiakObjsAcc = [RiakObj|RiakObjsAccIn],
-                
+
                 %% Return.
                 {NewRiakObjsAcc, NewDeleteAcc, NewIndexAcc}
         end,
     FlatIndexAcc = lists:flatten(IndexAcc),
     index_terms(FlatIndexAcc),
     ok.
-    
+
 
 %% Index the specified term - better to use the plural 'terms' interfaces
 index_term(Index, Field, Term, DocID, Props) ->
     index_terms([{Index, Field, Term, DocID, Props, K}]).
 
 index_terms(Terms) ->
-    IndexFun = fun(VNode, Postings) -> 
+    IndexFun = fun(VNode, Postings) ->
                        riak_search_vnode:index(VNode, Postings)
                end,
     process_terms(IndexFun, Terms).
 process_terms_1(IndexFun, BatchSize, PreflistCache, Terms) ->
     %% Split off the next chunk of terms.
     case length(Terms) > BatchSize of
-        true -> 
+        true ->
             {Batch, Rest} = lists:split(BatchSize, Terms);
-        false -> 
+        false ->
             {Batch, Rest} = {Terms, []}
     end,
 
         %% Ensure the PreflistCache contains all needed entries...
         F1 = fun(PIKey, Cache) ->
                      case gb_trees:lookup(PIKey, Cache) of
-                         {value, _} -> 
+                         {value, _} ->
                              PreflistCache;
-                         none -> 
+                         none ->
                              %% Create a sample DocIdx in the section
                              %% of the ring where we want a partition.
                              {Partition, Index} = PIKey,
                 end
         end,
     {ExistingObjs, DeleteAcc} = lists:foldl(F, {[],[]}, Docs),
-    
+
     %% Delete the postings...
     FlatDeleteAcc = lists:flatten(DeleteAcc),
     delete_terms(FlatDeleteAcc),
-    
+
     %% Delete the Riak objects...
     [RiakClient:delete(DocIndex, DocID) || {DocIndex, DocID} <- ExistingObjs],
     ok.
     #riak_search_ref {
         id=Ref, termcount=NumTerms,
         inputcount=NumInputs, querynorm=QueryNorm }.
-    
+
 
 %% Receive results from the provided SearchRef, run through the
 %% provided Fun starting with Acc.