public void aggregateUsersByTweetCountByRegion()
        {
            ResultSet rs = null;
            try
            {
                int min;
                int max;
                Console.WriteLine("\nEnter Min Tweet Count:");
                min = int.Parse(Console.ReadLine());
                Console.WriteLine("Enter Max Tweet Count:");
                max = int.Parse(Console.ReadLine());

                // NOTE: UDF registration has been included here for convenience and to demonstrate the syntax.
                // NOTE: The recommended way of registering UDFs in production env is via AQL
                string luaDirectory = @"..\..\udf";
                LuaConfig.PackagePath = luaDirectory + @"\?.lua";

                string filename = "aggregationByRegion.lua";
                string path = Path.Combine(luaDirectory, filename);

                RegisterTask rt = client.Register(null, path, filename, Language.LUA);
                rt.Wait();

                string[] bins = { "tweetcount", "region" };
                Statement stmt = new Statement();
                stmt.SetNamespace("test");
                stmt.SetSetName("users");
                stmt.SetIndexName("tweetcount_index");
                stmt.SetBinNames(bins);
                stmt.SetFilters(Filter.Range("tweetcount", min, max));

                Console.WriteLine("\nAggregating users with " + min + "-" + max + " tweets by region. Hang on...\n");

                rs = client.QueryAggregate(null, stmt, "aggregationByRegion", "sum");

                if (rs.Next())
                {
                    Dictionary<object, object> result = (Dictionary<object, object>)rs.Object;
                    Console.WriteLine("Total Users in North: " + result["n"]);
                    Console.WriteLine("Total Users in South: " + result["s"]);
                    Console.WriteLine("Total Users in East: " + result["e"]);
                    Console.WriteLine("Total Users in West: " + result["w"]);
                }
            }
            finally
            {
                if (rs != null)
                {
                    // Close record set
                    rs.Close();
                }
            }
        }
        public void queryUsersByTweetCount()
        {
            Console.WriteLine("\n********** Query Users By Tweet Count Range **********\n");

            RecordSet rs = null;
            try
            {
                // NOTE: Index creation has been included in here for convenience and to demonstrate the syntax.
                // NOTE: The recommended way of creating indexes in production env is via AQL.
                IndexTask task = client.CreateIndex(null, "test", "users", "tweetcount_index", "tweetcount", IndexType.NUMERIC);
                task.Wait();

                // Get min and max tweet counts
                int min;
                int max;
                Console.WriteLine("\nEnter Min Tweet Count:");
                min = int.Parse(Console.ReadLine());
                Console.WriteLine("Enter Max Tweet Count:");
                max = int.Parse(Console.ReadLine());

                string[] bins = { "username", "tweetcount" };
                Statement stmt = new Statement();
                stmt.SetNamespace("test");
                stmt.SetSetName("users");
                stmt.SetIndexName("tweetcount_index");
                stmt.SetBinNames(bins);
                stmt.SetFilters(Filter.Range("tweetcount", min, max));

                Console.WriteLine("\nList of users with " + min + "-" + max + " tweets:\n");

                rs = client.Query(null, stmt);
                while (rs.Next())
                {
                    Record r = rs.Record;
                    Console.WriteLine(r.GetValue("username") + " has " + r.GetValue("tweetcount") + " tweets");
                }
            }
            finally
            {
                if (rs != null)
                {
                    // Close record set
                    rs.Close();
                }
            }
        }
        public void queryTweetsByUsername()
        {
            Console.WriteLine("\n********** Query Tweets By Username **********\n");

            RecordSet rs = null;
            try
            {
                // NOTE: Index creation has been included in here for convenience and to demonstrate the syntax.
                // NOTE: The recommended way of creating indexes in production env is via AQL.
                IndexTask task = client.CreateIndex(null, "test", "tweets", "username_index", "username", IndexType.STRING);
                task.Wait();

                // Get username
                string username;
                Console.WriteLine("\nEnter username:"******"tweet" };
                    Statement stmt = new Statement ();
                    stmt.SetNamespace ("test");
                    stmt.SetSetName ("tweets");
                    stmt.SetIndexName ("username_index");
                    stmt.SetBinNames (bins);
                    stmt.SetFilters (Filter.Equal ("username", username));

                    Console.WriteLine ("\nHere's " + username + "'s tweet(s):\n");

                    rs = client.Query (null, stmt);
                    while (rs.Next ()) {
                        Record r = rs.Record;
                        Console.WriteLine (r.GetValue ("tweet"));
                    }
                } else {
                    Console.WriteLine ("ERROR: User record not found!");
                }
            }
            finally
            {
                if (rs != null)
                {
                    // Close record set
                    rs.Close();
                }
            }
        }
        /// <summary>
        /// Example functions not in use
        /// </summary>
        private void deleteTweets()
        {
            RecordSet rs = null;
            try
            {
                // Get username
                string username;
                Console.WriteLine("\nEnter username:"******"test", "users", username);
                    Record userRecord = client.Get(null, userKey);
                    if (userRecord != null)
                    {
                        WritePolicy wPolicy = new WritePolicy();
                        wPolicy.recordExistsAction = RecordExistsAction.UPDATE;

                        string[] bins = { "tweet" };
                        Statement stmt = new Statement();
                        stmt.SetNamespace("test");
                        stmt.SetSetName("tweets");
                        stmt.SetIndexName("username_index");
                        stmt.SetBinNames(bins);
                        stmt.SetFilters(Filter.Equal("username", username));

                        Console.WriteLine("\nDeleting " + username + "'s tweet(s):\n");

                        rs = client.Query(null, stmt);
                        while (rs.Next())
                        {
                            Record r = rs.Record;
                            Console.WriteLine(r.GetValue("tweet"));
                            client.Delete(null, rs.Key);
                        }
                        //Update tweetcount and timestamp to reflect this
                        client.Operate(wPolicy, userKey, Operation.Put(new Bin("tweetcount", 0)), Operation.Put(new Bin("lasttweeted", 0)));
                        rs.Close();
                    }
                    else
                    {
                        Console.WriteLine("ERROR: User record not found!");
                    }
                }
                else
                {
                    Console.WriteLine("ERROR: User record not found!");
                }
            }
            finally
            {
                if (rs != null)
                {
                    // Close record set
                    rs.Close();
                }
            }
        }