On Tue, Oct 9, 2012 at 7:49 AM, 郎咸武 <langxian...@gmail.com> wrote: > > > ((ejabberd@meta)19> f(O),O=riakc_obj:new(<<"user1">>, <<"jason3">>, > list_to_binary("[{\"name\":\"\\u00e9\\u0083\\u008e\\u00e5\\u0093\\u00b2\"},{\"sex\":\"male1\"}]"), > "application/json"). > {riakc_obj,<<"user1">>,<<"jason3">>,undefined,[], > {dict,1,16,16,8,80,48, > {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],...}, > > {{[],[],[],[],[],[],[],[],[],[],[[<<...>>|...]],[],[],...}}}, > > > <<"[{\"name\":\"\\u00e9\\u0083\\u008e\\u00e5\\u0093\\u00b2\"},{\"sex\":\"male1\"}]">>} > > (ejabberd@meta)20> riakc_pb_socket:put(Pid, O). > ok > > (ejabberd@meta)28> riakc_pb_socket:search(Pid, <<"user1">>, > list_to_binary("\"sex\":male1*")). * The operation is ok.* > {ok,{search_results,[{<<"user1">>, > [{<<"id">>,<<"jason3">>}, > {<<"name">>, > > <<195,169,194,131,194,142,195,165,194,147,194,178>>}, > {<<"sex">>,<<"male1">>}]}], > 0.0,1}} >
Notice the value of the name field in the result here. It has been properly converted to a UTF-8 sequence. That is, at some point Riak Search took your ASCII string of unicode escapes and converted it to a proper unicode byte sequence. > (ejabberd@meta)29> riakc_pb_socket:search(Pid, <<"user1">>, > list_to_binary("\"name\":\\u00e9\\u0083\\u008e\\u00e5\\u0093\\u00b2")). > > {ok,{search_results,[],0.0,0}} *%% But there is empty. Why?* > First off, you are adding additional quotes around the name field. 11> list_to_binary("\"name\":\\u00e9\\u0083\\u008e\\u00e5\\u0093\\u00b2"). <<"\"name\":\\u00e9\\u0083\\u008e\\u00e5\\u0093\\u00b2">> Second, you are searching for the ASCII string "\\u00e9\\u0083\\u008e\\u00e5\\u0093\\u00b2". At no point is this string converted to a unicode sequence for you. This is the correct behavior because you might have ASCII documents containing unicode escapes. You need to query using a proper unicode binary. 19> riakc_pb_socket:search(Pid, <<"user1">>, <<"name:",195,169,194,131,194,142,195,165,194,147,194,178>>). {ok,{search_results,[{<<"user1">>, [{<<"id">>,<<"jason3">>}, {<<"name">>, <<195,169,194,131,194,142,195,165,194,147,194,178>>}, {<<"sex">>,<<"male1">>}]}], 0.35355299711227417,1}} (ejabberd@meta)30> riakc_pb_socket:search(Pid, <<"user1">>, > list_to_binary("\"name\":\\u00e9\\u0083\\u008e\\u00e5\\u0093\\u00b2*")). > > {ok,{search_results,[],0.0,0}} *%% There is empty,too. Why?* > > 20> riakc_pb_socket:search(Pid, <<"user1">>, <<"name:",195,169,"*">>). {ok,{search_results,[{<<"user1">>, [{<<"id">>,<<"jason3">>}, {<<"name">>, <<195,169,194,131,194,142,195,165,194,147,194,178>>}, {<<"sex">>,<<"male1">>}]}], 0.0,1}} -Z
_______________________________________________ riak-users mailing list riak-users@lists.basho.com http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com