Subject: Re: [bug#39258] [PATCH v3 3/3] guix: Use package metadata cache for package search.

From: Ludovic Courtès <[email-masked]>
Date: Fri, 24 Apr 2020 23:03:10 +0200

Hello,

Arun Isaac <[email-masked]> skribis:

> * guix/scripts/package.scm (process-query): Call search-packages and
> display-package-search-results instead of find-packages-by-description and
> display-search-results respectively.
> * guix/ui.scm (package-metadata->recutils): New function.
> (%package-metrics): Use package-metadata record field accessors.
> (package-relevance): Rename argument package to package-metadata.
> (display-package-search-results): New function.

[...]

> +(define* (package-metadata->recutils p port #:optional (width (%text-width))
> +                                     #:key
> +                                     (hyperlinks? (supports-hyperlinks? port))
> +                                     (extra-fields '()))
> +  "Write to PORT a `recutils' record of <package-metadata> object P, arranging
> +to fit within WIDTH columns.  EXTRA-FIELDS is a list of symbol/value pairs to
> +emit.  When HYPERLINKS? is true, emit hyperlink escape sequences when
> +appropriate."

I think we should avoid copy/paste of ‘package->recutils’.

How about factorizing by having a common procedure that takes the fields
as keyword arguments instead of taking a record?

>  (define %package-metrics
>    ;; Metrics used to compute the "relevance score" of a package against a set
>    ;; of regexps.
> -  `((,package-name . 4)
> +  `((,package-metadata-name . 4)

Here we would also need to arrange so that this can apply to both a
<package> and <package-metadata> (or whatever), perhaps by defining the
two sets of metrics at once, or defining the second one by mapping over
the first one.

Thanks,
Ludo’.