From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id IEJtA8IOJWGI4wAAgWs5BA (envelope-from ) for ; Tue, 24 Aug 2021 17:22:42 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id GH3BOsEOJWGCUAAAbx9fmQ (envelope-from ) for ; Tue, 24 Aug 2021 15:22: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)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A26548542 for ; Tue, 24 Aug 2021 17:22:41 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 2717D20675; Tue, 24 Aug 2021 11:21:19 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id D0A34205F9 for ; Tue, 24 Aug 2021 11:21:12 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id C6E4A5FD5C; Tue, 24 Aug 2021 11:21:12 -0400 (EDT) Received: (nullmailer pid 2942871 invoked by uid 1000); Tue, 24 Aug 2021 15:17:51 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 21/36] lib: generate actual Xapian query for "*" and "" Date: Tue, 24 Aug 2021 08:17:30 -0700 Message-Id: <20210824151745.2941868-22-david@tethera.net> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210824151745.2941868-1-david@tethera.net> References: <20210824151745.2941868-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: X3DJELR7O7WFOYESB6VDUN7PEZ4AEX4T X-Message-ID-Hash: X3DJELR7O7WFOYESB6VDUN7PEZ4AEX4T 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=1629818561; 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=nSMcExNXbnCtEzXNtYc2SmcvOgjuVjSnMKxdYtYoMoc=; b=WwTnuyN1N45ev7DS1/0zP4zYEwRco0HwjPQeBqTqeiLBZnkX+o17lv/Wi/t0Sdp3RjGZwB 1kBJK2Pj1sirxGPWEZZ67N938tfcbXZzh6A+d4iHyNwfs0tPOjz/sAm0/IANRTvZvjKwMr m/LsTfcTATmXyzAWlUcxUx6qFL268OFEsNJbbaicikyj0vi5z3yV0VArKjEz6jso8uyhXD a2Fl/asPQgZkj84qPtBKE+XGIMg0urbCSIu79PlSFKQKgafbzFiqvOPjxKPAX1uA9Bz58q RpaI5ICOT9l15v4QDO99l4Bp9HkhijEmohgo8MMc8bzcBRIpF/RpLD1OiJ1gYA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1629818561; a=rsa-sha256; cv=none; b=OIKt5PXinUO8pPTv2e6ZNpi2xLu7SkCy/4MUy7d5QAEd43h/QnxFkwgVmYVUGttDp+JelH 8jHj5Dvdz7sh+pm62a52XMToUv6B9Lek3k8Z7xa1xNrSJbp5rqGBAXIzK/UMN3Msg1rL+6 IMtgukO+RPxLAw0wRcKMAnjitiAmKg6ZO95x8JGp0wZUhOR2SULRi7t1ppyw9Sl/JCF0xW +bS2xFLidoaPjb7ZxyNxVN/vmg0MwHGHFkhREq+cwY50zJA4sR0g7iPNpDMNxubeiyRFkf Ud7TeCzV/THyaojxrGB06STVSg7i7OJa2PiqcjzB+3dNMCNY1u21su12YVi4Ng== 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.93 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: A26548542 X-Spam-Score: -0.93 X-Migadu-Scanner: scn0.migadu.com X-TUID: k6gwLa7leCc+ 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.32.0