mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2025-01-31 06:46:50 +01:00
guix: Include synopsis and description in filesearch database.
This commit is contained in:
parent
25147f983b
commit
0127cfa5d0
2 changed files with 73 additions and 13 deletions
|
@ -59,17 +59,37 @@ (define* (add-files db
|
||||||
(path (error "Missing argument"))
|
(path (error "Missing argument"))
|
||||||
(files (error "Missing argument"))
|
(files (error "Missing argument"))
|
||||||
(version (error "Missing argument"))
|
(version (error "Missing argument"))
|
||||||
|
(synopsis (error "Missing argument"))
|
||||||
|
(description (error "Missing argument"))
|
||||||
(guix-version (error "Missing argument")))
|
(guix-version (error "Missing argument")))
|
||||||
"FILES is a list of path underneath PATH."
|
"FILES is a list of path underneath PATH."
|
||||||
(sqlite-exec
|
(with-statement
|
||||||
db
|
db
|
||||||
(string-append "insert into Packages (name, system, output, path, version, guix)"
|
(string-append "insert into Packages (name, system, output, version, path, guix)"
|
||||||
;; "insert or replace into Packages (name, system, output, path, version, guix)"
|
" values (:name, :system, :output, :version, :path, :guix)")
|
||||||
(format #f " values (~s, ~s, ~s, ~s, ~s, ~s)"
|
stmt
|
||||||
name system output path version guix-version)
|
(sqlite-bind-arguments stmt
|
||||||
;; " on conflict (path) do nothing"
|
#:name name
|
||||||
))
|
#:system system
|
||||||
|
#:output output
|
||||||
|
#:path path
|
||||||
|
#:version version
|
||||||
|
#:guix guix-version)
|
||||||
|
(map vector->list
|
||||||
|
(sqlite-fold cons '() stmt)))
|
||||||
(let ((id ((@@ (guix store database) last-insert-row-id) db))) ; TODO: Export?
|
(let ((id ((@@ (guix store database) last-insert-row-id) db))) ; TODO: Export?
|
||||||
|
(with-statement
|
||||||
|
db
|
||||||
|
(string-append "insert into Info (name, synopsis, description, package)"
|
||||||
|
" values (:name, :synopsis, :description, :id)")
|
||||||
|
stmt
|
||||||
|
(sqlite-bind-arguments stmt
|
||||||
|
#:name name
|
||||||
|
#:synopsis synopsis
|
||||||
|
#:description description
|
||||||
|
#:id id)
|
||||||
|
(map vector->list
|
||||||
|
(sqlite-fold cons '() stmt)))
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (file)
|
(lambda (file)
|
||||||
(sqlite-exec
|
(sqlite-exec
|
||||||
|
@ -134,6 +154,8 @@ (define (persist-package-files db package)
|
||||||
#:output output
|
#:output output
|
||||||
#:path path ; Storing /gnu/store for all packages has no significant size cost.
|
#:path path ; Storing /gnu/store for all packages has no significant size cost.
|
||||||
#:version (package-version package)
|
#:version (package-version package)
|
||||||
|
#:synopsis (package-synopsis package)
|
||||||
|
#:description (package-description package)
|
||||||
#:guix-version %guix-version
|
#:guix-version %guix-version
|
||||||
#:files (directory-files path)))))
|
#:files (directory-files path)))))
|
||||||
output-path-pairs)))
|
output-path-pairs)))
|
||||||
|
@ -166,6 +188,29 @@ (define (search-file-package pattern . more-patterns)
|
||||||
(map vector->list
|
(map vector->list
|
||||||
(sqlite-fold cons '() stmt)))))
|
(sqlite-fold cons '() stmt)))))
|
||||||
|
|
||||||
|
(define (search-package pattern . more-patterns)
|
||||||
|
"Return corresponding packages.
|
||||||
|
Search is performed over name, synopsis, description.
|
||||||
|
Packages or ordered by most relevant last.
|
||||||
|
Search is subject to SQLite \"full-text search\" pattern matching.
|
||||||
|
See https://www.sqlite.org/fts5.html."
|
||||||
|
(let ((pattern (string-concatenate
|
||||||
|
(map (lambda (s)
|
||||||
|
(format #f "~s*" s))
|
||||||
|
(cons pattern more-patterns)))))
|
||||||
|
(with-database %db db
|
||||||
|
(with-statement
|
||||||
|
db
|
||||||
|
(string-append
|
||||||
|
"SELECT name FROM Info WHERE Info MATCH :pattern ORDER BY RANK")
|
||||||
|
stmt
|
||||||
|
(sqlite-bind-arguments
|
||||||
|
stmt
|
||||||
|
#:pattern (format #f "name:~a OR synopsis:~a OR description:~a"
|
||||||
|
pattern pattern pattern))
|
||||||
|
(map vector->list
|
||||||
|
(sqlite-fold cons '() stmt))))))
|
||||||
|
|
||||||
(define (format-search search-result)
|
(define (format-search search-result)
|
||||||
(for-each
|
(for-each
|
||||||
(match-lambda
|
(match-lambda
|
||||||
|
@ -213,14 +258,21 @@ (define (test-search)
|
||||||
;; Measures
|
;; Measures
|
||||||
;;
|
;;
|
||||||
;; Context:
|
;; Context:
|
||||||
;; - 14,000 packages
|
;; - 15005 packages
|
||||||
;; - 1700 store items
|
;; - 1796 store items
|
||||||
;; - CPU 3.5 GHz
|
;; - CPU 3.5 GHz
|
||||||
;; - SSD
|
;; - SSD
|
||||||
;;
|
;;
|
||||||
;; Results:
|
;; Data with synopsis and description:
|
||||||
;; - Database generation time: 30 seconds.
|
;; - Database generation time: 30 seconds.
|
||||||
;; - Database size: 31 MiB.
|
;; - Database size: 37 MiB.
|
||||||
;; - Database Zstd-compressed size: 6.1 MiB.
|
;; - Database Zstd-compressed size: 6.4 MiB.
|
||||||
|
;; - Zstd-compression time: 0.13 seconds.
|
||||||
|
;; - FTS queries: < 0.01 seconds.
|
||||||
|
;;
|
||||||
|
;; Data without synopsis and description:
|
||||||
|
;; - Database generation time: 30 seconds.
|
||||||
|
;; - Database size: 36 MiB.
|
||||||
|
;; - Database Zstd-compressed size: 6.0 MiB.
|
||||||
;; - Zstd-compression time: 0.13 seconds.
|
;; - Zstd-compression time: 0.13 seconds.
|
||||||
;; - FTS queries: < 0.01 seconds.
|
;; - FTS queries: < 0.01 seconds.
|
||||||
|
|
|
@ -9,6 +9,14 @@ create table if not exists Packages (
|
||||||
guix text not null
|
guix text not null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
create virtual table if not exists Info using fts5(
|
||||||
|
name,
|
||||||
|
synopsis,
|
||||||
|
description,
|
||||||
|
package
|
||||||
|
);
|
||||||
|
|
||||||
create virtual table if not exists Files using fts5(
|
create virtual table if not exists Files using fts5(
|
||||||
subpath,
|
subpath,
|
||||||
package
|
package
|
||||||
|
|
Loading…
Reference in a new issue