ruby: Add wrapper for notmuch_query_count_threads
authorWael M. Nasreddine <wael.nasreddine@gmail.com>
Sat, 10 May 2014 21:40:11 +0000 (14:40 -0700)
committerDavid Bremner <david@tethera.net>
Sat, 17 May 2014 21:39:58 +0000 (06:39 +0900)
bindings/ruby/defs.h
bindings/ruby/init.c
bindings/ruby/query.c

index 5b44585a6ad0cc329d311975a7aa4470a6a890ee..f4901a047923e3340e373b4bff8ded8335996323 100644 (file)
@@ -231,6 +231,9 @@ notmuch_rb_query_search_messages (VALUE self);
 VALUE
 notmuch_rb_query_count_messages (VALUE self);
 
+VALUE
+notmuch_rb_query_count_threads (VALUE self);
+
 /* threads.c */
 VALUE
 notmuch_rb_threads_destroy (VALUE self);
index 663271d4e598ed46d60cec5467d4e82f127d8729..ab3f22df9c8106624b7e42e28bd4a805fa925686 100644 (file)
@@ -271,6 +271,7 @@ Init_notmuch (void)
     rb_define_method (notmuch_rb_cQuery, "search_threads", notmuch_rb_query_search_threads, 0); /* in query.c */
     rb_define_method (notmuch_rb_cQuery, "search_messages", notmuch_rb_query_search_messages, 0); /* in query.c */
     rb_define_method (notmuch_rb_cQuery, "count_messages", notmuch_rb_query_count_messages, 0); /* in query.c */
+    rb_define_method (notmuch_rb_cQuery, "count_threads", notmuch_rb_query_count_threads, 0); /* in query.c */
 
     /*
      * Document-class: Notmuch::Threads
index 1658edee4dac046e7bcc9f95e751ef77f9cee9da..a7dacba3351edfe631934daac37220c34cd9e781 100644 (file)
@@ -182,3 +182,22 @@ notmuch_rb_query_count_messages (VALUE self)
      */
     return UINT2NUM(notmuch_query_count_messages(query));
 }
+
+/*
+ * call-seq: QUERY.count_threads => Fixnum
+ *
+ * Return an estimate of the number of threads matching a search
+ */
+VALUE
+notmuch_rb_query_count_threads (VALUE self)
+{
+    notmuch_query_t *query;
+
+    Data_Get_Notmuch_Query (self, query);
+
+    /* Xapian exceptions are not handled properly.
+     * (function may return 0 after printing a message)
+     * Thus there is nothing we can do here...
+     */
+    return UINT2NUM(notmuch_query_count_threads(query));
+}