Rusty Klophaus  committed 0662606

Maintain sort order while performing search result doc lookups.

This fixes a bug introduced in commit 78bc1348. We replaced plists:map/N with the ptransform/2 function, which unfortunately no longer preserved the order of the original list of items to transform. Modified ptransform/2 to preserve the original order.

  • Participants
  • Parent commits 25ef3d9

Comments (0)

Files changed (1)

File apps/riak_search/src/riak_search_utils.erl

 %% has some subtle bugs because messages are not tagged with
 %% Refs. This causes heisenbugs.
 ptransform(F, List) ->
+    %% Maintain order by adding a position to the list. Then run the
+    %% results, sort, and return the unwrapped list.
+    WrappedF = fun({Pos, X}) -> {Pos, F(X)} end,
+    WrappedList = lists:zip(lists:seq(1, length(List)), List),
+    %% Run in parallel for however many schedulers there are.
     Schedulers = erlang:system_info(schedulers),
-    ptransform(F, List, Schedulers).
+    Results = ptransform(WrappedF, WrappedList, Schedulers),
+    %% Unwrap and return the results.
+    [X || {_,X} <- lists:sort(Results)].
 %% Run a map operation in parallel.
 ptransform(F, List, NumProcesses) ->