Subject: [PATCH] ui: Search matches additional package outputs.

From: Tobias Geerinckx-Rice <[email-masked]>
Date: Sun, 5 May 2019 23:41:53 +0200

* guix/ui.scm (%package-metrics): Add a PACKAGE-OUTPUTS metric with a
relevance of 1.
* guix/scripts/package.scm (process-query)<search>: Add the
REGEXP/NEWLINE flag.
---

mikadoZero, Guix,

Here's a patch to match package outputs (except ‘out’, since it can't affect the relative score) in ‘guix search’.

Before:

  ~ λ guix search ernel-patch
  # nothing

After:

  ~ λ guix search ernel-patch
  name: wireguard
  version: 0.0.20190406
  outputs: out kernel-patch
  …

  ~ λ guix search ^ernel-patch
  # nothing

While the new REGEXP/NEWLINE flag affects how all fields are matched, I don't think it actually changes anything in practice without the second hunk.

If there's a possibility that it might, I'd split this into two commits.

Kind regards,

T G-R

 guix/scripts/package.scm | 3 ++-
 guix/ui.scm              | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index aa27984ea2..a31e78484e 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -751,7 +751,8 @@ processed, #f otherwise."
                                       (('query 'search rx) rx)
                                       (_                   #f))
                                     opts))
-              (regexps  (map (cut make-regexp* <> regexp/icase) patterns)))
+              (regexps  (map (cut make-regexp* <> regexp/icase regexp/newline)
+                             patterns)))
          (leave-on-EPIPE
           (let-values (((packages scores)
                         (find-packages-by-description regexps)))
diff --git a/guix/ui.scm b/guix/ui.scm
index 92c845e944..f2466b605b 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -1404,6 +1404,12 @@ score, the more relevant OBJ is to REGEXPS."
   ;; of regexps.
   `((,package-name . 4)
 
+    ;; Separate package outputs by newlines to match regexps like "^tools$".
+    ;; Hard-codedly ignore ‘out’ since it presumably exists for every package.
+    (,(lambda (package)
+        (string-join (delete "out" (package-outputs package))
+                     "\n")) . 1)
+
     ;; Match regexps on the raw Texinfo since formatting it is quite expensive
     ;; and doesn't have much of an effect on search results.
     (,(lambda (package)
-- 
2.21.0