@@ -1678,6 +1678,14 @@ (define* (package->recutils p port #:optional (width (terminal-columns))
;;; Searching.
;;;
+(define char-set:delimiters (char-set-xor
+ (char-set #\-) ;remove from punctuation
+ (char-set-union (char-set #\nul)
+ (char-set #\newline)
+ char-set:punctuation
+ char-set:symbol
+ char-set:whitespace)))
+
(define (relevance obj regexps metrics)
"Compute a \"relevance score\" for OBJ as a function of its number of
matches of REGEXPS and accordingly to METRICS. METRICS is list of
@@ -1687,13 +1695,28 @@ (define (relevance obj regexps metrics)
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 (string-match-term? regex-match str)
+ (let* ((start (match:start regex-match))
+ (char:start (if (= 0 start)
+ #\nul
+ (string-ref str (1- start))))
+ (end (match:end regex-match))
+ (char:end (if (= end (string-length str))
+ #\nul
+ (string-ref str end))))
+ (and (char-set-contains? char-set:delimiters char:start)
+ (char-set-contains? char-set:delimiters char:end))))
+
(define (score regexp str)
(fold-matches regexp str 0
(lambda (m score)
(+ score
- (if (string=? (match:substring m) str)
- 5 ;exact match
- 1)))))
+ (cond
+ ((string=? (match:substring m) str)
+ 5) ;exact match
+ ((string-match-term? m str)
+ 3) ;XXX
+ (else 1))))))
(define (regexp->score regexp)
(let ((score-regexp (lambda (str) (score regexp str))))