From 91d06d8950e700a8a3c3479c3613b579c53411c9 Mon Sep 17 00:00:00 2001
* 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
guix/scripts/package.scm | 6 ++---
guix/scripts/system/search.scm | 17 +++++++++++----
guix/ui.scm | 40 ++++++++++++++++++++++++----------
3 files changed, 44 insertions(+), 19 deletions(-)
Toggle diff (135 lines)
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
+ "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
(let ((matches (fold-packages (lambda (package result)
(if (package-superseded package)
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
;;; 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)
+ (match (service-type-name* type)
+ (match (service-type-description-string type)
+ (description (list description))))
(match (and=> (service-type-location type) location-file)
- (basename file ".scm"))
+ (list (basename file ".scm")))
(define (find-service-types regexps)
diff --git a/guix/ui.scm b/guix/ui.scm
index 92c845e944..9121e3daee 100644
;;; 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)
- (* (score str) weight)))))))
+ (let ((strings (field obj)))
+ ;; Evaluates to 0 when strings is the empty list.
+ (apply + (map score strings))))))))
;; Metrics used to compute the "relevance score" of a package against a set
+ (list (package-name package)))
+ ;; Match against uncommon outputs.
+ (filter (lambda (output)
+ ;; Some common outpus shared by many packages.
+ '("out" "debug" "doc" "static"))))
+ (package-outputs package)))
;; Match regexps on the raw Texinfo since formatting it is quite expensive
;; and doesn't have much of an effect on search results.
- (and=> (package-synopsis package) P_)) . 3)
+ (match (and=> (package-synopsis package) P_)
+ (synopsis (list synopsis))))
- (and=> (package-description package) P_)) . 2)
+ (match (and=> (package-description package) P_)
+ (description (list description))))
(match (and=> (package-location type) location-file)
- ((? string? file) (basename file ".scm"))
+ ((? string? file) (list (basename file ".scm")))
(define (package-relevance package regexps)