GNU bug report logs - #58136
[PATCH] ui: Improve sort order when searching package names.

Previous Next

Package: guix-patches;

Reported by: Lars-Dominik Braun <lars <at> 6xq.net>

Date: Wed, 28 Sep 2022 09:28:02 UTC

Severity: normal

Tags: moreinfo, patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#58136: closed ([PATCH] ui: Improve sort order when searching
 package names.)
Date: Tue, 13 Dec 2022 13:30:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Tue, 13 Dec 2022 14:28:58 +0100
with message-id <87fsdjwhyd.fsf <at> gnu.org>
and subject line Re: [PATCH] ui: Improve sort order when searching package names.
has caused the debbugs.gnu.org bug report #58136,
regarding [PATCH] ui: Improve sort order when searching package names.
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
58136: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58136
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Lars-Dominik Braun <lars <at> 6xq.net>
To: guix-patches <at> gnu.org
Subject: [PATCH] ui: Improve sort order when searching package names.
Date: Wed, 28 Sep 2022 11:27:37 +0200
Hi,

we provide a `guix serach`-based package search to our users and noticed
that searching for “ggplot2” yields the package r-ggplot2 on position
11 only – when it should be the first. Looking at other potential
search terms (haven, shiny, ape, renv, here, ini, setuptools) reveals
similar issues.

I propose we also score the unprefixed package name, so SCORE can award
bonus points for a full string match. I don’t like that we have to
maintain a list of common prefixes for this and that package names are
scored twice now, but I can’t think of a better solution right now.

Cheers,
Lars


* guix/ui.scm (%package-metrics): Increase score for PACKAGE-NAME and
add score for unprefixed package name.
---
 guix/ui.scm | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/guix/ui.scm b/guix/ui.scm
index dad2b853ac..55b596ed35 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -1655,7 +1655,38 @@ (define (regexp->score regexp)
 (define %package-metrics
   ;; Metrics used to compute the "relevance score" of a package against a set
   ;; of regexps.
-  `((,package-name . 4)
+  `((,package-name . 8)
+
+    ;; For packages with a language prefix (namespaces), also compare the
+    ;; unprefixed name, so searching for “ggplot2” yields
+    ;; r-ggplot2 as first result instead of other, higher-ranked packages,
+    ;; which contain “ggplot2” in their description alot.
+    (,(lambda (package)
+        (let ((namespaces (list "cl-"
+                                "ecl-"
+                                "emacs-"
+                                "ghc-"
+                                "go-"
+                                "guile-"
+                                "java-"
+                                "julia-"
+                                "node-"
+                                "ocaml-"
+                                "perl-"
+                                "python-"
+                                "r-"
+                                "ruby-"
+                                "rust-"
+                                "sbcl-"
+                                "texlive-"))
+              (name (package-name package)))
+          (fold (lambda (prefix accum)
+                  (if (string-prefix? prefix name)
+                      (cons (substring name (string-length prefix)) accum)
+                      accum))
+                '()
+                namespaces)))
+       . 4)
 
     ;; Match against uncommon outputs.
     (,(lambda (package)
-- 
2.35.1



[Message part 3 (message/rfc822, inline)]
From: Ludovic Courtès <ludo <at> gnu.org>
To: Lars-Dominik Braun <lars <at> 6xq.net>
Cc: 58136-done <at> debbugs.gnu.org, zimoun <zimon.toutoune <at> gmail.com>
Subject: Re: [PATCH] ui: Improve sort order when searching package names.
Date: Tue, 13 Dec 2022 14:28:58 +0100
[Message part 4 (text/plain, inline)]
Hi,

Lars-Dominik Braun <lars <at> 6xq.net> skribis:

> From e0092d786b29f4f1cdc35217212a86804f36cdb4 Mon Sep 17 00:00:00 2001
> From: Lars-Dominik Braun <lars <at> 6xq.net>
> Date: Fri, 9 Dec 2022 11:46:37 +0100
> Subject: [PATCH v2 1/2] packages: Add 'package-upstream-name*'.
>
> * guix/packages.scm (package-upstream-name*): New procedure.
> * tests/packages.scm ("package-upstream-name*"): New test.

[...]

> From 5e0e8c0145a728d0ed49116596f06cc15e1e865d Mon Sep 17 00:00:00 2001
> From: Lars-Dominik Braun <lars <at> 6xq.net>
> Date: Fri, 9 Dec 2022 12:01:31 +0100
> Subject: [PATCH v2 2/2] ui: Take package upstream name into account when
>  searching.
>
> * guix/ui.scm (%package-metrics): Add PACKAGE-UPSTREAM-NAME*.

Applied with the minor changes below, thank you!

Ludo’.

[Message part 5 (text/x-patch, inline)]
diff --git a/guix/packages.scm b/guix/packages.scm
index 5e8e3a4ff4..6e61e16aa4 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -718,11 +718,11 @@ (define (package-upstream-name* package)
     (or (assq-ref (package-properties package) 'upstream-name)
         (let loop ((prefixes namespaces))
           (match prefixes
-            ('() name)
+            (() name)
             ((prefix rest ...)
               (if (string-prefix? prefix name)
                 (substring name (string-length prefix))
-                (loop (cdr prefixes)))))))))
+                (loop rest))))))))
 
 (define (hidden-package p)
   "Return a \"hidden\" version of P--i.e., one that 'fold-packages' and thus,
[Message part 6 (text/plain, inline)]
and:

[Message part 7 (text/x-patch, inline)]
diff --git a/tests/ui.scm b/tests/ui.scm
index 6a25a204ca..438acae525 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, 2019, 2020 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2013-2017, 2019-2020, 2022 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2022 Taiju HIGASHI <higashi <at> taiju.info>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -294,6 +294,15 @@ (define guile-2.0.9
          (>0 (package-relevance libb2
                                 (map rx '("crypto" "library")))))))
 
+(test-assert "package-relevance and upstream name"
+  ;; https://issues.guix.gnu.org/58136
+  (let ((ggplot2  (specification->package "r-ggplot2"))
+        (ggstance (specification->package "r-ggstance"))
+        (rx       (make-regexp "ggplot2" regexp/icase)))
+    (> (package-relevance ggplot2 (list rx))
+       (package-relevance ggstance (list rx))
+       0)))
+
 (define (make-empty-file directory file)
   ;; Create FILE in DIRECTORY.
   (close-port (open-output-file (in-vicinity directory file))))

This bug report was last modified 2 years and 161 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.