From: "Ludovic Courtès" <ludo@gnu.org>
To: Lars-Dominik Braun <ldb@leibniz-psychology.org>
Cc: 58136@debbugs.gnu.org, zimoun <zimon.toutoune@gmail.com>
Subject: [bug#58136] [PATCH] ui: Improve sort order when searching package names.
Date: Mon, 17 Oct 2022 09:46:28 +0200 [thread overview]
Message-ID: <8735bmj3jf.fsf_-_@gnu.org> (raw)
In-Reply-To: <Y0aj2GRdkZG6cFhs@zpidnb93> (Lars-Dominik Braun's message of "Wed, 12 Oct 2022 13:24:08 +0200")
Hi!
Lars-Dominik Braun <ldb@leibniz-psychology.org> skribis:
> diff --git a/guix/packages.scm b/guix/packages.scm
> index 94e464cd01..9934501cdb 100644
> --- a/guix/packages.scm
> +++ b/guix/packages.scm
> @@ -86,6 +86,7 @@ (define-module (guix packages)
> this-package
> package-name
> package-upstream-name
> + package-upstream-name*
> package-version
> package-full-name
> package-source
> @@ -657,6 +658,38 @@ (define (package-upstream-name package)
> (or (assq-ref (package-properties package) 'upstream-name)
> (package-name package)))
>
> +(define (package-upstream-name* package)
> + "Return the upstream name of PACKAGE, which could be different from the name
> +it has in Guix."
s/which could.*Guix/accounting for commonly-used package name prefixes
in addition to the @code{upstream-name} property/
Preferably make this addition in a separate commit.
> +++ b/guix/ui.scm
> @@ -1623,10 +1623,23 @@ (define (relevance obj regexps metrics)
> (define (score regexp str)
> (fold-matches regexp str 0
> (lambda (m score)
> - (+ score
> - (if (string=? (match:substring m) str)
> - 5 ;exact match
> - 1)))))
> + (let* ((start (- (match:start m) 1))
> + (end (match:end m))
> + (left (if (>= start 0) (string-ref str start) #f))
> + (right (if (< end (string-length str)) (string-ref str end) #f))
> + (delimiter-classes '(Cc Cf Pd Pe Pf Pi Po Ps Sk Zs Zl Zp))
> + (delim-left (or (member (and=> left char-general-category) delimiter-classes) (eq? left #f)))
> + (delim-right (or (member (and=> right char-general-category) delimiter-classes) (eq? right #f))))
> + (max score
> + (cond
> + ;; regexp is a full match for str.
> + ((and (eq? left #f) (eq? right #f)) 4)
> + ;; regexp matches a single word in str.
> + ((and delim-left delim-right) 3)
> + ;; regexp matches the beginning or end of a word in str.
> + ((or delim-left delim-right) 2)
> + ;; Everything else.
> + (#t 1)))))))
The intent is to have all regexps behave as if the user passed \<STR\>,
is that right? Would be nice to have a comment clarifying that above
and perhaps making it a separate change?
Stylistic notes:
(if cond consequent #f) => (and cond consequent)
(eq? x #f) => (not x)
(cond … (#t x)) => (cond … (else x))
> @@ -1635,10 +1648,11 @@ (define (regexp->score regexp)
> ((field . weight)
> (match (field obj)
> (#f relevance)
> + ('() relevance)
> ((? string? str)
> - (+ relevance (* (score-regexp str) weight)))
> + (max relevance (* (score-regexp str) weight)))
> ((lst ...)
> - (+ relevance (* weight (apply + (map score-regexp lst)))))))))
> + (max relevance (* weight (apply max (map score-regexp lst)))))))))
Intuitively I would expect scores to add up, otherwise we’re kinda
losing information; so I would not make this change. WDYT?
There’s a test for ‘package-relevance’ in tests/ui.scm. Please make
sure it still passes and ideally add relevant tests such as the CSV
example you gave.
Thanks!
Ludo’.
next prev parent reply other threads:[~2022-10-17 7:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-28 9:27 [bug#58136] [PATCH] ui: Improve sort order when searching package names Lars-Dominik Braun
2022-09-28 14:26 ` zimoun
2022-09-28 20:23 ` Maxime Devos
2022-09-28 20:45 ` Maxime Devos
2022-09-28 21:40 ` zimoun
2022-09-28 21:43 ` Maxime Devos
2022-10-01 21:42 ` Ludovic Courtès
2022-10-02 8:26 ` zimoun
2022-10-12 11:24 ` Lars-Dominik Braun
2022-10-17 7:46 ` Ludovic Courtès [this message]
2022-10-17 8:19 ` zimoun
2022-12-09 11:49 ` Lars-Dominik Braun
2022-12-13 13:28 ` bug#58136: " Ludovic Courtès
2022-12-13 14:53 ` [bug#58136] " Lars-Dominik Braun
2022-12-13 16:40 ` Ludovic Courtès
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
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8735bmj3jf.fsf_-_@gnu.org \
--to=ludo@gnu.org \
--cc=58136@debbugs.gnu.org \
--cc=ldb@leibniz-psychology.org \
--cc=zimon.toutoune@gmail.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).