From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id KEWDBYH3A2E7hQEAgWs5BA (envelope-from ) for ; Fri, 30 Jul 2021 14:58:41 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id cN5BAYH3A2GvJQAA1q6Kng (envelope-from ) for ; Fri, 30 Jul 2021 12:58:41 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A575D10EC4 for ; Fri, 30 Jul 2021 14:58:39 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 6B2CA299F3; Fri, 30 Jul 2021 08:57:17 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 528CB29203 for ; Fri, 30 Jul 2021 08:56:36 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 4AAA75FD17; Fri, 30 Jul 2021 08:56:36 -0400 (EDT) Received: (nullmailer pid 2166906 invoked by uid 1000); Fri, 30 Jul 2021 12:56:10 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 20/27] lib: generate actual Xapian query for "*" and "" Date: Fri, 30 Jul 2021 09:56:00 -0300 Message-Id: <20210730125607.2165433-21-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210730125607.2165433-1-david@tethera.net> References: <20210730125607.2165433-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: YND3J5PRFPR3AZZ6N5MF3DAEWJI34XP7 X-Message-ID-Hash: YND3J5PRFPR3AZZ6N5MF3DAEWJI34XP7 X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1627649919; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=oPd0MVNI6AVx6B6l8m6NGSegZNzHpQD5NMZGoCNxV4A=; b=ZVQDjP1TYq9+B9ZZ+IUMysoNLESymNlFt/86sXeTxAwsCCfineSou6aEvWaZdEu1KaxJ3E Mnsx+TzWd7YfTO4FRurAuvOPymwtP2QcOenqAxuqMvp3wPR2IyHEvcsH6em+Dl51a0kgrO Xu4bwyblAQ7B6eGBMpQK+IZHx1EX/0J+UCfMYtk3y51LmhCLfPCMveDkbmnleRWS3g38gZ s1XxH9PiGNcDv1PiGS+u2tXeUsEEvw5FaqHJKJPdHAfA6XEnqqiucswfi6m+k3B0oSyFmQ CM88EGBYyc1DoNPrkBhWW1ZWbOuuKabAb92v3bbZZktK1aKIRHzldJ8FdgW41w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1627649919; a=rsa-sha256; cv=none; b=QXFhUq8pAQFlbmw0H4fd6LM0L5vtsDuZJyiIWwNBsRRkm0f2VILgdD6Jp7xLutk7I/FAos Ej1nvttYG1E0TOQXBqJ2cbGRINgRx9+kGqPqAwOmv0+r+A5gt23GMFMDY8tIIVor6aOCiT nflUpMrshykT4fC8C3pK1PhZjL/Rz18Ay+Dxj/vhjEPDPvq5y54QYp/+D3Jlf4HnXf1UbG FgRvpBNKmgJJGqfgyIdG0AhzAgeo6zZV4cEibsn5CqM+hJR9WOCmjjoD+1mUtmpPJkocQx hvgECvZZevAfM7WcP6o/UNKHuJ2udXs+86zrFrFPQ4vvBH0wcIbiVnfKqkS6Mg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 0.52 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: A575D10EC4 X-Spam-Score: 0.52 X-Migadu-Scanner: scn0.migadu.com X-TUID: txAAGjkof03p The previous code had the somewhat bizarre effect that the (notmuch specific) query string was "*" (interpreted as MatchAll) and the allegedly parsed xapian_query was "MatchNothing". This commit also reduces code duplication. --- lib/query.cc | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/query.cc b/lib/query.cc index 56f90e1c..57596f48 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -182,11 +182,16 @@ static notmuch_status_t _notmuch_query_ensure_parsed_xapian (notmuch_query_t *query) { try { - query->xapian_query = - query->notmuch->query_parser-> - parse_query (query->query_string, NOTMUCH_QUERY_PARSER_FLAGS); + if (strcmp (query->query_string, "") == 0 || + strcmp (query->query_string, "*") == 0) { + query->xapian_query = Xapian::Query::MatchAll; + } else { + query->xapian_query = + query->notmuch->query_parser-> + parse_query (query->query_string, NOTMUCH_QUERY_PARSER_FLAGS); - _notmuch_query_cache_terms (query); + _notmuch_query_cache_terms (query); + } query->parsed = true; } catch (const Xapian::Error &error) { @@ -331,7 +336,6 @@ _notmuch_query_search_documents (notmuch_query_t *query, notmuch_messages_t **out) { notmuch_database_t *notmuch = query->notmuch; - const char *query_string = query->query_string; notmuch_mset_messages_t *messages; notmuch_status_t status; @@ -361,13 +365,9 @@ _notmuch_query_search_documents (notmuch_query_t *query, Xapian::MSet mset; Xapian::MSetIterator iterator; - if (strcmp (query_string, "") == 0 || - strcmp (query_string, "*") == 0) { - final_query = mail_query; - } else { - final_query = Xapian::Query (Xapian::Query::OP_AND, - mail_query, query->xapian_query); - } + final_query = Xapian::Query (Xapian::Query::OP_AND, + mail_query, query->xapian_query); + messages->base.excluded_doc_ids = NULL; if ((query->omit_excluded != NOTMUCH_EXCLUDE_FALSE) && (query->exclude_terms)) { @@ -688,7 +688,6 @@ notmuch_status_t _notmuch_query_count_documents (notmuch_query_t *query, const char *type, unsigned *count_out) { notmuch_database_t *notmuch = query->notmuch; - const char *query_string = query->query_string; Xapian::doccount count = 0; notmuch_status_t status; @@ -704,13 +703,8 @@ _notmuch_query_count_documents (notmuch_query_t *query, const char *type, unsign Xapian::Query final_query, exclude_query; Xapian::MSet mset; - if (strcmp (query_string, "") == 0 || - strcmp (query_string, "*") == 0) { - final_query = mail_query; - } else { - final_query = Xapian::Query (Xapian::Query::OP_AND, - mail_query, query->xapian_query); - } + final_query = Xapian::Query (Xapian::Query::OP_AND, + mail_query, query->xapian_query); exclude_query = _notmuch_exclude_tags (query); -- 2.30.2