From 25147f983bdf432b03e8271abe0318f4812f94ba Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Mon, 24 Aug 2020 12:47:51 +0200 Subject: [PATCH] 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"). --- guix/scripts/filesearch.scm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/guix/scripts/filesearch.scm b/guix/scripts/filesearch.scm index a409dc152e..3cb542d7b7 100644 --- a/guix/scripts/filesearch.scm +++ b/guix/scripts/filesearch.scm @@ -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