anchor.diff:      "\"" ++ lists:flatten(io_lib:format("~4w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0wZ",
           [Year,Month,Day,Hour,Min,Sec])) ++ "\"".
   
  +
  +check_key(id, [], Acc) ->
  +{'_yz_rk' , Acc};
  +check_key(id, [H|T], Acc) ->
  +  {_, _, RK} = infer_type_from_id(H),
  +  check_key(id, T, lists:append(Acc, [binary_to_list(RK)])).
  +
   check_key(id, V) ->
       {_, _, RK} = infer_type_from_id(V),
       {'_yz_rk' , RK};
  
positive.code: % this is a stub just to make the tests runable
  count(Conn, Type, Conditions) ->
    Bucket = type_to_bucket_name(Type),
    lager:info("~p", [build_search_query(Conditions)]),
    {ok, {search_results, _, _, Count}} = case Conditions of
                                            [] ->  riakc_pb_socket:search(Conn, list_to_binary(Bucket),
                                              list_to_binary("_yz_id:*"),
  
negative.code:     {K, V} = check_key(Key, Value),
      build_search_query(Rest, [lists:concat(["NOT ", K, ":", quote_value(V)])|Acc]);
  build_search_query([{Key, 'in', Value}|Rest], Acc) when is_list(Value) ->
      {K, V} = check_key(Key, Value, []),
      build_search_query(Rest, [lists:concat([K, ":", "(", string:join(lists:map(fun(Val) ->
                                      lists:concat([quote_value(Val)])
                              end, V), " OR "), ")"])|Acc]);
  build_search_query([{Key, 'not_in', Value}|Rest], Acc) when is_list(Value) ->
      {K, V} = check_key(Key, Value, []),
      build_search_query(Rest, [lists:concat(["NOT ", K, ":", "(", string:join(lists:map(fun(Val) ->
                                      lists:concat([quote_value(Val)])
                              end, V), " AND "), ")"])|Acc]);
  