Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 5F785431FD5 for ; Mon, 7 May 2012 08:03:20 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.699 X-Spam-Level: X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OcnfDaWL7hww for ; Mon, 7 May 2012 08:03:19 -0700 (PDT) Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id C4019431FD4 for ; Mon, 7 May 2012 08:03:18 -0700 (PDT) Received: by wgbdt14 with SMTP id dt14so4053259wgb.2 for ; Mon, 07 May 2012 08:03:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references:organization:mime-version :content-type:content-transfer-encoding; bh=GBGUTmsRXL4o36c/DTspGhEa4itUxdnh6Y8rdphuK5g=; b=TeLhAm6oCTK9hmhpX1jz4Q8aa2P1PK+EzmROfJp5N8/fDaKNiNo5D8VTQMpJe4rmv1 ZlYuOvKZP3lel12qWlGKgR+N9iiNtwvophma6trG6l18P32HHvHIg+rBQcIfxPUrPyP8 8dyQuVcQuOMTCwsgg/bEVzi1WojpofWFTgdP9GXg4QDZs3znIPMiyz4Vj5gtGx/9Zuzw wB1QXZh+oT6bCFEx9NyLVix5+/b12ykBl5NovsGgTp4Pz+CLdnEwDi310+CbxVi+APET /O94ZBlZtZSUgbBj5IqIZpHQebdj4Z8wgyYNc17S5pK7N8QvexGY5x0jZfMezr4VjEcQ lCuQ== Received: by 10.180.81.166 with SMTP id b6mr36119775wiy.0.1336402997544; Mon, 07 May 2012 08:03:17 -0700 (PDT) Received: from hayalet.ev ([88.234.38.242]) by mx.google.com with ESMTPS id ff2sm34852610wib.9.2012.05.07.08.03.16 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 07 May 2012 08:03:17 -0700 (PDT) Sender: Ali Polatel From: Ali Polatel To: David Bremner Subject: [PATCH 1/4] ruby: Add wrapper for notmuch_query_count_messages Date: Mon, 7 May 2012 18:02:43 +0300 Message-Id: <9c4448b3a5dc2b62663545ea8579e27a17a3bb99.1336402558.git.alip@exherbo.org> X-Mailer: git-send-email 1.7.10.1 In-Reply-To: References: <87txzsgs4g.fsf@zancas.localnet> In-Reply-To: References: Organization: Pink Floyd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Ali Polatel , notmuch@notmuchmail.org X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 May 2012 15:03:20 -0000 --- bindings/ruby/defs.h | 3 +++ bindings/ruby/init.c | 3 ++- bindings/ruby/query.c | 21 ++++++++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h index 81f652f..25222a6 100644 --- a/bindings/ruby/defs.h +++ b/bindings/ruby/defs.h @@ -222,6 +222,9 @@ notmuch_rb_query_search_threads (VALUE self); VALUE notmuch_rb_query_search_messages (VALUE self); +VALUE +notmuch_rb_query_count_messages (VALUE self); + /* threads.c */ VALUE notmuch_rb_threads_destroy (VALUE self); diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c index 4405f19..7ad0ecf 100644 --- a/bindings/ruby/init.c +++ b/bindings/ruby/init.c @@ -1,6 +1,6 @@ /* The Ruby interface to the notmuch mail library * - * Copyright © 2010, 2011 Ali Polatel + * Copyright © 2010, 2011, 2012 Ali Polatel * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -236,6 +236,7 @@ Init_notmuch (void) rb_define_method (notmuch_rb_cQuery, "to_s", notmuch_rb_query_get_string, 0); /* in query.c */ 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 */ /* * Document-class: Notmuch::Threads diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c index 74fd585..02b7819 100644 --- a/bindings/ruby/query.c +++ b/bindings/ruby/query.c @@ -1,6 +1,6 @@ /* The Ruby interface to the notmuch mail library * - * Copyright © 2010, 2011 Ali Polatel + * Copyright © 2010, 2011, 2012 Ali Polatel * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -127,3 +127,22 @@ notmuch_rb_query_search_messages (VALUE self) return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages); } + +/* + * call-seq: QUERY.count_messages => Fixnum + * + * Return an estimate of the number of messages matching a search + */ +VALUE +notmuch_rb_query_count_messages (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 UINT2FIX(notmuch_query_count_messages(query)); +} -- 1.7.10.1