all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Chris Marusich <cmmarusich@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>, swedebugia <swedebugia@riseup.net>
Cc: 35588@debbugs.gnu.org
Subject: bug#35588: [PATCH] ui: Search matches additional package outputs., bug#35588: [PATCH] ui: Search matches additional package outputs.
Date: Tue, 07 May 2019 23:50:29 -0700	[thread overview]
Message-ID: <878svhv3re.fsf@gmail.com> (raw)
In-Reply-To: <87mujy8yd8.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Tue, 07 May 2019 10:25:39 +0200, Wed, 8 May 2019 00:24:39 +0200")


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

Ludovic Courtès <ludo@gnu.org> writes:

>>               (match (field obj)
>>                 (#f  relevance)
>> -               (str (+ relevance
>> -                       (* (score str) weight)))))))
>> +               ((? string? str) (+ relevance
>> +                                   (* (score str) weight)))
>> +               ((? list? lst) (+ relevance
>> +                                 (* weight
>> +                                    (apply + (map score lst)))))))))
>
> Nitpick: it’s a bit subjective, but I think this clause might be
> slightly nicer like this:
>
>   ((lst ...)
>    (+ relevance (* weight (reduce + 0 (map score lst)))))

Works for me!  I've changed the match clause accordingly in the attached
patch.

swedebugia <swedebugia@riseup.net> writes:

> On 2019-05-07 02:57, Chris Marusich wrote:
>> +    ;; Match against uncommon outputs.
>> +    (,(lambda (package)
>> +        (filter (lambda (output)
>> +                  (not (member output
>> +                               ;; Some common outpus shared by many packages.
>> +                               '("out" "debug" "doc" "static"))))
>
> I suggest we add "gui" and "lib" to this list.

Actually, I was curious about this, so I checked how many outputs are
being used by all our packages today.  Here are the results:

--8<---------------cut here---------------start------------->8---
scheme@(guix-user)> ,use (gnu packages) (guix packages)
scheme@(guix-user)> (define (increment table key) (hash-set! table key (+ 1 (hash-ref table key 0))))
scheme@(guix-user)> (define (increment-outputs package table) (for-each (lambda (output) (increment table output)) (package-outputs package)) table)
scheme@(guix-user)> (define outputs-to-count (fold-packages increment-outputs (make-hash-table)))
scheme@(guix-user)> ,pp (sort (hash-map->list cons outputs-to-count) (lambda (a b) (< (cdr a) (cdr b))))
$1 = (("kernel-patch" . 1)
 ("pcf-8bit" . 1)
 ("python2" . 1)
 ("schema" . 1)
 ("octave" . 1)
 ("jp" . 1)
 ("db" . 1)
 ("gtk3" . 1)
 ("kr" . 1)
 ("subtree" . 1)
 ("pulseaudio" . 1)
 ("cn" . 1)
 ("ruby" . 1)
 ("fbgrab" . 1)
 ("credential-netrc" . 1)
 ("front-end" . 1)
 ("psf" . 1)
 ("tw" . 1)
 ("libedataserverui" . 1)
 ("gtk2" . 1)
 ("pcf" . 1)
 ("send-email" . 1)
 ("jack" . 1)
 ("python3" . 1)
 ("ndiff" . 1)
 ("installer" . 1)
 ("svn" . 1)
 ("image" . 1)
 ("tiles" . 2)
 ("fortran" . 3)
 ("include" . 3)
 ("utils" . 3)
 ("tests" . 3)
 ("python" . 4)
 ("tk" . 4)
 ("metis" . 4)
 ("gui" . 4)
 ("examples" . 5)
 ("jdk" . 6)
 ("bin" . 8)
 ("cargo" . 16)
 ("static" . 33)
 ("lib" . 38)
 ("debug" . 87)
 ("doc" . 134)
 ("out" . 9811))
scheme@(guix-user)> 
--8<---------------cut here---------------end--------------->8---

In light of that, I've chosen to exclude all of the following outputs:

  '("out" "doc" "debug" "lib" "static" "bin" "examples" "gui" "tests"
    "utils" "include")

I've also added a test to verify that package outputs are included in
search results.

What do you all think of this latest version?

-- 
Chris

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

From dedea618bdd0d557e3e1183c403ff4e11d1757f8 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): Allow the "field" procedure of a metric to
return a list, and handle that case appropriately.  Update docstring.
(%package-metrics): Add a metric for package outputs.
* guix/scripts/package.scm (find-packages-by-description): Update
docstring.
* tests/guix-package.sh: Add a test case to verify that package outputs are
included in search results.

Co-authored-by: Tobias Geerinckx-Rice <me@tobias.gr>
---
 guix/scripts/package.scm |  6 +++---
 guix/ui.scm              | 25 ++++++++++++++++++++-----
 tests/guix-package.sh    | 25 +++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 8 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/ui.scm b/guix/ui.scm
index 92c845e944..8f95c00361 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -11,6 +11,8 @@
 ;;; 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>
+;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1370,9 +1372,9 @@ 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
-describing OBJ, and WEIGHT is a positive integer denoting the weight of this
-field in the final score.
+field/weight pairs, where FIELD is a procedure that returns a string or list
+of strings describing OBJ, and WEIGHT is a positive integer denoting the
+weight of this field in the final score.
 
 A score of zero means that OBJ does not match any of REGEXPS.  The higher the
 score, the more relevant OBJ is to REGEXPS."
@@ -1394,8 +1396,10 @@ score, the more relevant OBJ is to REGEXPS."
             ((field . weight)
              (match (field obj)
                (#f  relevance)
-               (str (+ relevance
-                       (* (score str) weight)))))))
+               ((? string? str)
+                (+ relevance (* (score str) weight)))
+               ((lst ...)
+                (+ relevance (* weight (apply + (map score lst)))))))))
         0
         metrics))
 
@@ -1404,6 +1408,17 @@ score, the more relevant OBJ is to REGEXPS."
   ;; of regexps.
   `((,package-name . 4)
 
+    ;; Match against uncommon outputs.
+    (,(lambda (package)
+        (filter (lambda (output)
+                  (not (member output
+                               ;; Some common outpus shared by many packages.
+                               '("out" "doc" "debug" "lib" "static" "bin"
+                                 "examples" "gui" "tests" "utils"
+                                 "include"))))
+                (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)
diff --git a/tests/guix-package.sh b/tests/guix-package.sh
index 0d60481895..262d29bd59 100644
--- a/tests/guix-package.sh
+++ b/tests/guix-package.sh
@@ -398,3 +398,28 @@ else
     grep "manifest.scm:[1-3]:.*wonderful-package.*: unbound variable" \
 	 "$module_dir/stderr"
 fi
+
+# Verify that package outputs are included in search results.
+rm -rf "$module_dir"
+mkdir "$module_dir"
+cat > "$module_dir/foo.scm"<<EOF
+(define-module (foo)
+  #:use-module (guix packages)
+  #:use-module (guix build-system trivial))
+
+(define-public dummy-package
+  (package
+    (name "dummy-package")
+    (version "dummy-version")
+    (outputs '("out" "dummy-output"))
+    (source #f)
+    ;; Without a real build system, the "guix pacakge -s" command will fail.
+    (build-system trivial-build-system)
+    (synopsis "dummy-synopsis")
+    (description "dummy-description")
+    (home-page "https://dummy-home-page")
+    (license #f)))
+EOF
+guix package -L "$module_dir" -s dummy-output > /tmp/out
+test "`guix package -L "$module_dir" -s dummy-output | grep ^name:`" = "name: dummy-package"
+rm -rf "$module_dir"
-- 
2.20.1


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

  reply	other threads:[~2019-05-08  6:51 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
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           ` Chris Marusich [this message]
2019-05-08 10:39             ` bug#35588: [PATCH] ui: Search matches additional package outputs., " 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=878svhv3re.fsf@gmail.com \
    --to=cmmarusich@gmail.com \
    --cc=35588@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    --cc=swedebugia@riseup.net \
    /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.