Subject: Re: [bug#58136] [PATCH] ui: Improve sort order when searching package names.

From: zimoun <[email-masked]>
Date: Wed, 28 Sep 2022 16:26:38 +0200

Hi Lars,

On Wed, 28 Sep 2022 at 11:27, Lars-Dominik Braun <[email-masked]> wrote:

> 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.

In addition to your proposal which LGTM, maybe we could also use the
’upstream-name’ properties.  Most of the time, the Guix name matches the
upstream name, but sometimes not.  Although, it would not fix the issue
for ggplot2 since there is no upstream-name for this package. :-)

Well, I propose something like see below (based on your patch):

 1. keep the weight as 4
 2. set the “namespace” weight to 1 (or 2 if you prefer)

    Otherwise, for example, generic name as CSV could artificially bump
    the relevance and hide relevant packages.  For instance, compare

       guix search csv

 3. use upstream-name if provided

WDYT?

--8<---------------cut here---------------start------------->8---
diff --git a/guix/ui.scm b/guix/ui.scm
index 55b596ed35..14f296a546 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -1655,7 +1655,7 @@ (define (regexp->score regexp)
 (define %package-metrics
   ;; Metrics used to compute the "relevance score" of a package against a set
   ;; of regexps.
-  `((,package-name . 8)
+  `((,package-name . 4)
 
     ;; For packages with a language prefix (namespaces), also compare the
     ;; unprefixed name, so searching for “ggplot2” yields
@@ -1684,9 +1684,9 @@ (define %package-metrics
                   (if (string-prefix? prefix name)
                       (cons (substring name (string-length prefix)) accum)
                       accum))
-                '()
+                (list (package-upstream-name package))
                 namespaces)))
-       . 4)
+     . 1)
 
     ;; Match against uncommon outputs.
     (,(lambda (package)
--8<---------------cut here---------------end--------------->8---

Cheers,
simon