Hi,
I'm using Ruby and I'm trying to learn how to use Riak basics, now I'm
learning links and I have a question I know will be so easy to answer by
you, experts :).
I know how to search with a simple MapReduce query what items I'm linking,
but now the opposite, what items links me.
As little concept I've made this simple script, just it creates 10 items in
a bucket, 20 relations as follow, 20 as like (I don't try to do the next
graph thing, just was the first tags that come to my brain): (BTW: I have
tryed to find how this is done in ripple but seems I need to study more to
obtain the answer looking the code Sean wrote).
As you can see, I just create those 10 items in the bucket (1..10) and
randomly add the relations. The mapreduce function works showing me all the
links in each relation for each object in the last iteration.
Now, I'm trying to find how to get the reverse.
Thank you in advance. Hope someone can get some time and help me.
-- test-creator.rb --
require 'rubygems'
require 'riak'
client = Riak::Client.new
client.http_port = 8091
bucket_name = "users8" #change for test in different bucket
bucket = client.bucket(bucket_name)
10.times do |n|
o = bucket.new("#{n + 1}")
o.data = "#{n + 1}"
o.store
end
20.times do |n|
source = rand(10) + 1
destination = rand(10) + 1
puts "#{source} --> follow --> #{destination}"
o = bucket["#{source}"]
o.links << Riak::Link.new(bucket_name, destination, 'follow')
o.store
end
20.times do |n|
source = rand(10) + 1
destination = rand(10) + 1
puts "#{source} --> like --> #{destination}"
o = bucket["#{source}"]
o.links << Riak::Link.new(bucket_name, destination, 'like')
o.store
end
10.times do |n|
results = Riak::MapReduce.new(client).add(bucket_name, "#{n +
1}").link(:bucket => bucket_name, :tag => 'follow').map("function(v) {
return [JSON.parse(v.values[0].data)]; }", :keep => true).run
puts "follow #{n + 1} = "
p results
results = Riak::MapReduce.new(client).add(bucket_name, "#{n +
1}").link(:bucket => bucket_name, :tag => 'like').map("function(v) { return
[JSON.parse(v.values[0].data)]; }", :keep => true).run
puts "like #{n + 1} = "
p results
end
_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com