From patchwork Wed Jun 26 08:59:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 14395 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 8A4F317160; Wed, 26 Jun 2019 10:00:16 +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,URIBL_BLOCKED autolearn=ham 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 3C8EA17101 for ; Wed, 26 Jun 2019 10:00:16 +0100 (BST) Received: from localhost ([::1]:37864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hg3mp-00023Y-Sq for patchwork@mira.cbaines.net; Wed, 26 Jun 2019 05:00:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55362) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hg3mi-0001wj-SD for guix-patches@gnu.org; Wed, 26 Jun 2019 05:00:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hg3mc-0008Cs-TU for guix-patches@gnu.org; Wed, 26 Jun 2019 05:00:08 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:48931) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hg3mc-0008CV-Pi for guix-patches@gnu.org; Wed, 26 Jun 2019 05:00:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hg3mc-00006g-ME for guix-patches@gnu.org; Wed, 26 Jun 2019 05:00:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#36390] [PATCH 1/3] ui: 'relevance' considers regexps connected with a logical and. References: <20190626084338.3153-1-ludo@gnu.org> In-Reply-To: <20190626084338.3153-1-ludo@gnu.org> Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 26 Jun 2019 09:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36390 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 36390@debbugs.gnu.org Received: via spool by 36390-submit@debbugs.gnu.org id=B36390.156153956132754 (code B ref 36390); Wed, 26 Jun 2019 09:00:02 +0000 Received: (at 36390) by debbugs.gnu.org; 26 Jun 2019 08:59:21 +0000 Received: from localhost ([127.0.0.1]:34236 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hg3lw-0008WD-O9 for submit@debbugs.gnu.org; Wed, 26 Jun 2019 04:59:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49238) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hg3lu-0008Vy-9x for 36390@debbugs.gnu.org; Wed, 26 Jun 2019 04:59:18 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:47248) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hg3lp-0007Vr-3L; Wed, 26 Jun 2019 04:59:13 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=34310 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hg3ln-0003qF-7z; Wed, 26 Jun 2019 04:59:11 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Wed, 26 Jun 2019 10:59:02 +0200 Message-Id: <20190626085904.3560-1-ludo@gnu.org> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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 * guix/ui.scm (relevance)[score]: Change to return 0 when one of REGEXPS doesn't match. * tests/ui.scm ("package-relevance"): New test. --- guix/ui.scm | 25 ++++++++++++++----------- tests/ui.scm | 27 ++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/guix/ui.scm b/guix/ui.scm index 0b4fe144b6..d9dbe4a652 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -1256,17 +1256,20 @@ 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) - (let ((counts (map (lambda (regexp) - (match (fold-matches regexp str '() cons) - (() 0) - ((m) (if (string=? (match:substring m) str) - 5 ;exact match - 1)) - (lst (length lst)))) - regexps))) - ;; Compute a score that's proportional to the number of regexps matched - ;; and to the number of matches for each regexp. - (* (length counts) (reduce + 0 counts)))) + (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)) + + ;; Return zero if one of REGEXPS doesn't match. + (if (any zero? scores) + 0 + (reduce + 0 scores))) (fold (lambda (metric relevance) (match metric diff --git a/tests/ui.scm b/tests/ui.scm index 1e98e3534b..2138e23369 100644 --- a/tests/ui.scm +++ b/tests/ui.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013, 2014, 2015, 2016, 2017 Ludovic Courtès +;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2019 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -22,10 +22,12 @@ #:use-module (guix profiles) #:use-module (guix store) #:use-module (guix derivations) + #:use-module ((gnu packages) #:select (specification->package)) #:use-module (guix tests) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-19) + #:use-module (srfi srfi-26) #:use-module (srfi srfi-64) #:use-module (ice-9 regex)) @@ -260,4 +262,27 @@ Second line" 24)) "ISO-8859-1") (show-manifest-transaction store m t)))))))) +(test-assert "package-relevance" + (let ((guile (specification->package "guile")) + (gcrypt (specification->package "guile-gcrypt")) + (go (specification->package "go")) + (gnugo (specification->package "gnugo")) + (rx (cut make-regexp <> regexp/icase)) + (>0 (cut > <> 0)) + (=0 zero?)) + (and (>0 (package-relevance guile + (map rx '("scheme")))) + (>0 (package-relevance guile + (map rx '("scheme" "implementation")))) + (>0 (package-relevance gcrypt + (map rx '("guile" "crypto")))) + (=0 (package-relevance guile + (map rx '("guile" "crypto")))) + (>0 (package-relevance go + (map rx '("go")))) + (=0 (package-relevance go + (map rx '("go" "game")))) + (>0 (package-relevance gnugo + (map rx '("go" "game"))))))) + (test-end "ui")