anchor.diff:    riakc_pb_socket:search(Conn, Index, Query, [{start, Offset}, {rows, Limit}]).
   
   -spec build_query(sumo:conditions()) -> binary().
  -build_query([]) ->
  -  <<"*:*">>;
  -build_query(PL) when is_list(PL) ->
  -  build_query1(PL, <<"">>);
  -build_query(_) ->
  -  <<"*:*">>.
  +build_query(Conditions) ->
  +  build_query1(Conditions).
   
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   %% Private API.
  
positive.code:         {ok, {_, Res}} -> {ok, Res, State};
          {error, Error} -> {error, Error, State}
        end
    end.
  
  -spec find_by(
  
negative.code: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  %% @private
  build_query1([]) ->
    <<"*:*">>;
  build_query1(Exprs) when is_list(Exprs) ->
    Clauses = [build_query1(Expr) || Expr <- Exprs],
    binary:list_to_bin(["(", interpose(" AND ", Clauses), ")"]);
  build_query1({'and', Exprs}) ->
    build_query1(Exprs);
  build_query1({'or', Exprs}) ->
    Clauses = [build_query1(Expr) || Expr <- Exprs],
    binary:list_to_bin(["(", interpose(" OR ", Clauses), ")"]);
  build_query1({'not', Expr}) ->
    binary:list_to_bin(["(NOT ", build_query1(Expr), ")"]);
  build_query1({Name, Op, Value}) when Op =:= '<'; Op =:= '<=' ->
    NewVal = binary:list_to_bin(["[* TO ", escape(Value), "]"]),
    query_eq(Name, NewVal);
  build_query1({Name, Op, Value}) when Op =:= '>'; Op =:= '>=' ->
    NewVal = binary:list_to_bin(["[", escape(Value), " TO *]"]),
    query_eq(Name, NewVal);
  build_query1({Name, '==', Value}) ->
    build_query1({Name, Value});
  build_query1({Name, '/=', Value}) ->
    build_query1({negative_field(Name), Value});
  build_query1({Name, 'null'}) ->
    query_eq(negative_field(Name), <<"[* TO *]">>);
  build_query1({Name, 'not_null'}) ->
    query_eq(Name, <<"[* TO *]">>);
  build_query1({Name, Value}) ->
    query_eq(Name, quote(escape(Value))).
  
  %% @private
  query_eq(K, V) ->
    binary:list_to_bin([build_key(K), V]).
  
  %% @private
  build_key(K) ->
    build_key(binary:split(to_bin(K), <<".">>, [global]), <<"">>).
  
  %% @private
  build_key([K], <<"">>) ->
    binary:list_to_bin([K, "_register:"]);
  build_key([K], Acc) ->
    binary:list_to_bin([Acc, ".", K, "_register:"]);
  build_key([K | T], <<"">>) ->
    build_key(T, binary:list_to_bin([K, "_map"]));
  build_key([K | T], Acc) ->
    build_key(T, binary:list_to_bin([Acc, ".", K, "_map"])).
  
  %% @private
  interpose(Sep, List) ->
    interpose(Sep, List, []).
  
  %% @private
  interpose(_Sep, [], Result) ->
    lists:reverse(Result);
  interpose(Sep, [Item | []], Result) ->
    interpose(Sep, [], [Item | Result]);
  interpose(Sep, [Item | Rest], Result) ->
    interpose(Sep, Rest, [Sep, Item | Result]).
  
  %% @private
  negative_field(Name) ->
    binary:list_to_bin([<<"-">>, to_bin(Name)]).
  
  %% @private
  quote(Value) ->
    [$\", re:replace(to_bin(Value), "[\\\"\\\\]", "\\\\&", [global]), $\"].
  
  %% @private
  escape(Value) ->
    Escape = "[\\+\\-\\&\\|\\!\\(\\)\\{\\}\\[\\]\\^\\\"\\~\\*\\?\\:\\\\]",
    re:replace(to_bin(Value), Escape, "\\\\&", [global, {return, binary}]).
  