[PATCH] ruby: Add wrapper for notmuch_query_count_threads

Wael M. Nasreddine wael.nasreddine at gmail.com
Sat May 10 14:40:11 PDT 2014


---
 bindings/ruby/defs.h  |  3 +++
 bindings/ruby/init.c  |  1 +
 bindings/ruby/query.c | 19 +++++++++++++++++++
 3 files changed, 23 insertions(+)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 5b44585..f4901a0 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -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);
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 663271d..ab3f22d 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -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
diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index 1658ede..a7dacba 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -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));
+}
-- 
1.9.1.423.g4596e3a



More information about the notmuch mailing list