branch: elpa/flx
commit 4d625bdfb92f12738f12606ad869a26f2020e66e
Author: PythonNut <[email protected]>
Commit: PythonNut <[email protected]>
Test score before building possible match
---
flx.el | 45 ++++++++++++++++++++++++++-------------------
1 file changed, 26 insertions(+), 19 deletions(-)
diff --git a/flx.el b/flx.el
index 0d5640bb03..77f3d3477b 100644
--- a/flx.el
+++ b/flx.el
@@ -245,7 +245,13 @@ See documentation for logic."
(puthash str res cache))
res))))
-(defun flx-get-matches-worker (greater-than q-index query-length heatmap
match-cache str-info query)
+(defun flx-get-matches-worker (greater-than
+ q-index
+ query-length
+ heatmap
+ match-cache
+ str-info
+ query)
(let ((hash-key (+ q-index
(* (or greater-than 0)
query-length))))
@@ -260,28 +266,29 @@ See documentation for logic."
(mapcar (lambda (index)
(cons (list index)
(cons (aref heatmap index) 0))) indexes)
- (let ((match) (best-score most-negative-fixnum))
+ (let ((match)
+ (score)
+ (best-score most-negative-fixnum))
(dolist (index indexes (and match (list match)))
(dolist (elem (flx-get-matches-worker index (1+ q-index)
query-length heatmap
match-cache str-info query))
- (setq elem
- (cons (cons index (car elem))
- (cons
- (+ (cadr elem)
- (aref heatmap index)
- (if (= (1- (caar elem)) index)
- (+ (* (min (cddr elem)
- 3)
- 15)
- 60)
- 0))
- (if (= (1- (caar elem)) index)
- (1+ (cddr elem))
- 0))))
+ (setq score (+ (cadr elem)
+ (aref heatmap index)
+ (if (= (1- (caar elem)) index)
+ (+ (* (min (cddr elem)
+ 3)
+ 15)
+ 60)
+ 0)))
+
;; we only care about the optimal score
- (when (> (cadr elem) best-score)
- (setq best-score (cadr elem)
- match elem)))))))
+ (when (> score best-score)
+ (setq best-score score
+ match (cons (cons index (car elem))
+ (cons score
+ (if (= (1- (caar elem)) index)
+ (1+ (cddr elem))
+ 0))))))))))
match-cache))))
(defun flx-score (str query &optional cache)