guix: Automatically quote and append wildcard to filesearch patterns.

* guix/scripts/filesearch.scm (search-file-package): Use sqlite-bind-arguments
instead of brittle format.
Quote patterns to avoid interpretation of special characters like "-" in
"transmission-gtk".
Append wildcard to search patterns to be smarteer at inferring the
matches (e.g. "perl" should match "perl5").
This commit is contained in:
Pierre Neidhardt 2020-08-24 12:47:51 +02:00
parent 49b52c2c7b
commit 25147f983b
No known key found for this signature in database
GPG key ID: 9BDCF497A4BBCC7F

View file

@ -138,7 +138,7 @@ (define (persist-package-files db package)
#:files (directory-files path)))))
output-path-pairs)))
(define (search-file-package pattern)
(define (search-file-package pattern . more-patterns)
"Return corresponding packages.
Packages or ordered by most relevant last.
Path is subject to SQLite \"full-text search\" pattern matching.
@ -155,10 +155,14 @@ (define (search-file-package pattern)
db
;; REVIEW: Is this inner join cheap?
(string-append
"select subpath, name, version, output"
" from Files inner join Packages on Files.package = Packages.id"
(format #f " where Files.subpath match '~a' order by rank" pattern))
stmt
"SELECT subpath, name, version, output"
" FROM Files INNER JOIN Packages ON Files.package = Packages.id"
" WHERE Files.subpath MATCH :pattern ORDER BY RANK")
stmt
(sqlite-bind-arguments stmt #:pattern (string-concatenate
(map (lambda (s)
(format #f "~s*" s))
(cons pattern more-patterns))))
(map vector->list
(sqlite-fold cons '() stmt)))))
@ -206,7 +210,7 @@ (define (test-search)
;; with xdelta (probably not since it would send entries for Guix versions
;; that the user does not have).
;; Statistics
;; Measures
;;
;; Context:
;; - 14,000 packages