Skip to content

Instantly share code, notes, and snippets.

@macintux
Created August 21, 2013 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macintux/6296458 to your computer and use it in GitHub Desktop.
Save macintux/6296458 to your computer and use it in GitHub Desktop.
Perform secondary index (2i) searches on Twitter hashtags stored in Riak and count the matching tags.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment