From nobody Tue May 13 15:38:26 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 1538145958305576.6750711539913; Fri, 28 Sep 2018 07:45:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 044F930001E7; Fri, 28 Sep 2018 14:45:57 +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 E9CEE261AB; Fri, 28 Sep 2018 14:45:56 +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 D84214BB74; Fri, 28 Sep 2018 14:45:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8SEjsWq024613 for ; Fri, 28 Sep 2018 10:45:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 79170600CD; Fri, 28 Sep 2018 14:45:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 70CC2600C7 for ; Fri, 28 Sep 2018 14:45:51 +0000 (UTC) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 4631B86647 for ; Fri, 28 Sep 2018 14:45:50 +0000 (UTC) Received: by mail-wm1-f45.google.com with SMTP id r1-v6so2019951wmh.0 for ; Fri, 28 Sep 2018 07:45:50 -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.47 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Sep 2018 07:45:47 -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=lJz9Pknhhl5moG+1ybKTzJDQV0njV5vqElewJawA+Kw=; b=TcbSdqsU+EDf/aTUEQjwAWmkjacF4i6MI3yB/jpgIZ3N6/LkpDKZGF6/tcGJ0qqf+t lmYNxdYI3Pju6K2TfD5hIlAyEU+eyeKHZBNNK5owKduHmAr3/CLQavvTNZRUCujm0gsr D70o13NbRG5YK18LoAoEWUSjFlVWUDh7qG9hiw4Y5po80N9/jHEGTadDke4ZFTbAeqpr ONGbP3MrdqyMZkjwbu6NbRO0KqqZEVUfrxsCZn4zvOjF0N6iv5ayilCpr5FKIm6momE5 hMiQY8/FUUdBdi4ZeQsoB+xqZREv98sntpusUR8fWUw+oGyely2obOBr6wXy4nqe204G qJ6Q== 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=lJz9Pknhhl5moG+1ybKTzJDQV0njV5vqElewJawA+Kw=; b=o5g8u+G3NRAn7czRyNeLLAApvGDieyqOJAvvpIJJX+5455RiQVeOz1KEVFT1b+Z0D/ GI4lWOz3+RX4V0riwAPhtbGZcyv4yRkdcK7REz51uPMPZUf0aKZRk4+tvMlPlPoiV5Bq 8ORNtf8NzHe4bkSh53PF1Bl0ZyNSXZ0FMTmw5ElYNNGDpQH2gVW1NYzJgRIyzjYm3zzI PZYn+Am7vxvnV07dXc+VaYuaFGwcNnglOJEJ9e7GXFZt/NPJ2o36CH9c7ivOKdUJstLn onx2jAEw3xZZx8ytgtFpBDwFx69F771zbJME18XZy8dyiLBzfJunaNxq+tWu/WwcfEb2 h+cw== X-Gm-Message-State: ABuFfoizp+WUQyK/jAnR7r4jstg/R79EjlRG/wuedkBL4ultmjOnhfXg jWUlVSSy1l4x1mpFE83dF192av92e5Y= X-Google-Smtp-Source: ACcGV62nn9t/qmeP95qOIzvzRHdwSlGA5LNN5yc/w1hZtYpDURugbPJv1Kmmftl+Z99TGZZiqVvezw== X-Received: by 2002:a1c:b20d:: with SMTP id b13-v6mr1974542wmf.141.1538145948555; Fri, 28 Sep 2018 07:45:48 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Fri, 28 Sep 2018 16:45:34 +0200 Message-Id: <20180928144537.5051-8-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.26]); Fri, 28 Sep 2018 14:45:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 28 Sep 2018 14:45:50 +0000 (UTC) for IP:'209.85.128.45' DOMAIN:'mail-wm1-f45.google.com' HELO:'mail-wm1-f45.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.488 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.128.45 mail-wm1-f45.google.com 209.85.128.45 mail-wm1-f45.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH v2 07/10] search: add search by result 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 28 Sep 2018 14:45:57 +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" Signed-off-by: Paolo Bonzini --- api/search.py | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/api/search.py b/api/search.py index 90e6596..a2644c5 100644 --- a/api/search.py +++ b/api/search.py @@ -8,10 +8,23 @@ # This work is licensed under the MIT License. Please see the LICENSE fil= e or # http://opensource.org/licenses/MIT. =20 -from .models import Message, MessageProperty, Result +from .models import Message, MessageProperty, MessageResult, Result from functools import reduce from django.db.models import Q =20 +from django.db.models import Lookup +from django.db.models.fields import Field + +@Field.register_lookup +class NotEqual(Lookup): + lookup_name =3D 'ne' + + def as_sql(self, compiler, connection): + lhs, lhs_params =3D self.process_lhs(compiler, connection) + rhs, rhs_params =3D self.process_rhs(compiler, connection) + params =3D lhs_params + rhs_params + return '%s <> %s' % (lhs, rhs), params + class InvalidSearchTerm(Exception): pass =20 @@ -94,6 +107,21 @@ Compare the address info of message. Example: =20 --- =20 +### Search by result + +Syntax: + + - pending:NAME, success:NAME, failure:NAME, running:NAME + +where NAME can be e.g. "git", "testing", "testing.TEST-NAME" + +Example: + + success:git + failure:testing.FreeBSD + +--- + ### Reverse condition =20 - Syntax: !TERM @@ -132,6 +160,10 @@ 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 _make_filter_result(self, term, **kwargs): + q =3D Q(name=3Dterm, **kwargs) | Q(name__startswith=3Dterm+'.', **= kwargs) + return self._make_filter_subquery(MessageResult, q) + def _make_filter_age(self, cond): import datetime def human_to_seconds(n, unit): @@ -217,6 +249,17 @@ Search text keyword in the email message. Example: return Q(last_comment_date__isnull=3DFalse) else: return Q(properties__name=3Dcond) + elif term.startswith("failure:"): + return self._make_filter_result(term[8:], status=3DResult.FAIL= URE) + elif term.startswith("success:"): + # What we want is "all results are successes", but the only wa= y to + # express it is "there is a result and not (any result is not = a success)". + return self._make_filter_result(term[8:]) \ + & ~self._make_filter_result(term[8:], status__ne=3DResult.= SUCCESS) + elif term.startswith("pending:"): + return self._make_filter_result(term[8:], status=3DResult.PEND= ING) + elif term.startswith("running:"): + return self._make_filter_result(term[8:], status=3DResult.RUNN= ING) elif term.startswith("project:"): cond =3D term[term.find(":") + 1:] self._projects.add(cond) --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel