all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Chris Marusich <cmmarusich@gmail.com>
To: Tobias Geerinckx-Rice <me@tobias.gr>
Cc: 35588@debbugs.gnu.org
Subject: bug#35588: [PATCH] ui: Search matches additional package outputs.
Date: Mon, 06 May 2019 02:08:58 -0700	[thread overview]
Message-ID: <87bm0g6jbp.fsf@garuda.local.i-did-not-set--mail-host-address--so-tickle-me> (raw)
In-Reply-To: <20190505214153.32372-1-me@tobias.gr> (Tobias Geerinckx-Rice's message of "Sun, 5 May 2019 23:41:53 +0200")


[-- Attachment #1.1: Type: text/plain, Size: 1750 bytes --]

Hi Tobias!

Tobias Geerinckx-Rice <me@tobias.gr> writes:

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

Wow, thank you for the quick patch!  Indeed, it works as advertised.

That said, I see that your patch only omits the "out" output, and it
also changes the way the regular expression matching works for all
fields.  Previously, a regex like "foo$" would have matched against
"foo" at the end of a package's description string, but now it matches
"foo" right before any newline in the description.  In practice, it
seems we have many newlines in the descriptions, since people wrap the
lines in the source code with non-escaped newlines.  I doubt anyone is
relying on the use of $ or ^ to match at the start of end of the
description, so this probably isn't a big deal, but it made me wonder
how else we might be able to accomplish the same task without changing
the way the regexes already work.

I've attached a patch that attempts to do that.  Basically, this patch
is like yours in spirit, but it excludes a few more "common" outputs,
and it splits the outputs into a list, rather than separating them by
newlines in a single string.  The downside is that I had to update all
the other "metrics" procedures so they would always return a list.  I
kind of feel like returning the same type of object is an upside, not a
downside, but I guess the pattern of returning #f for special cases is
pretty common in Guile, so maybe my change isn't very idiomatic.

What do you think of this solution?  I think it's a little more drastic,
but it feels cleaner to me.  If I'm bike shedding, feel free to call me
out on that!  ;-)

-- 
Chris

[-- Attachment #1.2: 0001-ui-Make-package-outputs-searchable.patch --]
[-- Type: text/x-patch, Size: 6170 bytes --]

From 91d06d8950e700a8a3c3479c3613b579c53411c9 Mon Sep 17 00:00:00 2001
From: Chris Marusich <cmmarusich@gmail.com>
Date: Mon, 6 May 2019 01:51:30 -0700
Subject: [PATCH] ui: Make package outputs searchable.

* guix/ui.scm (relevance): Expect the "field" procedure to always return
a (possibly empty) list of strings, thereby eliminating the case in
which (before this commit) "field" might return #f.  Add up the score of
each string in the list, and use that as the overall score when folding
over the metrics.  Update docstring.
(%package-metrics): Return a list in every case.
* guix/scripts/system/search.scm (process-query)
<%service-type-metrics>: Return a list in every case.
* guix/scripts/package.scm (find-packages-by-description): Update
docstring.
---
 guix/scripts/package.scm       |  6 ++---
 guix/scripts/system/search.scm | 17 +++++++++++----
 guix/ui.scm                    | 40 ++++++++++++++++++++++++----------
 3 files changed, 44 insertions(+), 19 deletions(-)

diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index aa27984ea2..06e4cf5b9c 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -180,9 +180,9 @@ hooks\" run when building the profile."
 ;;;
 
 (define (find-packages-by-description regexps)
-  "Return two values: the list of packages whose name, synopsis, or
-description matches at least one of REGEXPS sorted by relevance, and the list
-of relevance scores."
+  "Return two values: the list of packages whose name, synopsis, description,
+or output matches at least one of REGEXPS sorted by relevance, and the list of
+relevance scores."
   (let ((matches (fold-packages (lambda (package result)
                                   (if (package-superseded package)
                                       result
diff --git a/guix/scripts/system/search.scm b/guix/scripts/system/search.scm
index 955cdd1e95..733fa22614 100644
--- a/guix/scripts/system/search.scm
+++ b/guix/scripts/system/search.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2017, 2018 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
+;;; Copyright © 2019 Chris Marusich <cmmarusich@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -128,14 +129,22 @@ columns."
 
 (define %service-type-metrics
   ;; Metrics used to estimate the relevance of a search result.
-  `((,service-type-name* . 3)
-    (,service-type-description-string . 2)
+  `((,(lambda (type)
+        (match (service-type-name* type)
+          (#f '())
+          (name (list name))))
+     . 3)
+    (,(lambda (type)
+        (match (service-type-description-string type)
+          (#f '())
+          (description (list description))))
+     . 2)
     (,(lambda (type)
         (match (and=> (service-type-location type) location-file)
           ((? string? file)
-           (basename file ".scm"))
+           (list (basename file ".scm")))
           (#f
-           "")))
+           '())))
      . 1)))
 
 (define (find-service-types regexps)
diff --git a/guix/ui.scm b/guix/ui.scm
index 92c845e944..9121e3daee 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -11,6 +11,7 @@
 ;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
 ;;; Copyright © 2018 Kyle Meyer <kyle@kyleam.com>
 ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
+;;; Copyright © 2019 Chris Marusich <cmmarusich@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1370,7 +1371,7 @@ WIDTH columns.  EXTRA-FIELDS is a list of symbol/value pairs to emit."
 (define (relevance obj regexps metrics)
   "Compute a \"relevance score\" for OBJ as a function of its number of
 matches of REGEXPS and accordingly to METRICS.  METRICS is list of
-field/weight pairs, where FIELD is a procedure that returns a string
+field/weight pairs, where FIELD is a procedure that returns a list of strings
 describing OBJ, and WEIGHT is a positive integer denoting the weight of this
 field in the final score.
 
@@ -1392,29 +1393,44 @@ score, the more relevant OBJ is to REGEXPS."
   (fold (lambda (metric relevance)
           (match metric
             ((field . weight)
-             (match (field obj)
-               (#f  relevance)
-               (str (+ relevance
-                       (* (score str) weight)))))))
+             (let ((strings (field obj)))
+               (+ relevance
+                  (* weight
+                     ;; Evaluates to 0 when strings is the empty list.
+                     (apply + (map score strings))))))))
         0
         metrics))
 
 (define %package-metrics
   ;; Metrics used to compute the "relevance score" of a package against a set
   ;; of regexps.
-  `((,package-name . 4)
-
+  `((,(lambda (package)
+        (list (package-name package)))
+     . 4)
+    ;; Match against uncommon outputs.
+    (,(lambda (package)
+        (filter (lambda (output)
+                  (not (member output
+                               ;; Some common outpus shared by many packages.
+                               '("out" "debug" "doc" "static"))))
+                (package-outputs package)))
+     . 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)
-        (and=> (package-synopsis package) P_)) . 3)
+        (match (and=> (package-synopsis package) P_)
+          (#f '())
+          (synopsis (list synopsis))))
+     . 3)
     (,(lambda (package)
-        (and=> (package-description package) P_)) . 2)
-
+        (match (and=> (package-description package) P_)
+          (#f '())
+          (description (list description))))
+     . 2)
     (,(lambda (type)
         (match (and=> (package-location type) location-file)
-          ((? string? file) (basename file ".scm"))
-          (#f "")))
+          ((? string? file) (list (basename file ".scm")))
+          (#f '())))
      . 1)))
 
 (define (package-relevance package regexps)
-- 
2.20.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2019-05-06  9:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-05 19:39 bug#35588: guix package --search does not search output names Chris Marusich
2019-05-05 21:41 ` bug#35588: [PATCH] ui: Search matches additional package outputs Tobias Geerinckx-Rice
2019-05-06  9:08   ` Chris Marusich [this message]
2019-05-06  9:32     ` Ludovic Courtès
2019-05-07  0:57       ` Chris Marusich
2019-05-07  8:25         ` Ludovic Courtès
2019-05-08  6:50           ` bug#35588: [PATCH] ui: Search matches additional package outputs., " Chris Marusich
2019-05-08 10:39             ` Ludovic Courtès
2019-05-09  7:22               ` Chris Marusich
2019-05-07 22:24         ` swedebugia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bm0g6jbp.fsf@garuda.local.i-did-not-set--mail-host-address--so-tickle-me \
    --to=cmmarusich@gmail.com \
    --cc=35588@debbugs.gnu.org \
    --cc=me@tobias.gr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.