From patchwork Wed Sep 18 15:57:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Tournier X-Patchwork-Id: 15408 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id AF6E6173FF; Wed, 18 Sep 2019 17:41:22 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 62244173FA for ; Wed, 18 Sep 2019 17:41:22 +0100 (BST) Received: from localhost ([::1]:60844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAd17-0001LA-CB for patchwork@mira.cbaines.net; Wed, 18 Sep 2019 12:41:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54557) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAcMC-00043w-9D for guix-patches@gnu.org; Wed, 18 Sep 2019 11:59:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAcMA-0007xW-W3 for guix-patches@gnu.org; Wed, 18 Sep 2019 11:59:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45913) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iAcMA-0007xS-Sz for guix-patches@gnu.org; Wed, 18 Sep 2019 11:59:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iAcMA-0007cK-Ng for guix-patches@gnu.org; Wed, 18 Sep 2019 11:59:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#37448] [PATCH] ui: 'relevance' connects regexps with a logical and. Resent-From: zimoun Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 18 Sep 2019 15:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 37448 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 37448@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.156882231129231 (code B ref -1); Wed, 18 Sep 2019 15:59:02 +0000 Received: (at submit) by debbugs.gnu.org; 18 Sep 2019 15:58:31 +0000 Received: from localhost ([127.0.0.1]:54734 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iAcLe-0007bP-ND for submit@debbugs.gnu.org; Wed, 18 Sep 2019 11:58:31 -0400 Received: from lists.gnu.org ([209.51.188.17]:33903) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iAcLb-0007bE-Uz for submit@debbugs.gnu.org; Wed, 18 Sep 2019 11:58:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54483) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAcLa-0003J4-4K for guix-patches@gnu.org; Wed, 18 Sep 2019 11:58:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAcLY-0007kq-P2 for guix-patches@gnu.org; Wed, 18 Sep 2019 11:58:25 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:35666) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iAcLY-0007jv-Io for guix-patches@gnu.org; Wed, 18 Sep 2019 11:58:24 -0400 Received: by mail-wm1-x344.google.com with SMTP id y21so682920wmi.0 for ; Wed, 18 Sep 2019 08:58:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ik/8VTq+SmL7Rw/0efRshmThF/HNJuUX9vBQIc+GLRk=; b=V0iAuDejuI9xUR6nJ04yr/KiR2632HivDz+XJQ2UqLk0jCwYR0VEBtlv5nALRbcQLb 3sJQ+yw/+TBoQaRdhzuNA4iED9okAFH1/jvKvShm/+f2mV12n/kVXrl9yxw/w5r9V+QK J65c7/A96SI+nmEWqBVsXhnJieuV1QWtKvs9IHhgZvytYoQgRouGwoLD9aDhT/ZBtOcs seNzOVVFfhU0wWiGHG6Vh7mHW4rBVOa5FWfuT9Z+r46aiWIQ/UfVeJJm2h8bJy7Btmnb bxJ2eu5EGrYQXJy5yXzEwpfE9kUAFc3oWD0XepLgWvs6q7CzNXo1oaf2+ccxgLJT3VHx TQeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ik/8VTq+SmL7Rw/0efRshmThF/HNJuUX9vBQIc+GLRk=; b=qpL5JfYhmLCttwh6Gg4VK4lT2xCGMsWDm9v/ZI7bLwcQsnzv6DFiKxRSZ1LtlnmHF7 ewnV91Pd2Txc/9pNv1/cpx3EWfvnsSXMSK7lEJvdxl3CCKqmhUeMgOEsBvY+IAfw0AMT GMRy3We2jKUn3Mk/cnteYb67vwTODy2SXnkoY12T4pasOn6g81SbHhzNkEiJysNGNqXB jOln/EHtlQZQX8PLn1vYs1kLRDA5F0ksKuNoQF9eJh6CFxOlwrT/5HYRLPXLgQU0/rat ZsmCKUOo5FKO+AgTHElcg/+vrtpdT8sM/wtU0DZ4LiwgbM2g9FJSUAIkkVqjOWupFHAb p50g== X-Gm-Message-State: APjAAAVl6fqwi9IczfOHciPGRFfijIo4NAQYNGuX2O3PZTg0GSzylI/4 OBR+YQY2fap2wK1qCjREVH12EwD/ X-Google-Smtp-Source: APXvYqxSBsDvl718W2qSllX3ia2okADUuGioDbsk1xOZtbxCybSNQ8EjIsmrWk5XkShFSf737uIhAw== X-Received: by 2002:a7b:c757:: with SMTP id w23mr3400486wmk.31.1568822302860; Wed, 18 Sep 2019 08:58:22 -0700 (PDT) Received: from pfiuh02.univ-paris-diderot.fr ([193.48.40.241]) by smtp.gmail.com with ESMTPSA id q22sm3351758wmj.31.2019.09.18.08.58.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Sep 2019 08:58:22 -0700 (PDT) From: zimoun Date: Wed, 18 Sep 2019 17:57:57 +0200 Message-Id: <20190918155757.4198-1-zimon.toutoune@gmail.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Fixes . Previously, the logical and connecting the regexps did not output the expected results (introduced in 8874faaaac665100a095ef25e39c9a389f5a397f). * guix/ui.scm (relevance) [score]: Change its arguments. [regexp->score]: New procedure. * tests/ui.scm ("package-relevance"): Add test. --- guix/ui.scm | 48 ++++++++++++++++++++++++------------------------ tests/ui.scm | 5 ++++- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/guix/ui.scm b/guix/ui.scm index 7920335928..4be31db047 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -13,6 +13,7 @@ ;;; Copyright © 2018 Ricardo Wurmus ;;; Copyright © 2019 Chris Marusich ;;; Copyright © 2019 Tobias Geerinckx-Rice +;;; Copyright © 2019 Simon Tournier ;;; ;;; This file is part of GNU Guix. ;;; @@ -1281,33 +1282,32 @@ weight of this field in the final score. A score of zero means that OBJ does not match any of REGEXPS. The higher the score, the more relevant OBJ is to REGEXPS." - (define (score str) - (define scores - (map (lambda (regexp) - (fold-matches regexp str 0 - (lambda (m score) - (+ score - (if (string=? (match:substring m) str) - 5 ;exact match - 1))))) - regexps)) - + (define (score regexp str) + (fold-matches regexp str 0 + (lambda (m score) + (+ score + (if (string=? (match:substring m) str) + 5 ;exact match + 1))))) + + (define (regexp->score regexp) + (let ((score-regexp (lambda (str) (score regexp str)))) + (fold (lambda (metric relevance) + (match metric + ((field . weight) + (match (field obj) + (#f relevance) + ((? string? str) + (+ relevance (* (score-regexp str) weight))) + ((lst ...) + (+ relevance (* weight (apply + (map score-regexp lst))))))))) + 0 metrics))) + + (let ((scores (map regexp->score regexps))) ;; Return zero if one of REGEXPS doesn't match. (if (any zero? scores) 0 - (reduce + 0 scores))) - - (fold (lambda (metric relevance) - (match metric - ((field . weight) - (match (field obj) - (#f relevance) - ((? string? str) - (+ relevance (* (score str) weight))) - ((lst ...) - (+ relevance (* weight (apply + (map score lst))))))))) - 0 - metrics)) + (reduce + 0 scores)))) (define %package-metrics ;; Metrics used to compute the "relevance score" of a package against a set diff --git a/tests/ui.scm b/tests/ui.scm index 2138e23369..d8573e88d8 100644 --- a/tests/ui.scm +++ b/tests/ui.scm @@ -267,6 +267,7 @@ Second line" 24)) (gcrypt (specification->package "guile-gcrypt")) (go (specification->package "go")) (gnugo (specification->package "gnugo")) + (libb2 (specification->package "libb2")) (rx (cut make-regexp <> regexp/icase)) (>0 (cut > <> 0)) (=0 zero?)) @@ -283,6 +284,8 @@ Second line" 24)) (=0 (package-relevance go (map rx '("go" "game")))) (>0 (package-relevance gnugo - (map rx '("go" "game"))))))) + (map rx '("go" "game")))) + (>0 (package-relevance libb2 + (map rx '("crypto" "library"))))))) (test-end "ui")