From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chris Marusich Subject: bug#35588: [PATCH] ui: Search matches additional package outputs. Date: Mon, 06 May 2019 02:08:58 -0700 Message-ID: <87bm0g6jbp.fsf@garuda.local.i-did-not-set--mail-host-address--so-tickle-me> References: <87r29czo6e.fsf@gmail.com> <20190505214153.32372-1-me@tobias.gr> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([209.51.188.92]:33712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNZdQ-0001CI-5o for bug-guix@gnu.org; Mon, 06 May 2019 05:10:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNZdK-0000wU-Tu for bug-guix@gnu.org; Mon, 06 May 2019 05:10:08 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:42159) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNZdK-0000wN-Oa for bug-guix@gnu.org; Mon, 06 May 2019 05:10:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hNZdK-0005w3-II for bug-guix@gnu.org; Mon, 06 May 2019 05:10:02 -0400 Sender: "Debbugs-submit" Resent-Message-ID: In-Reply-To: <20190505214153.32372-1-me@tobias.gr> (Tobias Geerinckx-Rice's message of "Sun, 5 May 2019 23:41:53 +0200") List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: Tobias Geerinckx-Rice Cc: 35588@debbugs.gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Tobias! Tobias Geerinckx-Rice writes: > Here's a patch to match package outputs (except =E2=80=98out=E2=80=99, si= nce it can't affect the relative score) in =E2=80=98guix search=E2=80=99. 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! ;-) =2D-=20 Chris --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-ui-Make-package-outputs-searchable.patch Content-Transfer-Encoding: quoted-printable From=2091d06d8950e700a8a3c3479c3613b579c53411c9 Mon Sep 17 00:00:00 2001 From: Chris Marusich 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. =2D-- 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 =2D-- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -180,9 +180,9 @@ hooks\" run when building the profile." ;;; =20 (define (find-packages-by-description regexps) =2D "Return two values: the list of packages whose name, synopsis, or =2Ddescription matches at least one of REGEXPS sorted by relevance, and the= list =2Dof relevance scores." + "Return two values: the list of packages whose name, synopsis, descripti= on, +or output matches at least one of REGEXPS sorted by relevance, and the lis= t 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 =2D-- a/guix/scripts/system/search.scm +++ b/guix/scripts/system/search.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2017, 2018 Ludovic Court=C3=A8s ;;; Copyright =C2=A9 2018 Cl=C3=A9ment Lassieur +;;; Copyright =C2=A9 2019 Chris Marusich ;;; ;;; This file is part of GNU Guix. ;;; @@ -128,14 +129,22 @@ columns." =20 (define %service-type-metrics ;; Metrics used to estimate the relevance of a search result. =2D `((,service-type-name* . 3) =2D (,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=3D> (service-type-location type) location-file) ((? string? file) =2D (basename file ".scm")) + (list (basename file ".scm"))) (#f =2D ""))) + '()))) . 1))) =20 (define (find-service-types regexps) diff --git a/guix/ui.scm b/guix/ui.scm index 92c845e944..9121e3daee 100644 =2D-- a/guix/ui.scm +++ b/guix/ui.scm @@ -11,6 +11,7 @@ ;;; Copyright =C2=A9 2016 Benz Schenk ;;; Copyright =C2=A9 2018 Kyle Meyer ;;; Copyright =C2=A9 2018 Ricardo Wurmus +;;; Copyright =C2=A9 2019 Chris Marusich ;;; ;;; This file is part of GNU Guix. ;;; @@ -1370,7 +1371,7 @@ WIDTH columns. EXTRA-FIELDS is a list of symbol/valu= e 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 =2Dfield/weight pairs, where FIELD is a procedure that returns a string +field/weight pairs, where FIELD is a procedure that returns a list of stri= ngs describing OBJ, and WEIGHT is a positive integer denoting the weight of th= is field in the final score. =20 @@ -1392,29 +1393,44 @@ score, the more relevant OBJ is to REGEXPS." (fold (lambda (metric relevance) (match metric ((field . weight) =2D (match (field obj) =2D (#f relevance) =2D (str (+ relevance =2D (* (score str) weight))))))) + (let ((strings (field obj))) + (+ relevance + (* weight + ;; Evaluates to 0 when strings is the empty list. + (apply + (map score strings)))))))) 0 metrics)) =20 (define %package-metrics ;; Metrics used to compute the "relevance score" of a package against a = set ;; of regexps. =2D `((,package-name . 4) =2D + `((,(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 packag= es. + '("out" "debug" "doc" "static")))) + (package-outputs package))) + . 1) ;; Match regexps on the raw Texinfo since formatting it is quite expen= sive ;; and doesn't have much of an effect on search results. (,(lambda (package) =2D (and=3D> (package-synopsis package) P_)) . 3) + (match (and=3D> (package-synopsis package) P_) + (#f '()) + (synopsis (list synopsis)))) + . 3) (,(lambda (package) =2D (and=3D> (package-description package) P_)) . 2) =2D + (match (and=3D> (package-description package) P_) + (#f '()) + (description (list description)))) + . 2) (,(lambda (type) (match (and=3D> (package-location type) location-file) =2D ((? string? file) (basename file ".scm")) =2D (#f ""))) + ((? string? file) (list (basename file ".scm"))) + (#f '()))) . 1))) =20 (define (package-relevance package regexps) =2D-=20 2.20.1 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEy/WXVcvn5+/vGD+x3UCaFdgiRp0FAlzP+aoACgkQ3UCaFdgi Rp2vHBAAt0ZFgM8T0NjBBlgrBuuYMH3Rx6Nk5fQt/9qzNQNMo0t2BeRFwHjZLmST /bKFpQi8H3/u/wRVr0bKcwM8P5Iu9C+swX6AJckt0h1XO85J/EOI4THCjCIAIx+/ vWMTNfaUhT1XEp3VLU/IpbyNyM7ZEEXL5PoE1UD0ZkL2ODuXHK1x4qO9lOApFvTq FRqveKBez1Qbj+jpWGRqGKbH4x0APg8Cm9M+jlGuzgw89lu0D44h0OB0A+s0GbMi 4OOZCug9eYKdeMQkpj4gv7HFjSSirrsCJnDOv+uK3y65oYUxfhV+nmSKIxshotr5 kElJn1UlJt7Eq0crqZ56Q1cnARNQKzOLiNleKZuzKSZf0n/3fsSTBvzEtajJmSqr vUSPB1ySWlLjva98azP0M8HxDE/X4xNyqgUlC9iKPZsi+nq+lFMbbzj1ljE4Upy9 c6ZaDL2hM71OqY3GUQYimeksaaKRdXexuO/LttV98L1zAiI494ZNoJ9hG7KHByd3 eJVhEtpGar8PynjapQhQPXqPwziEiqF/kcIUJ199BG44B11Sq3/8hDjcvcOiUEC8 D12vmC1BEvdIM3b/LJPFVQMSV/cxo47IXM3wGAwN3hp7CxWN1kyFZPY9LN7FdiQv WxaeOSmZGn9HN4AYSmLaSaF79+L5EYSjS4gAG14wdO0gYU+sMR4= =PVgI -----END PGP SIGNATURE----- --==-=-=--