From 3879c0afc86145a0f95cfb770c1c7dc59579bef1 Mon Sep 17 00:00:00 2001 From: Srivatsa Katta Date: Tue, 14 Jan 2014 11:40:54 +0530 Subject: [PATCH] Search by secondary index is now in place --- riakcli | 29 ++++++++++++++++++++++++++++- riakcli_bashcompletion | 13 +++++++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/riakcli b/riakcli index d7a3575..2f12fc6 100755 --- a/riakcli +++ b/riakcli @@ -9,6 +9,8 @@ printUsage() { echo "" echo " riakcli get object [bucket-name] [key] -> Gets the object associated with a given key in a specified bucket" echo " riakcli put object [bucket-name] [key] [object-json] -> Creates/Updates an object for a given key in a specified bucket" + echo " riakcli search by_index [bucket-name] [index-name] [index-value]" + echo " -> Searches given value by secondary index in a specified bucket" echo "" echo " riakcli delete bucket [bucket-name] -> Deletes all objects in a specified bucket" echo " riakcli delete object [bucket-name] [key] -> Deletes an object in a given bucket" @@ -83,7 +85,7 @@ getObject() { } putObject() { - checkForArgs 3 "riakcli put object [bucket-name] [key] [object-json]"$* + checkForArgs 3 "riakcli put object [bucket-name] [key] [object-json]" $* local BUCKET=$1 local KEY=$2 @@ -94,6 +96,15 @@ putObject() { cput ${RIAK_BASE_URL}/riak/${BUCKET}/${KEY} ${OBJECT} } +searchByIndex() { + checkForArgs 3 "search by_index [bucket-name] [index-name] [index-value]" $* + local BUCKET=$1 + local INDEX=$2 + local VALUE=$3 + + crl ${RIAK_BASE_URL}/buckets/${BUCKET}/index/${INDEX}_bin/${VALUE} +} + deleteBucket() { checkForArgs 1 "riakcli delete bucket [bucket-name]" $* local BUCKET=$1 @@ -151,6 +162,18 @@ get() { esac } +search() { + case "$1" in + "by_index" ) + shift + searchByIndex $* + ;; + * ) + printInvalidUsage + ;; + esac +} + put() { case "$1" in "object" ) @@ -209,6 +232,10 @@ __init__() { shift get $* ;; + "search" ) + shift + search $* + ;; "list" ) shift list $* diff --git a/riakcli_bashcompletion b/riakcli_bashcompletion index 7cda6dd..1833a17 100644 --- a/riakcli_bashcompletion +++ b/riakcli_bashcompletion @@ -4,7 +4,7 @@ _riakcli() { cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - opts="list get put delete flush ping help" + opts="list search get put delete flush ping help" case "${prev}" in list) @@ -18,14 +18,19 @@ _riakcli() { return 0 ;; delete) - local list_opts="bucket object" - COMPREPLY=( $(compgen -W "${list_opts}" -- ${cur}) ) + local delete_opts="bucket object" + COMPREPLY=( $(compgen -W "${delete_opts}" -- ${cur}) ) return 0 ;; flush | ping | help) return 0 ;; - object | keys | bucket) + search ) + local search_opts="by_index" + COMPREPLY=( $(compgen -W "${search_opts}" -- ${cur}) ) + return 0 + ;; + object | keys | bucket | by_index ) local bucket_opts=`riakcli list buckets | cut -d ':' -f2 | sed -e 's/^.*\[//g' -e 's/"//g' -e 's/\]\}//g' -e 's/,/ /g'` COMPREPLY=( $(compgen -W "${bucket_opts}" -- ${cur}) ) return 0