From: Simon Tournier <zimon.toutoune@gmail.com>
To: 73220@debbugs.gnu.org
Cc: aurtzy@gmail.com, "Simon Tournier" <zimon.toutoune@gmail.com>,
"Christopher Baines" <guix@cbaines.net>,
"Josselin Poiret" <dev@jpoiret.xyz>,
"Ludovic Courtès" <ludo@gnu.org>,
"Mathieu Othacehe" <othacehe@gnu.org>,
"Simon Tournier" <zimon.toutoune@gmail.com>,
"Tobias Geerinckx-Rice" <me@tobias.gr>
Subject: [bug#73220] [PATCH v2] ui: Add partial match relevance scoring.
Date: Fri, 13 Sep 2024 16:24:06 +0200 [thread overview]
Message-ID: <fdb82e6274c5d0bbc3470b09ca73cccf4abb5a9a.1726237401.git.zimon.toutoune@gmail.com> (raw)
In-Reply-To: <c882a1a5d8085e513c5c3d8bc997e3dd8f4460bb.1726210587.git.aurtzy@gmail.com>
* guix/ui.scm (char-set:delimiters): New variable.
(revelance)[string-match-term?]: New procedure.
[score]: Use it.
Change-Id: If2edc0e08b338a0064f73425db60d688c0535fb0
---
guix/ui.scm | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/guix/ui.scm b/guix/ui.scm
index 966f0611f6..a8d1d120a4 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -1678,6 +1678,14 @@ (define* (package->recutils p port #:optional (width (terminal-columns))
;;; Searching.
;;;
+(define char-set:delimiters (char-set-xor
+ (char-set #\-) ;remove from punctuation
+ (char-set-union (char-set #\nul)
+ (char-set #\newline)
+ char-set:punctuation
+ char-set:symbol
+ char-set:whitespace)))
+
(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
@@ -1687,13 +1695,28 @@ (define (relevance obj regexps metrics)
A score of zero means that OBJ does not match any of REGEXPS. The higher the
score, the more relevant OBJ is to REGEXPS."
+ (define (string-match-term? regex-match str)
+ (let* ((start (match:start regex-match))
+ (char:start (if (= 0 start)
+ #\nul
+ (string-ref str (1- start))))
+ (end (match:end regex-match))
+ (char:end (if (= end (string-length str))
+ #\nul
+ (string-ref str end))))
+ (and (char-set-contains? char-set:delimiters char:start)
+ (char-set-contains? char-set:delimiters char:end))))
+
(define (score regexp str)
(fold-matches regexp str 0
(lambda (m score)
(+ score
- (if (string=? (match:substring m) str)
- 5 ;exact match
- 1)))))
+ (cond
+ ((string=? (match:substring m) str)
+ 5) ;exact match
+ ((string-match-term? m str)
+ 3) ;XXX
+ (else 1))))))
(define (regexp->score regexp)
(let ((score-regexp (lambda (str) (score regexp str))))
base-commit: 98bc13b9ea5f22a60de6c289d59072638001e08e
prerequisite-patch-id: 912de410e3d8a0796e83bfa50047debb0030b624
prerequisite-patch-id: 9c72d45734a13bd80021b14b562ed1b6238aa7ca
prerequisite-patch-id: 952cbe8dad322348d00f15125b512d34aaad8009
prerequisite-patch-id: fa6543fd5e6ec54a5036335aa5fa2b3a52675610
prerequisite-patch-id: cd68729ed441ec8235fde738e1f19669b570b099
prerequisite-patch-id: 53c5439602662bd61a3729aedf9327dfee5e9956
prerequisite-patch-id: a7edcd751c7a127f76b9c8e33ee425b6e800cfd7
prerequisite-patch-id: 29c1b2b9fcc017cff904ff3c1a32f65a6d54bad8
prerequisite-patch-id: 71757f95077bb7812f9d5a4e942c15b152ec7ac9
--
2.45.2
prev parent reply other threads:[~2024-09-13 14:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-13 7:02 [bug#73220] [PATCH] ui: Add more nuance to relevance scoring aurtzy
2024-09-13 14:12 ` Simon Tournier
2024-09-14 0:17 ` aurtzy
2024-09-13 14:24 ` Simon Tournier [this message]
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=fdb82e6274c5d0bbc3470b09ca73cccf4abb5a9a.1726237401.git.zimon.toutoune@gmail.com \
--to=zimon.toutoune@gmail.com \
--cc=73220@debbugs.gnu.org \
--cc=aurtzy@gmail.com \
--cc=dev@jpoiret.xyz \
--cc=guix@cbaines.net \
--cc=ludo@gnu.org \
--cc=me@tobias.gr \
--cc=othacehe@gnu.org \
/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).