From nobody Tue May 13 15:35:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538145955265947.3651983434002; Fri, 28 Sep 2018 07:45:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 19F123097075; Fri, 28 Sep 2018 14:45:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07B50600C7; Fri, 28 Sep 2018 14:45:54 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id ECE554BB74; Fri, 28 Sep 2018 14:45:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8SEjqxj024597 for ; Fri, 28 Sep 2018 10:45:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8F85E3066752; Fri, 28 Sep 2018 14:45:52 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 84B083001A47 for ; Fri, 28 Sep 2018 14:45:48 +0000 (UTC) Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 018E930820C1 for ; Fri, 28 Sep 2018 14:45:47 +0000 (UTC) Received: by mail-wr1-f52.google.com with SMTP id j15-v6so6670537wrt.8 for ; Fri, 28 Sep 2018 07:45:46 -0700 (PDT) Received: from donizetti.par1.mozilla.com ([2a00:8c40:243:232:de:fba5:535e:2dc2]) by smtp.gmail.com with ESMTPSA id n68-v6sm1884636wmn.5.2018.09.28.07.45.44 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Sep 2018 07:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=CKzC8ZPye34WAD5FBL6biQTO3SLSJehHdIoN8PgT2GM=; b=sSrOXGcamgfjNK08x6sdaK5KSdsrJSe/dhARAaY7uRcNPFlRr4UN64H2JpnknJVElR Ei1ESsSA+9DeD0+JZlf0W8JaEWXT2EL7JE3u3Xg0S5CCsSqG7c3QhLypcuE/w+bPayMj vQhvA0N5MnR1+4CnqmdQr0pfEhZp+5XJ9SOEBvnZpj9utzkWzc4Omo4TPyyC+FtmvACf VuroNx5pTDORFSFATrLD/OK670MOog2Jye6dMlKQGX0BsEoRz8wLiUVKNSH7K1846lr6 VKM/yR098ma4B32O/OGjK1rdUzqvGtd+CzQ9f1XeSbi2+S5D5K3W6PHGF7khxquYMPoa qEkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=CKzC8ZPye34WAD5FBL6biQTO3SLSJehHdIoN8PgT2GM=; b=GVxZg/rpbX4neTtqtbHf3fT9b/2p9o24zYzQ8PUK3lrxQpziQCRJZAm8TeVRYF7mHO QjsHO+JMwttS7cj05Dfsy8Z4nRp2A6PopGl9GXpqtM9xOdOu4jNxhkEBQK+AqEfrLSvH xZNdkZfq81HYTwcrLuqJjB/NenF09SEcg48hxng1e8PGe5dB68N17rKfiKtU8wb4KvkK mCDfGCFqZ7K9c5ftp7dsjbWboAWBbnr+cb8btRBY8EAe1SaIK48TN16SBHiSbAAon+4v z2iXVQ1MZG6jU3VjanSZyX2R65NkLhMTRzMM9SRWNTMVqLAoHFs0Ll/KsnR5kCokmni7 w2tw== X-Gm-Message-State: ABuFfogGZLG2ye8j+iYvXCz7jmUwoVRjuVKRzgYiT+GJtumk8yJ9CDwd Y+C66Lz+NXkpw2EqztPvQlZDP+oyHAk= X-Google-Smtp-Source: ACcGV62+pfVX/RPB0jhD58Bey1obdx0+GPPue9NfCEf1VdCR6CNU6llCz5wzlA234Ba6xBeHovERQA== X-Received: by 2002:adf:f5c6:: with SMTP id k6-v6mr2441940wrp.59.1538145945278; Fri, 28 Sep 2018 07:45:45 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Fri, 28 Sep 2018 16:45:31 +0200 Message-Id: <20180928144537.5051-5-pbonzini@redhat.com> In-Reply-To: <20180928144537.5051-1-pbonzini@redhat.com> References: <20180928144537.5051-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 28 Sep 2018 14:45:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 28 Sep 2018 14:45:47 +0000 (UTC) for IP:'209.85.221.52' DOMAIN:'mail-wr1-f52.google.com' HELO:'mail-wr1-f52.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.489 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.221.52 mail-wr1-f52.google.com 209.85.221.52 mail-wr1-f52.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH v2 04/10] search: move queryset out of _process_term X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 28 Sep 2018 14:45:54 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Make _process_term return a Q object as mentioned in the doc comment, rather than a QuerySet. Signed-off-by: Paolo Bonzini --- api/search.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/api/search.py b/api/search.py index b33aa1b..b1d20ec 100644 --- a/api/search.py +++ b/api/search.py @@ -9,6 +9,7 @@ # http://opensource.org/licenses/MIT. =20 from .models import Message, MessageProperty, Result +from functools import reduce from django.db.models import Q =20 class InvalidSearchTerm(Exception): @@ -128,19 +129,19 @@ Search text keyword in the email message. Example: message_ids =3D model.objects.filter(q).values('message_id') return Q(id__in=3Dmessage_ids) =20 - def _process_term(self, query, term, neg=3DFalse): + def _process_term(self, term, neg=3DFalse): """ Return a Q object that will be applied to the query """ def as_keywords(t): self._last_keywords.append(t) return Q(subject__icontains=3Dt) =20 if term.startswith("!"): - return self._process_term(query, term[1:], not neg) + return self._process_term(term[1:], not neg) if term.startswith("age:"): cond =3D term[term.find(":") + 1:] - q =3D self._process_age_term(query, cond) + q =3D self._process_age_term(cond) elif term[0] in "<>" and len(term) > 1: - q =3D self._process_age_term(query, term) + q =3D self._process_age_term(term) elif term.startswith("from:"): cond =3D term[term.find(":") + 1:] q =3D Q(sender__icontains=3Dcond) @@ -196,9 +197,9 @@ Search text keyword in the email message. Example: # Keyword in subject is the default q =3D as_keywords(term) if neg: - return query.exclude(pk__in=3Dquery.filter(q)) + return ~q else: - return query.filter(q) + return q =20 def last_keywords(self): return getattr(self, "_last_keywords", []) @@ -209,13 +210,13 @@ Search text keyword in the email message. Example: def search_series(self, *terms, queryset=3DNone): self._last_keywords =3D [] self._projects =3D set() + q =3D reduce(lambda x, y: x & y, + map(lambda t: self._process_term(t), terms), Q()) if queryset is None: queryset =3D Message.objects.series_heads() - for t in terms: - queryset =3D self._process_term(queryset, t) - return queryset + return queryset.filter(q) =20 - def _process_age_term(self, query, cond): + def _process_age_term(self, cond): import datetime def human_to_seconds(n, unit): if unit =3D=3D "d": --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel