[PATCH] ui: Improve sort order when searching package names.

  • Done
  • quality assurance status badge
Details
6 participants
  • Lars-Dominik Braun
  • Lars-Dominik Braun
  • Ludovic Courtès
  • Christopher Baines
  • Maxime Devos
  • zimoun
Owner
unassigned
Submitted by
Lars-Dominik Braun
Severity
normal

Debbugs page

L
L
Lars-Dominik Braun wrote on 28 Sep 2022 02:27
(address . guix-patches@gnu.org)
YzQTieJZSCJGTGY2@noor.fritz.box
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(-)

Toggle diff (46 lines)
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
Z
Z
zimoun wrote on 28 Sep 2022 07:26
(address . ludo@gnu.org)
86wn9na82p.fsf@gmail.com
Hi Lars,

On Wed, 28 Sep 2022 at 11:27, Lars-Dominik Braun <lars@6xq.net> wrote:

Toggle quote (5 lines)
> 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?


Toggle snippet (28 lines)
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)


Cheers,
simon
M
M
Maxime Devos wrote on 28 Sep 2022 13:23
(address . ludo@gnu.org)
47edd297-92ec-d8a1-5999-813f4b9644db@telenet.be
Toggle quote (1 lines)
> + ;; For packages with a language prefix (namespaces), also compare the
You missed "minetest-"
On 28-09-2022 16:26, zimoun wrote:
Toggle quote (3 lines)
> 3. use upstream-name if provided
>
> WDYT?
For the Minetest mods (which have upstream-names like "Jeija/mesecons"),
I don't think think the upstream-name is useful as-is
Greetings,
Maxime.
Attachment: OpenPGP_signature
M
Z
Z
zimoun wrote on 28 Sep 2022 14:40
(address . ludo@gnu.org)
87v8p7b2kt.fsf@gmail.com
Hi,

On mer., 28 sept. 2022 at 22:23, Maxime Devos <maximedevos@telenet.be> wrote:

Toggle quote (6 lines)
> On 28-09-2022 16:26, zimoun wrote:
>> 3. use upstream-name if provided
>
> For the Minetest mods (which have upstream-names like "Jeija/mesecons"),
> I don't think think the upstream-name is useful as-is

Using the change I am proposing, just knowing ’jeija’ returns a match:

Toggle snippet (21 lines)
$ ./pre-inst-env guix search jeija
name: minetest-mesecons
version: 1.2.1-63.27c3c51
outputs:
+ out: everything else
systems: x86_64-linux
dependencies:
location: gnu/packages/minetest.scm:367:4
homepage: https://mesecons.net
license: LGPL 3, CC-BY-SA 3.0
synopsis: Digital circuitry for Minetest, including wires, buttons and lights
description: Mesecons is a mod for Minetest implementing various items
+ related to digital circuitry, such as wires, buttons, lights and programmable
+ controllers. Among other things, there are also pistons, solar panels,
+ pressure plates and note blocks.
+
+ Mesecons has a similar goal to Redstone in Minecraft, but works in its own
+ way, with different rules and mechanics.
relevance: 4

which is better than nothing.

Well, upstream-name is not so much useful as-is but it can help for some
cases.


Cheers,
simon
M
M
Maxime Devos wrote on 28 Sep 2022 14:43
(address . ludo@gnu.org)
4dc4d1e1-9775-5c29-877f-91022b794348@telenet.be
On 28-09-2022 23:40, zimoun wrote:
Toggle quote (5 lines)
> Using the change I am proposing, just knowing ’jeija’ returns a match:
>
> --8<---------------cut here---------------start------------->8---
> $ ./pre-inst-env guix search jeija
> name: minetest-mesecons
> [...]
Right, didn't think of that.
Greetings,
Maxime.
Attachment: OpenPGP_signature
L
L
Ludovic Courtès wrote on 1 Oct 2022 14:42
(name . zimoun)(address . zimon.toutoune@gmail.com)
87v8p3b4pt.fsf@gnu.org
Hi,

zimoun <zimon.toutoune@gmail.com> skribis:

Toggle quote (12 lines)
> 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

Maybe something like:

(define %package-metrics
`((,package-name . 4)
(,package-upstream-name* . 4) ;or a lower weight, dunno
…))

where:

(define (package-upstream-name* package)
(or (assoc-ref (package-properties package) 'upstream-name)
(package-name-sans-namespace package))) ;strip "r-", "emacs-", etc.

WDYT?

(Perhaps ‘package-upstream-name’ could be taught about these implicit
name conversions done for R, Python, Emacs, etc.?)

Ludo’.
Z
Z
zimoun wrote on 2 Oct 2022 01:26
(name . Ludovic Courtès)(address . ludo@gnu.org)
868rly3a31.fsf@gmail.com
Hi,

On Sat, 01 Oct 2022 at 23:42, Ludovic Courtès <ludo@gnu.org> wrote:

Toggle quote (4 lines)
> (define (package-upstream-name* package)
> (or (assoc-ref (package-properties package) 'upstream-name)
> (package-name-sans-namespace package))) ;strip "r-", "emacs-", etc.

I think it is better to rely on ’package-upstream-name’ and hides the
plumbing. It helps when something needs to be “refactored“, IMHO.


Toggle quote (3 lines)
> (Perhaps ‘package-upstream-name’ could be taught about these implicit
> name conversions done for R, Python, Emacs, etc.?)

Maybe, but it requires to scrutinize importer per importer since
upstream name is mainly used by these, IIUC.


Cheers,
simon
L
L
Lars-Dominik Braun wrote on 12 Oct 2022 04:24
(name . zimoun)(address . zimon.toutoune@gmail.com)
Y0aj2GRdkZG6cFhs@zpidnb93
Hi simon,

Toggle quote (4 lines)
> 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. :-)
I agree that using the upstream-name would be a good idea.

Toggle quote (6 lines)
> 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
The issue here is we don’t know what the user is searching for. If we
add more weight to the package name then usually libraries (rust-csv,
ghc-csv, …) win. Imo a search for “csv” should return tools to
manipulate CSV files like csvkit, csvdiff, xlsx2csv, … Just like
“json” should yield tools like jq, json.sh and possibly others which
I cannot find right now. But maybe I’m searching for a C library that
parses CSV instead. And then what…?

As for ggplot2, the particular issue seems to be that scores are added
for each match and the description for some of our packages contains
“ggplot2” alot. So I tried using MAX instead of +, which works,
but results in little variation of scores and thus weird sort order
(descending by name). It does not feel like an improvement either.

Cheers,
Lars

--
Lars-Dominik Braun
Wissenschaftlicher Mitarbeiter/Research Associate

www.leibniz-psychology.org
ZPID - Leibniz-Institut für Psychologie /
ZPID - Leibniz Institute for Psychology
Universitätsring 15
D-54296 Trier - Germany
Tel.: +49–651–201-4964
Toggle diff (107 lines)
diff --git a/guix/packages.scm b/guix/packages.scm
index 94e464cd01..9934501cdb 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -86,6 +86,7 @@ (define-module (guix packages)
this-package
package-name
package-upstream-name
+ package-upstream-name*
package-version
package-full-name
package-source
@@ -657,6 +658,38 @@ (define (package-upstream-name package)
(or (assq-ref (package-properties package) 'upstream-name)
(package-name package)))
+(define (package-upstream-name* package)
+ "Return the upstream name of PACKAGE, which could be different from the name
+it has in Guix."
+ (let ((namespaces (list "cl-"
+ "ecl-"
+ "emacs-"
+ "ghc-"
+ "go-"
+ "guile-"
+ "java-"
+ "julia-"
+ "lua-"
+ "minetest-"
+ "node-"
+ "ocaml-"
+ "perl-"
+ "python-"
+ "r-"
+ "ruby-"
+ "rust-"
+ "sbcl-"
+ "texlive-"))
+ (name (package-name package)))
+ (or (assq-ref (package-properties package) 'upstream-name)
+ (let loop ((prefixes namespaces))
+ (match prefixes
+ ('() name)
+ ((prefix rest ...)
+ (if (string-prefix? prefix name)
+ (substring name (string-length prefix))
+ (loop (cdr prefixes)))))))))
+
(define (hidden-package p)
"Return a \"hidden\" version of P--i.e., one that 'fold-packages' and thus,
user interfaces, ignores."
diff --git a/guix/ui.scm b/guix/ui.scm
index dad2b853ac..da16a50f9f 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -1623,10 +1623,23 @@ (define (relevance obj regexps metrics)
(define (score regexp str)
(fold-matches regexp str 0
(lambda (m score)
- (+ score
- (if (string=? (match:substring m) str)
- 5 ;exact match
- 1)))))
+ (let* ((start (- (match:start m) 1))
+ (end (match:end m))
+ (left (if (>= start 0) (string-ref str start) #f))
+ (right (if (< end (string-length str)) (string-ref str end) #f))
+ (delimiter-classes '(Cc Cf Pd Pe Pf Pi Po Ps Sk Zs Zl Zp))
+ (delim-left (or (member (and=> left char-general-category) delimiter-classes) (eq? left #f)))
+ (delim-right (or (member (and=> right char-general-category) delimiter-classes) (eq? right #f))))
+ (max score
+ (cond
+ ;; regexp is a full match for str.
+ ((and (eq? left #f) (eq? right #f)) 4)
+ ;; regexp matches a single word in str.
+ ((and delim-left delim-right) 3)
+ ;; regexp matches the beginning or end of a word in str.
+ ((or delim-left delim-right) 2)
+ ;; Everything else.
+ (#t 1)))))))
(define (regexp->score regexp)
(let ((score-regexp (lambda (str) (score regexp str))))
@@ -1635,10 +1648,11 @@ (define (regexp->score regexp)
((field . weight)
(match (field obj)
(#f relevance)
+ ('() relevance)
((? string? str)
- (+ relevance (* (score-regexp str) weight)))
+ (max relevance (* (score-regexp str) weight)))
((lst ...)
- (+ relevance (* weight (apply + (map score-regexp lst)))))))))
+ (max relevance (* weight (apply max (map score-regexp lst)))))))))
0 metrics)))
(let loop ((regexps regexps)
@@ -1655,7 +1669,8 @@ (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 . 5)
+ (,package-upstream-name* . 1)
;; Match against uncommon outputs.
(,(lambda (package)
-----BEGIN PGP SIGNATURE-----

iQGzBAABCAAdFiEEyk+M9DfXR4/aBV/UQhN3ARo3hEYFAmNGo8wACgkQQhN3ARo3
hEba5gv+ILcz/1yKN1+6IUZ4SaSfwURreKttay/0O7uTVddFMAfOmkryx4SOfLoN
0fpmhpJ93nF7TYkaUBelvTSOmrb0bZa63OgxfOxLc4DoDRjAY+F7bY2Oa9HvRM1r
dCuHh/Fob7JvVFy9Z8jA5iqmnICrUcNgJnh1TI8xNybY+g+1nvLhyKwWH5+ZjtDt
J9r60nDeisxk8Dkoub3mxJbILBymjscviPWRoA0iwY0//KZv3JIRl4ICufqGMil0
S2TkL5vpzVYtCLfhyvv33rKNkXjj5bHGy6Cy94psVkVo3v0wIf5JS5mJGpYv3wEP
wTp74j7dd1wnZgwhjlK3hUXBnm/vwBPOJxTYdH0VGUjxmqFcGJ7Hm6tYWv++3Zbz
x5BK6l3dgXCNgcNf5yUShRncpVLHyeOnjQ/Lv6i64pKaPxRpVkCXO66uyTpc+lgq
WDLbjmKjq8nTiokwfRtFMNspwjquhlju4C5NXsM21WQJ916TOotSRmVlONKQvdh4
whHkNPMm
=Ji6J
-----END PGP SIGNATURE-----


L
L
Ludovic Courtès wrote on 17 Oct 2022 00:46
Re: bug#58136: [PATCH] ui: Improve sort order when searching package names.
(name . Lars-Dominik Braun)(address . ldb@leibniz-psychology.org)
8735bmj3jf.fsf_-_@gnu.org
Hi!

Lars-Dominik Braun <ldb@leibniz-psychology.org> skribis:

Toggle quote (20 lines)
> diff --git a/guix/packages.scm b/guix/packages.scm
> index 94e464cd01..9934501cdb 100644
> --- a/guix/packages.scm
> +++ b/guix/packages.scm
> @@ -86,6 +86,7 @@ (define-module (guix packages)
> this-package
> package-name
> package-upstream-name
> + package-upstream-name*
> package-version
> package-full-name
> package-source
> @@ -657,6 +658,38 @@ (define (package-upstream-name package)
> (or (assq-ref (package-properties package) 'upstream-name)
> (package-name package)))
>
> +(define (package-upstream-name* package)
> + "Return the upstream name of PACKAGE, which could be different from the name
> +it has in Guix."

s/which could.*Guix/accounting for commonly-used package name prefixes
in addition to the @code{upstream-name} property/

Preferably make this addition in a separate commit.

Toggle quote (27 lines)
> +++ b/guix/ui.scm
> @@ -1623,10 +1623,23 @@ (define (relevance obj regexps metrics)
> (define (score regexp str)
> (fold-matches regexp str 0
> (lambda (m score)
> - (+ score
> - (if (string=? (match:substring m) str)
> - 5 ;exact match
> - 1)))))
> + (let* ((start (- (match:start m) 1))
> + (end (match:end m))
> + (left (if (>= start 0) (string-ref str start) #f))
> + (right (if (< end (string-length str)) (string-ref str end) #f))
> + (delimiter-classes '(Cc Cf Pd Pe Pf Pi Po Ps Sk Zs Zl Zp))
> + (delim-left (or (member (and=> left char-general-category) delimiter-classes) (eq? left #f)))
> + (delim-right (or (member (and=> right char-general-category) delimiter-classes) (eq? right #f))))
> + (max score
> + (cond
> + ;; regexp is a full match for str.
> + ((and (eq? left #f) (eq? right #f)) 4)
> + ;; regexp matches a single word in str.
> + ((and delim-left delim-right) 3)
> + ;; regexp matches the beginning or end of a word in str.
> + ((or delim-left delim-right) 2)
> + ;; Everything else.
> + (#t 1)))))))

The intent is to have all regexps behave as if the user passed \<STR\>,
is that right? Would be nice to have a comment clarifying that above
and perhaps making it a separate change?

Stylistic notes:

(if cond consequent #f) => (and cond consequent)
(eq? x #f) => (not x)
(cond … (#t x)) => (cond … (else x))

Toggle quote (12 lines)
> @@ -1635,10 +1648,11 @@ (define (regexp->score regexp)
> ((field . weight)
> (match (field obj)
> (#f relevance)
> + ('() relevance)
> ((? string? str)
> - (+ relevance (* (score-regexp str) weight)))
> + (max relevance (* (score-regexp str) weight)))
> ((lst ...)
> - (+ relevance (* weight (apply + (map score-regexp lst)))))))))
> + (max relevance (* weight (apply max (map score-regexp lst)))))))))

Intuitively I would expect scores to add up, otherwise we’re kinda
losing information; so I would not make this change. WDYT?

There’s a test for ‘package-relevance’ in tests/ui.scm. Please make
sure it still passes and ideally add relevant tests such as the CSV
example you gave.

Thanks!

Ludo’.
Z
Z
zimoun wrote on 17 Oct 2022 01:19
Re: [bug#58136] [PATCH] ui: Improve sort order when searching package names.
(address . 58136@debbugs.gnu.org)
877d0yoo9n.fsf@gmail.com
Hi Lars, Ludo,

In short, I miss why the initial patch with a minor tweak is not enough
for covering the corner cases. :-)


On lun., 17 oct. 2022 at 09:46, Ludovic Courtès <ludo@gnu.org> wrote:
Toggle quote (31 lines)
>> +++ b/guix/ui.scm
>> @@ -1623,10 +1623,23 @@ (define (relevance obj regexps metrics)
>> (define (score regexp str)
>> (fold-matches regexp str 0
>> (lambda (m score)
>> - (+ score
>> - (if (string=? (match:substring m) str)
>> - 5 ;exact match
>> - 1)))))
>> + (let* ((start (- (match:start m) 1))
>> + (end (match:end m))
>> + (left (if (>= start 0) (string-ref str start) #f))
>> + (right (if (< end (string-length str)) (string-ref str end) #f))
>> + (delimiter-classes '(Cc Cf Pd Pe Pf Pi Po Ps Sk Zs Zl Zp))
>> + (delim-left (or (member (and=> left char-general-category) delimiter-classes) (eq? left #f)))
>> + (delim-right (or (member (and=> right char-general-category) delimiter-classes) (eq? right #f))))
>> + (max score
>> + (cond
>> + ;; regexp is a full match for str.
>> + ((and (eq? left #f) (eq? right #f)) 4)
>> + ;; regexp matches a single word in str.
>> + ((and delim-left delim-right) 3)
>> + ;; regexp matches the beginning or end of a word in str.
>> + ((or delim-left delim-right) 2)
>> + ;; Everything else.
>> + (#t 1)))))))
>
> The intent is to have all regexps behave as if the user passed \<STR\>,
> is that right? Would be nice to have a comment clarifying that above
> and perhaps making it a separate change?

All this appears to me overcomplicated. Personally, I have to read it
many times to get the logic; while the initial patch was much clearer,
IMHO.

Other said, I am not convinced the complexity is worth the corner case.


The initial patch with the minor tweak I am proposing (maybe using
package-upstream-name*) appears to me enough for covering the corner
cases initially reported (as ggplot2).


Toggle quote (15 lines)
>> @@ -1635,10 +1648,11 @@ (define (regexp->score regexp)
>> ((field . weight)
>> (match (field obj)
>> (#f relevance)
>> + ('() relevance)
>> ((? string? str)
>> - (+ relevance (* (score-regexp str) weight)))
>> + (max relevance (* (score-regexp str) weight)))
>> ((lst ...)
>> - (+ relevance (* weight (apply + (map score-regexp lst)))))))))
>> + (max relevance (* weight (apply max (map score-regexp lst)))))))))
>
> Intuitively I would expect scores to add up, otherwise we’re kinda
> losing information; so I would not make this change. WDYT?

I agree with Ludo that ’max’ is counterintuitive.


Well, could we list some examples (keyword and expectation)? Because
the initial patch with a minor tweak LGTM and covers ggplot2, csv, and
some others.


Cheers,
simon
C
C
Christopher Baines wrote on 3 Nov 2022 08:45
tag 58136 moreinfo
(address . control@debbugs.gnu.org)
87mt98xcs1.fsf@cbaines.net
tags 58136 + moreinfo
quit
L
L
Lars-Dominik Braun wrote on 9 Dec 2022 03:49
Re: [PATCH] ui: Improve sort order when searching package names.
(address . 58136@debbugs.gnu.org)
Y5MgzLjZGb49LVa4@noor.fritz.box
Hi,

attached is version 2 of my initial patch, which simply moves prefix
detection into PACKAGE-UPSTREAM-NAME* (as suggested by Ludo) and reduces
the score to 2 (as suggested by Simon). It’s therefore quite tailored
to the “ggplot2 problem”, but does the job.

Thanks,
Lars
From e0092d786b29f4f1cdc35217212a86804f36cdb4 Mon Sep 17 00:00:00 2001
From: Lars-Dominik Braun <lars@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.
---
guix/packages.scm | 33 +++++++++++++++++++++++++++++++++
tests/packages.scm | 4 ++++
2 files changed, 37 insertions(+)

Toggle diff (68 lines)
diff --git a/guix/packages.scm b/guix/packages.scm
index 8f119d9fa7..5e8e3a4ff4 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -89,6 +89,7 @@ (define-module (guix packages)
this-package
package-name
package-upstream-name
+ package-upstream-name*
package-version
package-full-name
package-source
@@ -691,6 +692,38 @@ (define (package-upstream-name package)
(or (assq-ref (package-properties package) 'upstream-name)
(package-name package)))
+(define (package-upstream-name* package)
+ "Return the upstream name of PACKAGE, accounting for commonly-used
+package name prefixes in addition to the @code{upstream-name} property."
+ (let ((namespaces (list "cl-"
+ "ecl-"
+ "emacs-"
+ "ghc-"
+ "go-"
+ "guile-"
+ "java-"
+ "julia-"
+ "lua-"
+ "minetest-"
+ "node-"
+ "ocaml-"
+ "perl-"
+ "python-"
+ "r-"
+ "ruby-"
+ "rust-"
+ "sbcl-"
+ "texlive-"))
+ (name (package-name package)))
+ (or (assq-ref (package-properties package) 'upstream-name)
+ (let loop ((prefixes namespaces))
+ (match prefixes
+ ('() name)
+ ((prefix rest ...)
+ (if (string-prefix? prefix name)
+ (substring name (string-length prefix))
+ (loop (cdr prefixes)))))))))
+
(define (hidden-package p)
"Return a \"hidden\" version of P--i.e., one that 'fold-packages' and thus,
user interfaces, ignores."
diff --git a/tests/packages.scm b/tests/packages.scm
index a5819d8de3..f58c47817b 100644
--- a/tests/packages.scm
+++ b/tests/packages.scm
@@ -626,6 +626,10 @@ (define read-at
(build-derivations %store (list drv))
(call-with-input-file output get-string-all)))
+(test-equal "package-upstream-name*"
+ (package-upstream-name* (specification->package "guile-gcrypt"))
+ "gcrypt")
+
;;;
;;; Source derivation with snippets.
--
2.37.4
From 5e0e8c0145a728d0ed49116596f06cc15e1e865d Mon Sep 17 00:00:00 2001
From: Lars-Dominik Braun <lars@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*.
---
guix/ui.scm | 1 +
1 file changed, 1 insertion(+)

Toggle diff (14 lines)
diff --git a/guix/ui.scm b/guix/ui.scm
index 45eccb7335..3bca3b1e40 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -1668,6 +1668,7 @@ (define %package-metrics
;; Metrics used to compute the "relevance score" of a package against a set
;; of regexps.
`((,package-name . 4)
+ (,package-upstream-name* . 2)
;; Match against uncommon outputs.
(,(lambda (package)
--
2.37.4
L
L
Ludovic Courtès wrote on 13 Dec 2022 05:28
(name . Lars-Dominik Braun)(address . lars@6xq.net)
87fsdjwhyd.fsf@gnu.org
Hi,

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

Toggle quote (8 lines)
> From e0092d786b29f4f1cdc35217212a86804f36cdb4 Mon Sep 17 00:00:00 2001
> From: Lars-Dominik Braun <lars@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.

[...]

Toggle quote (8 lines)
> From 5e0e8c0145a728d0ed49116596f06cc15e1e865d Mon Sep 17 00:00:00 2001
> From: Lars-Dominik Braun <lars@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’.
Toggle diff (18 lines)
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,
and:
Toggle diff (27 lines)
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@gnu.org>
+;;; Copyright © 2013-2017, 2019-2020, 2022 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2022 Taiju HIGASHI <higashi@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))))
Closed
L
L
Lars-Dominik Braun wrote on 13 Dec 2022 06:53
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 58136@debbugs.gnu.org)
Y5iR9ey3ReyExwot@noor.fritz.box
Hi Ludo,

Toggle quote (1 lines)
> Applied with the minor changes below, thank you!
thank you!

Toggle quote (8 lines)
> +(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)))
I was hesitant to add a system test, which depends on real package
descriptions (not synthetic ones), because at some point it *will* break.

Cheers,
Lars
L
L
Ludovic Courtès wrote on 13 Dec 2022 08:40
(name . Lars-Dominik Braun)(address . lars@6xq.net)(address . 58136@debbugs.gnu.org)
87wn6vuuij.fsf@gnu.org
Hi,

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

Toggle quote (14 lines)
>> Applied with the minor changes below, thank you!
> thank you!
>
>> +(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)))
> I was hesitant to add a system test, which depends on real package
> descriptions (not synthetic ones), because at some point it *will* break.

Yes, that’s a tradeoff. For now, I would think the test is a plus as it
will allow us to see if future tweaks break this use case but yeah, on
the day it breaks, we’ll have to rewrite it or to drop it.

Ludo’.
?
Your comment

This issue is archived.

To comment on this conversation send an email to 58136@patchwise.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 58136
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch