public
Created

Perform secondary index (2i) searches on Twitter hashtags stored in Riak and count the matching tags.

  • Download Gist
2i.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/usr/local/bin/python
 
import riak
 
Riak = riak.RiakClient(pb_port=10017, protocol='pbc')
TweetsBucket = Riak.bucket('tweets')
 
results = TweetsBucket.get_index("hashtags_bin", "android",
"androie", return_terms=True)
 
count = {}
 
# Thanks to return_terms=True, each result will be a tuple: matched
# index term and associated Riak key
for item in results.results:
hashtag = item[0]
if hashtag in count:
count[hashtag] += 1
else:
count[hashtag] = 1
 
print count

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.