How to search objects using riak_search method

郎咸武 langxianzhe at gmail.com
Tue Oct 9 07:49:50 EDT 2012


Hi, Joe Caswell
I have a new question.

((ejabberd at 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 at meta)20> riakc_pb_socket:put(Pid, O).
ok

(ejabberd at 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}}

(ejabberd at 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?*
(ejabberd at 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?*

Thanks in advance.

2012/9/7 郎咸武 <langxianzhe at gmail.com>

> Thanks a lot. That is ok
>
>
> 2012/9/6 Joe Caswell <jcaswell at basho.com>
>
>> Try without the extra quotes
>>
>> riakc_pb_socket:search(Pid, <<"user2">>, list_to_binary("sex:mal*")).
>>
>> Joe Caswell
>>
>> From: 郎咸武 <langxianzhe at gmail.com>
>> Date: Friday, August 31, 2012 3:14 AM
>> To: riak-users <riak-users at lists.basho.com>
>> Subject: Re: How to search objects using riak_search method
>>
>> Creating object like this:
>>  f(O),O=riakc_obj:new(<<"user">>, <<"jason">>,
>> list_to_binary("[{\"name\":\"jason\"},{\"sex\":\"male\"}]"),
>> "application/json").
>>
>>
>> 72> riakc_pb_socket:search(Pid, <<"user2">>,
>> list_to_binary("\"sex\":\"male\"")).
>> {ok,{search_results,[{<<"user2">>,
>>                       [{<<"id">>,<<"jason">>},
>>                        {<<"name">>,<<"jason">>},
>>                        {<<"sex">>,<<"male">>}]}],
>>                     0.35355299711227417,1}}
>> 73> riakc_pb_socket:search(Pid, <<"user2">>,
>> list_to_binary("\"sex\":\"mal*\"")). *%% But this is empty. Why?*
>> {ok,{search_results,[],0.0,0}}
>> 74> riakc_pb_socket:search(Pid, <<"user2">>,
>> list_to_binary("\"sex\":\"male\"")).
>> {ok,{search_results,[{<<"user2">>,
>>                       [{<<"id">>,<<"jason">>},
>>                        {<<"name">>,<<"jason">>},
>>                        {<<"sex">>,<<"male">>}]}],
>>                     0.35355299711227417,1}}
>>
>>
>> 2012/8/31 郎咸武 <langxianzhe at gmail.com>
>>
>>> anyone may reply me,thanks a lot.
>>>
>>> 在 2012年8月30日星期四,郎咸武 写道:
>>>
>>>> who can give me some idea
>>>>
>>>> 在 2012年8月30日星期四,郎咸武 写道:
>>>>
>>>> Hi guys,
>>>>        I need your help.
>>>>
>>>> Version:
>>>> 1)riak-erlang-client-1.3
>>>> 2)riak-1.2
>>>> 3)Erlang R14B04 (erts-5.8.5) [source] [64-bit]
>>>>
>>>> This is my bucket attributs in the following
>>>>
>>>> (riak at 127.0.0.1)52> {ok,C} = riak:local_client().
>>>>
>>>> {ok,{riak_client,'riak at 127.0.0.1',undefined}}
>>>> (riak at 127.0.0.1)53> C:set_bucket(<<"user">>,[{precommit,
>>>> [{struct,[{<<"mod">>,<<"riak_search_kv_hook">>},{<<"fun">>,<<"precommit">>}]}]}]).
>>>> ok
>>>> (riak at 127.0.0.1)54> C:get_bucket(<<"user">>).
>>>>
>>>> [{search,true},
>>>>  {allow_mult,false},
>>>>  {basic_quorum,false},
>>>>  {big_vclock,50},
>>>>  {chash_keyfun,{riak_core_util,chash_std_keyfun}},
>>>>  {dw,quorum},
>>>>  {last_write_wins,false},
>>>>  {linkfun,{modfun,riak_kv_wm_link_walker,mapreduce_linkfun}},
>>>>  {n_val,3},
>>>>  {name,<<"user">>},
>>>>  {notfound_ok,true},
>>>>  {old_vclock,86400},
>>>>  {postcommit,[]},
>>>>  {pr,0},
>>>> * {precommit,[{struct,[{<<"mod">>,<<"riak_search_kv_hook">>},*
>>>> *                      {<<"fun">>,<<"precommit">>}]}]},*
>>>>  {pw,0},
>>>>  {r,quorum},
>>>>  {rw,quorum},
>>>>  {small_vclock,50},
>>>>  {w,quorum},
>>>>  {young_vclock,20}]
>>>>
>>>> *------------------*
>>>> *In the client*
>>>> *To new a object  and search it*
>>>> 147> f(O),O=riakc_obj:new(<<"user">>, <<"jason">>, <<"jasonlang">>)
>>>> 147> .
>>>> {riakc_obj,<<"user">>,<<"jason">>,undefined,[],undefined,
>>>>            <<"jasonlang">>}
>>>>
>>>> 150> riakc_pb_socket:put(Pid,O).
>>>> ok
>>>> 151> riakc_pb_socket:search(Pid, <<"user">>, "jason*")
>>>> 151> .
>>>> {ok,{search_results,[{<<"user">>,
>>>>
>>>> [{<<"id">>,<<"jason">>},{<<"value">>,<<"jasonlang">>}]}],
>>>>                     0.0,1}}
>>>> 152>
>>>>
>>>> *This search operator  is ok*
>>>>
>>>> *TO new another object and search it*
>>>>
>>>> 152> f(O),O=riakc_obj:new(<<"user">>, <<"lang">>, <<"langzhe">>)
>>>> 152> .
>>>> {riakc_obj,<<"user">>,<<"lang">>,undefined,[],undefined,
>>>>            <<"langzhe">>}
>>>> 153> riakc_pb_socket:put(Pid,O).
>>>> ok
>>>> 154> riakc_pb_socket:search(Pid, <<"user">>, "langzh*")
>>>> 154> .
>>>> {ok,{search_results,[{<<"user">>,
>>>>
>>>> [{<<"id">>,<<"lang">>},{<<"value">>,<<"langzhe">>}]}],
>>>>                     0.0,1}}
>>>> *This is ok too*
>>>> *
>>>> *
>>>> *Search the objects:*
>>>> 157> riakc_pb_socket:search(Pid, <<"user">>, "langzh*\"\"jason*")
>>>> 157> .
>>>> {ok,{search_results,[{<<"user">>,
>>>>
>>>> [{<<"id">>,<<"jason">>},{<<"value">>,<<"jasonlang">>}]},
>>>>                      {<<"user">>,
>>>>
>>>> [{<<"id">>,<<"lang">>},{<<"value">>,<<"langzhe">>}]}],
>>>>                     0.0,2}}
>>>> 158>
>>>> This is ok too.
>>>> -------------------------------------------------------------------
>>>> *In the above is ok.*
>>>>
>>>> --
>>>> 只为成功找方法,不为失败找理由
>>>>
>>>
>>>
>>> --
>>> 只为成功找方法,不为失败找理由
>>>
>>
>>
>>
>> --
>> 只为成功找方法,不为失败找理由
>> _______________________________________________ riak-users mailing list
>> riak-users at lists.basho.com
>> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>>
>
>
>
> --
> 只为成功找方法,不为失败找理由
>



-- 
只为成功找方法,不为失败找理由
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20121009/a2cf31db/attachment.html>


More information about the riak-users mailing list