emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/flx 8ee8a877ab 028/182: boost entire match score


From: ELPA Syncer
Subject: [nongnu] elpa/flx 8ee8a877ab 028/182: boost entire match score
Date: Tue, 13 Dec 2022 03:59:22 -0500 (EST)

branch: elpa/flx
commit 8ee8a877abca48de3f9f3dcd0d8d816fc740971d
Author: Le Wang <le.wang@agworld.com.au>
Commit: Le Wang <le.wang@agworld.com.au>

    boost entire match score
    
    - This is helpful when the matched string is short.
    
    resolves #7
---
 flx.el            | 13 ++++++++-----
 tests/flx-test.el |  9 ++++++++-
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/flx.el b/flx.el
index 7d429c1d37..102b5db2cb 100644
--- a/flx.el
+++ b/flx.el
@@ -13,7 +13,7 @@
 ;; Version: 0.1
 ;; Last-Updated:
 ;;           By:
-;;     Update #: 4
+;;     Update #: 6
 ;; URL:
 ;; Keywords:
 ;; Compatibility:
@@ -286,11 +286,14 @@ e.g. (\"aab\" \"ab\") returns
            (heatmap (gethash 'heatmap info-hash))
            (matches (flx-get-matches info-hash query))
            (best-score nil))
-      (mapc (lambda (match-vector)
-              (let ((score 0)
+      (mapc (lambda (match-positions)
+              (let ((score (if (= (length match-positions)
+                                  (length str))
+                               10000
+                             0))
                     (contiguous-count 0)
                     last-match)
-                (loop for index in match-vector
+                (loop for index in match-positions
                       do (progn
                            (if (and last-match
                                     (= (1+ last-match) index))
@@ -302,7 +305,7 @@ e.g. (\"aab\" \"ab\") returns
                            (setq last-match index)))
                 (if (or (null best-score)
                         (> score (car best-score)))
-                    (setq best-score (cons score match-vector)))))
+                    (setq best-score (cons score match-positions)))))
             matches)
       best-score)))
 
diff --git a/tests/flx-test.el b/tests/flx-test.el
index 73b30b6fb1..e4035bd51e 100644
--- a/tests/flx-test.el
+++ b/tests/flx-test.el
@@ -13,7 +13,7 @@
 ;; Version: 0.1
 ;; Last-Updated:
 ;;           By:
-;;     Update #: 4
+;;     Update #: 5
 ;; URL:
 ;; Keywords:
 ;; Compatibility:
@@ -191,6 +191,13 @@
     (should (> (car higher) (car lower)))))
 
 
+(ert-deftest flx-entire-match ()
+  "when entire string is match, it shoud overpower acronym matches"
+  (let* ((query "rss")
+         (higher (flx-score "rss" query (flx-make-filename-cache)))
+         (lower (flx-score "rff-sff-sff" query (flx-make-filename-cache))))
+    (should (> (car higher) (car lower)))))
+
 ;;;;;;;;;;;;;;
 ;; advanced ;;
 ;;;;;;;;;;;;;;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]