all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: zimoun <zimon.toutoune@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 36763@debbugs.gnu.org
Subject: bug#36763: `guix search` does unexpected logical and
Date: Fri, 13 Sep 2019 20:23:50 +0200	[thread overview]
Message-ID: <CAJ3okZ0UOVg=gV4Ckx0QSC3Qsx_ix3J0V7kJ5zew9TSax=bF+g@mail.gmail.com> (raw)
In-Reply-To: <87imrqrp8t.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 457 bytes --]

Hi Ludo,

Thank you to look at it.

On Thu, 25 Jul 2019 at 19:35, Ludovic Courtès <ludo@gnu.org> wrote:

>   (fold p (make-list …) metrics)
>
> looks a lot like:
>
>   (map (lambda (x) (fold p x metrics)) regexps)
>
> Well, something like that.  :-)

Second try attached with your advice. :-)


I am not sure where to place the newlines on long line.
Then I will try to add tests and send it.


Thank you.


All the best,
simon

[-- Attachment #2: search.patch2 --]
[-- Type: application/octet-stream, Size: 2473 bytes --]

diff --git a/guix/ui.scm b/guix/ui.scm
index 7920335928..80b92bcc5f 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -1281,33 +1281,37 @@ 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."
-  (define (score str)
-    (define scores
-      (map (lambda (regexp)
-             (fold-matches regexp str 0
-                           (lambda (m score)
-                             (+ score
-                                (if (string=? (match:substring m) str)
-                                    5             ;exact match
-                                    1)))))
-           regexps))
+  (define (score str regexp)
+    (fold-matches regexp str 0
+                  (lambda (m score)
+                    (+ score
+                       (if (string=? (match:substring m) str)
+                           5             ;exact match
+                           1)))))
+
+  (let ((scores (map
+                 (lambda (regexp)
+                   (fold
+                    (lambda (metric relevance)
+                      (match metric
+                        ((field . weight)
+                         (match (field obj)
+                           (#f  relevance)
+                           ((? string? str)
+                            (+ relevance (* (score str regexp) weight)))
+                           ((lst ...)
+                            (+ relevance (* weight
+                                            (apply + (map
+                                                      (lambda (str)
+                                                        (score str regexp))
+                                                      lst)))))))))
+                    0 metrics))
+                 regexps)))
 
     ;; Return zero if one of REGEXPS doesn't match.
     (if (any zero? scores)
         0
-        (reduce + 0 scores)))
-
-  (fold (lambda (metric relevance)
-          (match metric
-            ((field . weight)
-             (match (field obj)
-               (#f  relevance)
-               ((? string? str)
-                (+ relevance (* (score str) weight)))
-               ((lst ...)
-                (+ relevance (* weight (apply + (map score lst)))))))))
-        0
-        metrics))
+        (reduce + 0 scores))))
 
 (define %package-metrics
   ;; Metrics used to compute the "relevance score" of a package against a set

  reply	other threads:[~2019-09-13 18:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-22 17:11 bug#36763: `guix search` does unexpected logical and zimoun
2019-07-25 17:35 ` Ludovic Courtès
2019-09-13 18:23   ` zimoun [this message]
2019-09-16  8:17     ` Ludovic Courtès
2019-09-19 17:32       ` zimoun
2019-09-19 19:56         ` 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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJ3okZ0UOVg=gV4Ckx0QSC3Qsx_ix3J0V7kJ5zew9TSax=bF+g@mail.gmail.com' \
    --to=zimon.toutoune@gmail.com \
    --cc=36763@debbugs.gnu.org \
    --cc=ludo@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 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.