using the erlang API for riak search

Rusty Klophaus rusty at basho.com
Tue Dec 14 14:36:30 EST 2010


Hi Carson,

That looks like a simple typo. ;-) The name of the module is
'riakc_pb_socket' module. Notice the 'c' after 'riak'.

Best,
Rusty

On Tue, Dec 14, 2010 at 2:30 PM, carson li <carson.li at liquidanalytics.com>wrote:

> Hi Rusty,
>
> That makes sense but i'm still running into problems.  My code is simple
>
> Pid = get_riak_client(),
>  {ok, Results} = riak_pb_socket:search(Pid, "testB", "firstName:Billie").
>
> This returns the following error.
>
> {error,{error,undef,
>               [{riak_pb_socket,search,[<0.97.0>,"testB","firstName:Billie"]},
>                {webmachine_demo_resource,to_text,2},
>                {webmachine_demo_resource,to_html,2},
>                {webmachine_resource,resource_call,3},
>                {webmachine_resource,do,3},
>                {webmachine_decision_core,resource_call,1},
>                {webmachine_decision_core,decision,1},
>                {webmachine_decision_core,handle_request,2}]}}
>
>
> So something isn't right, and i'm not getting any results back.  What
> exactly am i doing wrong?  Just to double check that the query itself is
> correct and the data is there, going to the terminal, and doing a
> "search-cmd search testB "firstName:Billie" returns me
>
> :: Searching for 'firstName:Billie' in testB...
>
> ------------------------------
>
> index/id: testB/testK1
> p -> [0]
> score -> 0.5
>
> ------------------------------
>
>  :: Found 1 results.
>
>
> So i know the item is in there. is my syntax wrong? or am i missing
> something?
>
>
> On Tue, Dec 14, 2010 at 2:01 PM, Rusty Klophaus <rusty at basho.com> wrote:
>
>> Hi Carson,
>>
>> You are definitely on the right track. The SearchQuery parameter is a
>> Lucene-syntax-ish search query, and the Bucket parameter is the bucket on
>> which to search. You can find more information on the query syntax here:
>> http://wiki.basho.com/display/RIAK/Riak+Search+-+Querying
>>
>> Usage is as follows:
>>
>> {ok, Pid} = riakc_pb_socket:start("127.0.0.1", "8087"),
>> Bucket = "json",
>> SearchQuery = "firstname:John"),
>> {ok, BucketKeyList} = riakc_pb_socket:search(Pid, Bucket, SearchQuery,
>> riakc_pb_socket:stop(Pid).
>>
>> You can also do more complicated things like using the results to spawn a
>> map/reduce operation by adding a MapReducePhases parameter. You can find
>> more information on map/reduce phases here:
>> http://wiki.basho.com/display/RIAK/MapReduce
>>
>> {ok, Result} = riakc_pb_socket:search(Pid, "json", "firstname:John",
>> MapReducePhases, TimeoutInMS),
>>
>> Best,
>> Rusty
>>
>>  On Mon, Dec 13, 2010 at 4:33 PM, carson li <carson.li@
>> liquidanalytics.com> wrote:
>>
>>> hey everyone,
>>>
>>> i just started off with using riak search.  (i have some basic riak
>>> experience) and i don't know how to use the erlang api for riak to do search
>>> queries.
>>>
>>> what i've done so far
>>> ------------------------------
>>> I have successfully installed the KV hook, put in a json document,
>>> and also used the search-cmd to retrieve something.  for reference i put
>>> in the json
>>>
>>> {
>>>    firstname:"John",
>>>    lastName:"Smith"
>>> }
>>>
>>> with the command curl -X PUT http://127.0.0.1:8098/riak/test/123 -H
>>> "Content-Type: application/json" -d @test.json
>>>
>>> to retrieve something i by navigating to riah search's bin, then
>>> ./search-cmd search json firstname:John
>>>
>>> the above works well.
>>> now i'm buildling an aplpication with webmachine / erlang. and i want to
>>> be able to perform searches as well.
>>> the wiki indicates that the Erlang api should support this
>>>
>>> https://wiki.basho.com/display/RIAK/Riak+Search+-+Querying
>>>
>>> looking at riakc_pb_socket.erl, i see there is a search method that has
>>> the signature search(Pid, Bucket, SearchQuery)
>>>
>>> so what exactly is SearchQuery, how is it supposed to look like.  So it
>>> just gets passed into a mapred_search?
>>> I'm confused on how this works.  Can someone please provide a simple
>>> example, of how i can search for say firstname:John with the json above?
>>>
>>> any help would be greatly appreciated.
>>>
>>>
>>>
>>> --
>>> Carson Li
>>> Liquid Analytics
>>> carson.li at liquidanalytics.com
>>> 647-273-1024
>>>
>>>
>>> _______________________________________________
>>> riak-users mailing list
>>> riak-users at lists.basho.com
>>> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>>>
>>>
>>
>
>
> --
> Carson Li
> Liquid Analytics
> carson.li at liquidanalytics.com
> 647-273-1024
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20101214/cd6524f1/attachment.html>


More information about the riak-users mailing list