From unknown Tue Jun 17 21:54:05 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#36390 <36390@debbugs.gnu.org> To: bug#36390 <36390@debbugs.gnu.org> Subject: Status: [PATCH 0/3] Improve 'guix search' relevance and display Reply-To: bug#36390 <36390@debbugs.gnu.org> Date: Wed, 18 Jun 2025 04:54:05 +0000 retitle 36390 [PATCH 0/3] Improve 'guix search' relevance and display reassign 36390 guix-patches submitter 36390 Ludovic Court=C3=A8s severity 36390 normal tag 36390 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 26 04:43:56 2019 Received: (at submit) by debbugs.gnu.org; 26 Jun 2019 08:43:56 +0000 Received: from localhost ([127.0.0.1]:34205 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hg3X1-00088p-TK for submit@debbugs.gnu.org; Wed, 26 Jun 2019 04:43:56 -0400 Received: from lists.gnu.org ([209.51.188.17]:42380) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hg3X0-00088i-Ia for submit@debbugs.gnu.org; Wed, 26 Jun 2019 04:43:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50310) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hg3Wz-0000s7-KQ for guix-patches@gnu.org; Wed, 26 Jun 2019 04:43:54 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=ALL_TRUSTED,BAYES_50 autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:470:142:3::e]:47106) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hg3Wz-0002YG-GV; Wed, 26 Jun 2019 04:43:53 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=34174 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hg3Wz-0000pw-0j; Wed, 26 Jun 2019 04:43:53 -0400 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= To: guix-patches@gnu.org Subject: [PATCH 0/3] Improve 'guix search' relevance and display Date: Wed, 26 Jun 2019 10:43:38 +0200 Message-Id: <20190626084338.3153-1-ludo@gnu.org> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit Cc: =?UTF-8?q?Ludovic=20Court=C3=A8s?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hello Guix! This improves ‘guix search’ in two ways: 1. The relevance score now excludes things that do not match *all* the regexps. So ‘guix search go game’ returns 28 results instead of 1,245 and the first one is ‘gnugo’; ‘guix search ssh client’ returns 14 results instead of 510; ‘guix search guile crypto’ returns just ‘guile-gcrypt’ instead of 279 results. 2. ‘guix search’ and ‘guix system search’ now write at most a full screen of results. You can pipe through a pager to view all the results. Thoughts? Ludo’. Ludovic Courtès (3): ui: 'relevance' considers regexps connected with a logical and. syscalls: Add 'terminal-rows'. ui: Add 'display-search-results' and use it. guix/build/syscalls.scm | 37 +++++++++++------ guix/scripts/package.scm | 41 ++++++++----------- guix/scripts/system/search.scm | 44 +++++++++----------- guix/ui.scm | 75 ++++++++++++++++++++++++++++------ tests/syscalls.scm | 5 ++- tests/ui.scm | 27 +++++++++++- 6 files changed, 155 insertions(+), 74 deletions(-) -- 2.22.0 From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 26 04:59:21 2019 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: =?UTF-8?q?Ludovic=20Court=C3=A8s?= To: 36390@debbugs.gnu.org Subject: [PATCH 1/3] ui: 'relevance' considers regexps connected with a logical and. 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 36390 Cc: =?UTF-8?q?Ludovic=20Court=C3=A8s?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) * 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") -- 2.22.0 From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 26 04:59:23 2019 Received: (at 36390) by debbugs.gnu.org; 26 Jun 2019 08:59:23 +0000 Received: from localhost ([127.0.0.1]:34240 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hg3lz-00004w-85 for submit@debbugs.gnu.org; Wed, 26 Jun 2019 04:59:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49242) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hg3lw-0008W1-Nn for 36390@debbugs.gnu.org; Wed, 26 Jun 2019 04:59:21 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:47250) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hg3lr-0007XM-GB; Wed, 26 Jun 2019 04:59:15 -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 1hg3lp-0003qF-FN; Wed, 26 Jun 2019 04:59:14 -0400 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= To: 36390@debbugs.gnu.org Subject: [PATCH 2/3] syscalls: Add 'terminal-rows'. Date: Wed, 26 Jun 2019 10:59:03 +0200 Message-Id: <20190626085904.3560-2-ludo@gnu.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190626085904.3560-1-ludo@gnu.org> References: <20190626085904.3560-1-ludo@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 36390 Cc: =?UTF-8?q?Ludovic=20Court=C3=A8s?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) * guix/build/syscalls.scm (terminal-dimension): New procedure. (terminal-columns): Rewrite in terms of 'terminal-dimension'. (terminal-rows): New procedure. * tests/syscalls.scm ("terminal-rows"): New test. --- guix/build/syscalls.scm | 37 +++++++++++++++++++++++++------------ tests/syscalls.scm | 5 ++++- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index 5c2eb3c14d..eb045cbd1c 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -146,6 +146,7 @@ window-size-y-pixels terminal-window-size terminal-columns + terminal-rows utmpx? utmpx-login-type @@ -1871,23 +1872,17 @@ corresponds to the TIOCGWINSZ ioctl." (list (strerror err)) (list err))))) -(define* (terminal-columns #:optional (port (current-output-port))) - "Return the best approximation of the number of columns of the terminal at -PORT, trying to guess a reasonable value if all else fails. The result is -always a positive integer." - (define (fall-back) - (match (and=> (getenv "COLUMNS") string->number) - (#f 80) - ((? number? columns) - (if (> columns 0) columns 80)))) - +(define (terminal-dimension window-dimension port fall-back) + "Return the terminal dimension defined by WINDOW-DIMENSION, one of +'window-size-columns' or 'window-size-rows' for PORT. If PORT does not +correspond to a terminal, return the value returned by FALL-BACK." (catch 'system-error (lambda () (if (file-port? port) - (match (window-size-columns (terminal-window-size port)) + (match (window-dimension (terminal-window-size port)) ;; Things like Emacs shell-mode return 0, which is unreasonable. (0 (fall-back)) - ((? number? columns) columns)) + ((? number? n) n)) (fall-back))) (lambda args (let ((errno (system-error-errno args))) @@ -1900,6 +1895,24 @@ always a positive integer." (fall-back) (apply throw args)))))) +(define* (terminal-columns #:optional (port (current-output-port))) + "Return the best approximation of the number of columns of the terminal at +PORT, trying to guess a reasonable value if all else fails. The result is +always a positive integer." + (define (fall-back) + (match (and=> (getenv "COLUMNS") string->number) + (#f 80) + ((? number? columns) + (if (> columns 0) columns 80)))) + + (terminal-dimension window-size-columns port fall-back)) + +(define* (terminal-rows #:optional (port (current-output-port))) + "Return the best approximation of the number of rows of the terminal at +PORT, trying to guess a reasonable value if all else fails. The result is +always a positive integer." + (terminal-dimension window-size-rows port (const 25))) + ;;; ;;; utmpx. diff --git a/tests/syscalls.scm b/tests/syscalls.scm index 3e267c9f01..eeb223b950 100644 --- a/tests/syscalls.scm +++ b/tests/syscalls.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2014, 2015, 2016, 2017, 2018 Ludovic Courtès +;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès ;;; Copyright © 2015 David Thompson ;;; ;;; This file is part of GNU Guix. @@ -538,6 +538,9 @@ (> (terminal-columns (open-input-string "Join us now, share the software!")) 0)) +(test-assert "terminal-rows" + (> (terminal-rows) 0)) + (test-assert "utmpx-entries" (match (utmpx-entries) (((? utmpx? entries) ...) -- 2.22.0 From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 26 04:59:24 2019 Received: (at 36390) by debbugs.gnu.org; 26 Jun 2019 08:59:24 +0000 Received: from localhost ([127.0.0.1]:34242 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hg3lz-00004y-J9 for submit@debbugs.gnu.org; Wed, 26 Jun 2019 04:59:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49260) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hg3ly-0008W4-8V for 36390@debbugs.gnu.org; Wed, 26 Jun 2019 04:59:22 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:47251) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hg3lt-0007Yv-0L; Wed, 26 Jun 2019 04:59:17 -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 1hg3lr-0003qF-SF; Wed, 26 Jun 2019 04:59:16 -0400 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= To: 36390@debbugs.gnu.org Subject: [PATCH 3/3] ui: Add 'display-search-results' and use it. Date: Wed, 26 Jun 2019 10:59:04 +0200 Message-Id: <20190626085904.3560-3-ludo@gnu.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190626085904.3560-1-ludo@gnu.org> References: <20190626085904.3560-1-ludo@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 36390 Cc: =?UTF-8?q?Ludovic=20Court=C3=A8s?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) * guix/ui.scm (display-search-results): New procedure. * guix/scripts/package.scm (find-packages-by-description): Remove 'unzip2' call and return a list of pairs. (process-query): Change to use 'display-search-results'. * guix/scripts/system/search.scm (find-service-types): Remove 'unzip2' call and return a list of pairs. (guix-system-search): Use 'display-search-results'. --- guix/scripts/package.scm | 41 ++++++++++++---------------- guix/scripts/system/search.scm | 44 +++++++++++++----------------- guix/ui.scm | 50 +++++++++++++++++++++++++++++++++- 3 files changed, 86 insertions(+), 49 deletions(-) diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 5751123525..7b277b63f1 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -26,6 +26,7 @@ (define-module (guix scripts package) #:use-module (guix ui) #:use-module ((guix status) #:select (with-status-verbosity)) + #:use-module ((guix build syscalls) #:select (terminal-rows)) #:use-module (guix store) #:use-module (guix grafts) #:use-module (guix derivations) @@ -178,9 +179,9 @@ hooks\" run when building the profile." ;;; (define (find-packages-by-description regexps) - "Return two values: the list of packages whose name, synopsis, description, -or output matches at least one of REGEXPS sorted by relevance, and the list of -relevance scores." + "Return a list of pairs: packages whose name, synopsis, description, +or output matches at least one of REGEXPS sorted by relevance, and its +non-zero relevance score." (let ((matches (fold-packages (lambda (package result) (if (package-superseded package) result @@ -189,19 +190,19 @@ relevance scores." ((? zero?) result) (score - (cons (list package score) + (cons (cons package score) result))))) '()))) - (unzip2 (sort matches - (lambda (m1 m2) - (match m1 - ((package1 score1) - (match m2 - ((package2 score2) - (if (= score1 score2) - (string>? (package-full-name package1) - (package-full-name package2)) - (> score1 score2))))))))))) + (sort matches + (lambda (m1 m2) + (match m1 + ((package1 . score1) + (match m2 + ((package2 . score2) + (if (= score1 score2) + (string>? (package-full-name package1) + (package-full-name package2)) + (> score1 score2)))))))))) (define (transaction-upgrade-entry entry transaction) "Return a variant of TRANSACTION that accounts for the upgrade of ENTRY, a @@ -755,16 +756,10 @@ processed, #f otherwise." (('query 'search rx) rx) (_ #f)) opts)) - (regexps (map (cut make-regexp* <> regexp/icase) patterns))) + (regexps (map (cut make-regexp* <> regexp/icase) patterns)) + (matches (find-packages-by-description regexps))) (leave-on-EPIPE - (let-values (((packages scores) - (find-packages-by-description regexps))) - (for-each (lambda (package score) - (package->recutils package (current-output-port) - #:extra-fields - `((relevance . ,score)))) - packages - scores))) + (display-search-results matches (current-output-port))) #t)) (('show requested-name) diff --git a/guix/scripts/system/search.scm b/guix/scripts/system/search.scm index 955cdd1e95..5278062edd 100644 --- a/guix/scripts/system/search.scm +++ b/guix/scripts/system/search.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2017, 2018 Ludovic Courtès +;;; Copyright © 2017, 2018, 2019 Ludovic Courtès ;;; Copyright © 2018 Clément Lassieur ;;; ;;; This file is part of GNU Guix. @@ -139,9 +139,8 @@ columns." . 1))) (define (find-service-types regexps) - "Return two values: the list of service types whose name or description -matches at least one of REGEXPS sorted by relevance, and the list of relevance -scores." + "Return a list of service type/score pairs: service types whose name or +description matches REGEXPS sorted by relevance, and their score." (let ((matches (fold-service-types (lambda (type result) (match (relevance type regexps @@ -149,30 +148,25 @@ scores." ((? zero?) result) (score - (cons (list type score) result)))) + (cons (cons type score) result)))) '()))) - (unzip2 (sort matches - (lambda (m1 m2) - (match m1 - ((type1 score1) - (match m2 - ((type2 score2) - (if (= score1 score2) - (string>? (service-type-name* type1) - (service-type-name* type2)) - (> score1 score2))))))))))) + (sort matches + (lambda (m1 m2) + (match m1 + ((type1 . score1) + (match m2 + ((type2 . score2) + (if (= score1 score2) + (string>? (service-type-name* type1) + (service-type-name* type2)) + (> score1 score2)))))))))) (define (guix-system-search . args) (with-error-handling - (let ((regexps (map (cut make-regexp* <> regexp/icase) args))) + (let* ((regexps (map (cut make-regexp* <> regexp/icase) args)) + (matches (find-service-types regexps))) (leave-on-EPIPE - (let-values (((services scores) - (find-service-types regexps))) - (for-each (lambda (service score) - (service-type->recutils service - (current-output-port) - #:extra-fields - `((relevance . ,score)))) - services - scores)))))) + (display-search-results matches (current-output-port) + #:print service-type->recutils + #:command "guix system search"))))) diff --git a/guix/ui.scm b/guix/ui.scm index d9dbe4a652..363ef36dcd 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -46,7 +46,8 @@ #:use-module (guix serialization) #:use-module ((guix licenses) #:select (license? license-name)) #:use-module ((guix build syscalls) - #:select (free-disk-space terminal-columns)) + #:select (free-disk-space terminal-columns + terminal-rows)) #:use-module ((guix build utils) ;; XXX: All we need are the bindings related to ;; '&invoke-error'. However, to work around the bug described @@ -106,8 +107,11 @@ string->recutils package->recutils package-specification->name+version+output + relevance package-relevance + display-search-results + string->generations string->duration matching-generations @@ -1246,6 +1250,11 @@ WIDTH columns. EXTRA-FIELDS is a list of symbol/value pairs to emit." extra-fields) (newline port)) + +;;; +;;; Searching. +;;; + (define (relevance obj regexps metrics) "Compute a \"relevance score\" for OBJ as a function of its number of matches of REGEXPS and accordingly to METRICS. METRICS is list of @@ -1315,6 +1324,45 @@ score, the more relevant OBJ is to REGEXPS." zero means that PACKAGE does not match any of REGEXPS." (relevance package regexps %package-metrics)) +(define* (display-search-results matches port + #:key + (command "guix search") + (print package->recutils)) + "Display MATCHES, a list of object/score pairs, by calling PRINT on each of +them. If PORT is a terminal, print at most a full screen of results." + (define first-line + (port-line port)) + + (define max-rows + (and first-line (isatty? port) + (terminal-rows port))) + + (define (line-count str) + (string-count str #\newline)) + + (let loop ((matches matches)) + (match matches + (((package . score) rest ...) + (let ((text (call-with-output-string + (lambda (port) + (print package port + #:extra-fields + `((relevance . ,score))))))) + (if (and max-rows + (> (port-line port) first-line) ;print at least one result + (> (+ 4 (line-count text) (port-line port)) + max-rows)) + (unless (null? rest) + (display-hint (format #f (G_ "Run @code{~a ... | less} \ +to view all the results.") + command))) + (begin + (display text port) + (loop rest))))) + (() + #t)))) + + (define (string->generations str) "Return the list of generations matching a pattern in STR. This function accepts the following patterns: \"1\", \"1,2,3\", \"1..9\", \"1..\", \"..9\"." -- 2.22.0 From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 26 05:57:16 2019 Received: (at 36390) by debbugs.gnu.org; 26 Jun 2019 09:57:16 +0000 Received: from localhost ([127.0.0.1]:34296 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hg4g0-0003cp-7i for submit@debbugs.gnu.org; Wed, 26 Jun 2019 05:57:16 -0400 Received: from sender-of-o51.zoho.com ([135.84.80.216]:21203) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hg4fy-0003cg-9m for 36390@debbugs.gnu.org; Wed, 26 Jun 2019 05:57:14 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1561543029; cv=none; d=zoho.com; s=zohoarc; b=FBnEFsnvWPSZAOhbJ2mVZhM2+IsMZc4GjvnFNN3sTONkAUoVsOopn0rLK2MKQPRUlw5XLBXYIUhGlTVG9fERp7c6XwtIHh9rmAONXTQ1fxXrgkdyh7Qdgf1GKVoZ08Z48g888tvEA+miLI9LhLUnifTJxVMJUeCalcXvaM+1nAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561543029; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To:ARC-Authentication-Results; bh=IYP6So3XVwWxwXRkxsO3R9obXdgyZTkaK8HGGv8LFAU=; b=OFnziaBjhII2uRtJOCDNEl+EbVZZta52MguTA2PFCbK3QG3y4r1bHahD81VcRreGAGgFbDqcM9eTaHaniMVgwmknJfiQVa+j3Uw5v5is31s/H8U1g6xiPngRPNMueXSIkAX13QIf8XpP1Cp6ZE14zR+qXG+8UQpxwxxRKuHmuyQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass header.i=elephly.net; spf=pass smtp.mailfrom=rekado@elephly.net; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1561543029; s=zoho; d=elephly.net; i=rekado@elephly.net; h=References:From:To:Cc:Subject:In-reply-to:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding; l=922; bh=IYP6So3XVwWxwXRkxsO3R9obXdgyZTkaK8HGGv8LFAU=; b=K4XJ/QOB7+5U/nABbNJBLXEATrEx6dVnlColwiYzYa5TtWaY5q64oDhy12YIXzX5 Ha31uPJ+RUCg+cqOC2nEi0nOf1QV8aHqgj3RVGmGYJjIzvEZBFkcfsCvq6gHgR/vlCG LLhKk5JsSIhguCqupBdynIkg3BU508U9LxtV3x50= Received: from localhost (141.80.247.250 [141.80.247.250]) by mx.zohomail.com with SMTPS id 15615430287741018.517095476686; Wed, 26 Jun 2019 02:57:08 -0700 (PDT) References: <20190626084338.3153-1-ludo@gnu.org> User-agent: mu4e 1.2.0; emacs 26.2 From: Ricardo Wurmus To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#36390] [PATCH 0/3] Improve 'guix search' relevance and display In-reply-to: <20190626084338.3153-1-ludo@gnu.org> X-URL: https://elephly.net X-PGP-Key: https://elephly.net/rekado.pubkey X-PGP-Fingerprint: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC Date: Wed, 26 Jun 2019 11:57:05 +0200 Message-ID: <87ef3gsm8e.fsf@elephly.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 36390 Cc: 36390@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Ludovic Court=C3=A8s writes: > This improves =E2=80=98guix search=E2=80=99 in two ways: > > 1. The relevance score now excludes things that do not match *all* > the regexps. So =E2=80=98guix search go game=E2=80=99 returns 28 re= sults instead > of 1,245 and the first one is =E2=80=98gnugo=E2=80=99; =E2=80=98guix= search ssh client=E2=80=99 > returns 14 results instead of 510; =E2=80=98guix search guile crypto= =E2=80=99 > returns just =E2=80=98guile-gcrypt=E2=80=99 instead of 279 results. > > 2. =E2=80=98guix search=E2=80=99 and =E2=80=98guix system search=E2=80= =99 now write at most a full > screen of results. You can pipe through a pager to view all the > results. Perfect, thank you for the patches! (I wonder why you chose to use =E2=80=9C(cut > <> 0)=E2=80=9D instead of = =E2=80=9Cpositive?=E2=80=9D for checking if a value is greater than zero.) -- Ricardo From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 27 05:19:29 2019 Received: (at 36390-done) by debbugs.gnu.org; 27 Jun 2019 09:19:29 +0000 Received: from localhost ([127.0.0.1]:37418 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hgQYz-0004Yh-KB for submit@debbugs.gnu.org; Thu, 27 Jun 2019 05:19:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56876) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hgQYx-0004YU-Op for 36390-done@debbugs.gnu.org; Thu, 27 Jun 2019 05:19:28 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46544) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hgQYr-0005j9-MB; Thu, 27 Jun 2019 05:19:21 -0400 Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=44936 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hgQYr-0007KQ-AP; Thu, 27 Jun 2019 05:19:21 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Ricardo Wurmus Subject: Re: [bug#36390] [PATCH 0/3] Improve 'guix search' relevance and display References: <20190626084338.3153-1-ludo@gnu.org> <87ef3gsm8e.fsf@elephly.net> Date: Thu, 27 Jun 2019 11:19:20 +0200 In-Reply-To: <87ef3gsm8e.fsf@elephly.net> (Ricardo Wurmus's message of "Wed, 26 Jun 2019 11:57:05 +0200") Message-ID: <87y31n2xnr.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 36390-done Cc: 36390-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hello! Ricardo Wurmus skribis: > Ludovic Court=C3=A8s writes: > >> This improves =E2=80=98guix search=E2=80=99 in two ways: >> >> 1. The relevance score now excludes things that do not match *all* >> the regexps. So =E2=80=98guix search go game=E2=80=99 returns 28 r= esults instead >> of 1,245 and the first one is =E2=80=98gnugo=E2=80=99; =E2=80=98gui= x search ssh client=E2=80=99 >> returns 14 results instead of 510; =E2=80=98guix search guile crypt= o=E2=80=99 >> returns just =E2=80=98guile-gcrypt=E2=80=99 instead of 279 results. >> >> 2. =E2=80=98guix search=E2=80=99 and =E2=80=98guix system search=E2=80= =99 now write at most a full >> screen of results. You can pipe through a pager to view all the >> results. > > Perfect, thank you for the patches! It seems rather non-controversial. :-) Pushed: 4311cf965c ui: Add 'display-search-results' and use it. 4593f5a654 syscalls: Add 'terminal-rows'. 8874faaaac ui: 'relevance' considers regexps connected with a logical and. > (I wonder why you chose to use =E2=80=9C(cut > <> 0)=E2=80=9D instead of = =E2=80=9Cpositive?=E2=80=9D for > checking if a value is greater than zero.) Actually no good reasons, I wanted to amend it and then forgot. Thanks, Ludo=E2=80=99. From unknown Tue Jun 17 21:54:05 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 25 Jul 2019 11:24:12 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator