How to search objects using riak_search method

郎咸武 langxianzhe at gmail.com
Thu Aug 30 09:19:59 EDT 2012


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.*
*
*
*I am sorry ,**the question in the following*
*
*
159> f(O),O=riakc_obj:new(<<"user">>, <<"mine">>,
term_to_binary([{"name_","jason"},{"sex_", "male"}])).
{riakc_obj,<<"user">>,<<"mine">>,undefined,[],undefined,
           <<131,108,0,0,0,2,104,2,107,0,5,110,97,109,101,95,107,0,
             5,106,97,115,...>>}
160> riakc_pb_socket:put(Pid,O).

ok
161> riakc_pb_socket:search(Pid, <<"user">>,
term_to_binary([{"name_","jason"},{"sex_", "male"}])).
{ok,{search_results,[{<<"user">>,
                      [{<<"id">>,<<"mine">>},
                       {<<"value">>,

<<131,108,0,0,0,2,104,2,107,0,5,110,97,109,101,95,107,
                          0,...>>}]}],
                    0.35355299711227417,1}}
162> riakc_pb_socket:search(Pid, <<"user">>,
term_to_binary([{"name_","jason"}])).
{ok,{search_results,[],0.0,0}}
163>
*How to get the object by the {"name_", "jason"} ?*
*Is there another way to solve the question?*



I need your help, thanks very much.

Jason













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


More information about the riak-users mailing list