branch: elpa/flx commit 955772f489300212a18d058ae7d3ee01e0e26847 Author: Le Wang <le.w...@agworld.com.au> Commit: Le Wang <le.w...@agworld.com.au>
optimize full-match boost --- flx.el | 11 ++++++++--- tests/flx-test.el | 26 +++++++++++++++++--------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/flx.el b/flx.el index 102b5db2cb..cda9c04a8e 100644 --- a/flx.el +++ b/flx.el @@ -13,7 +13,7 @@ ;; Version: 0.1 ;; Last-Updated: ;; By: -;; Update #: 6 +;; Update #: 11 ;; URL: ;; Keywords: ;; Compatibility: @@ -285,10 +285,15 @@ e.g. (\"aab\" \"ab\") returns (let* ((info-hash (flx-process-cache str cache)) (heatmap (gethash 'heatmap info-hash)) (matches (flx-get-matches info-hash query)) + (query-length (length query)) + (full-match-boost (and (< query-length 5) + (> query-length 1))) (best-score nil)) (mapc (lambda (match-positions) - (let ((score (if (= (length match-positions) - (length str)) + (let ((score (if (and + full-match-boost + (= (length match-positions) + (length str))) 10000 0)) (contiguous-count 0) diff --git a/tests/flx-test.el b/tests/flx-test.el index e4035bd51e..ec03f0ceba 100644 --- a/tests/flx-test.el +++ b/tests/flx-test.el @@ -13,7 +13,7 @@ ;; Version: 0.1 ;; Last-Updated: ;; By: -;; Update #: 5 +;; Update #: 7 ;; URL: ;; Keywords: ;; Compatibility: @@ -169,13 +169,6 @@ (car string-score))))) -(ert-deftest flx-basename-entire () - "whole match is preferred" - (let* ((query "a") - (higher (flx-score "a" query (flx-make-filename-cache))) - (lower (flx-score "ab" query (flx-make-filename-cache)))) - (should (> (car higher) (car lower))))) - (ert-deftest flx-basename-order () "index of match matters" (let* ((query "a") @@ -191,13 +184,28 @@ (should (> (car higher) (car lower))))) -(ert-deftest flx-entire-match () +(ert-deftest flx-entire-match-1 () + "whole match is preferred" + (let* ((query "a") + (higher (flx-score "a" query (flx-make-filename-cache))) + (lower (flx-score "ab" query (flx-make-filename-cache)))) + (should (> (car higher) (car lower))))) + +(ert-deftest flx-entire-match-3 () "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))))) +(ert-deftest flx-entire-match-5 () + "when entire string is match, 4 letters is the cutoff when +substring can overpower abbreviation." + (let* ((query "rssss") + (higher (flx-score "rssss" query (flx-make-filename-cache))) + (lower (flx-score "rff-sff-sff-sff-sff" query (flx-make-filename-cache)))) + (should (> (car higher) (car lower))))) + ;;;;;;;;;;;;;; ;; advanced ;; ;;;;;;;;;;;;;;