ui: Cut off search early if any regexp does not match.
* guix/ui.scm (relevance): When one of the regexps does not match, cut off early and return 0. Do not try to match the remaining regexps.
This commit is contained in:
parent
cf48f0fc4c
commit
e70a884706
1 changed files with 11 additions and 5 deletions
16
guix/ui.scm
16
guix/ui.scm
|
|
@ -14,6 +14,7 @@
|
||||||
;;; Copyright © 2019 Chris Marusich <cmmarusich@gmail.com>
|
;;; Copyright © 2019 Chris Marusich <cmmarusich@gmail.com>
|
||||||
;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
|
;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
|
||||||
;;; Copyright © 2019 Simon Tournier <zimon.toutoune@gmail.com>
|
;;; Copyright © 2019 Simon Tournier <zimon.toutoune@gmail.com>
|
||||||
|
;;; Copyright © 2020 Arun Isaac <arunisaac@systemreboot.net>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
|
@ -1520,11 +1521,16 @@ score, the more relevant OBJ is to REGEXPS."
|
||||||
(+ relevance (* weight (apply + (map score-regexp lst)))))))))
|
(+ relevance (* weight (apply + (map score-regexp lst)))))))))
|
||||||
0 metrics)))
|
0 metrics)))
|
||||||
|
|
||||||
(let ((scores (map regexp->score regexps)))
|
(let loop ((regexps regexps)
|
||||||
;; Return zero if one of REGEXPS doesn't match.
|
(total-score 0))
|
||||||
(if (any zero? scores)
|
(match regexps
|
||||||
0
|
((head . tail)
|
||||||
(reduce + 0 scores))))
|
(let ((score (regexp->score head)))
|
||||||
|
;; Return zero if one of PATTERNS doesn't match.
|
||||||
|
(if (zero? score)
|
||||||
|
0
|
||||||
|
(loop tail (+ total-score score)))))
|
||||||
|
(() total-score))))
|
||||||
|
|
||||||
(define %package-metrics
|
(define %package-metrics
|
||||||
;; Metrics used to compute the "relevance score" of a package against a set
|
;; Metrics used to compute the "relevance score" of a package against a set
|
||||||
|
|
|
||||||
Reference in a new issue