guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch wip-filesearch updated: guix: Include synopsis and description in


From: guix-commits
Subject: branch wip-filesearch updated: guix: Include synopsis and description in filesearch database.
Date: Sat, 26 Sep 2020 09:57:47 -0400

This is an automated email from the git hooks/post-receive script.

ambrevar pushed a commit to branch wip-filesearch
in repository guix.

The following commit(s) were added to refs/heads/wip-filesearch by this push:
     new 0127cfa  guix: Include synopsis and description in filesearch database.
0127cfa is described below

commit 0127cfa5d0898222257a716bf7b0a167f31cc6dd
Author: Pierre Neidhardt <mail@ambrevar.xyz>
AuthorDate: Sat Sep 26 13:48:35 2020 +0200

    guix: Include synopsis and description in filesearch database.
---
 guix/scripts/filesearch.scm | 78 +++++++++++++++++++++++++++++++++++++--------
 guix/scripts/schema.sql     |  8 +++++
 2 files changed, 73 insertions(+), 13 deletions(-)

diff --git a/guix/scripts/filesearch.scm b/guix/scripts/filesearch.scm
index 3cb542d..8b58202 100644
--- a/guix/scripts/filesearch.scm
+++ b/guix/scripts/filesearch.scm
@@ -59,17 +59,37 @@ string SQL for DB."
                     (path (error "Missing argument"))
                     (files (error "Missing argument"))
                     (version (error "Missing argument"))
+                    (synopsis (error "Missing argument"))
+                    (description (error "Missing argument"))
                     (guix-version (error "Missing argument")))
   "FILES is a list of path underneath PATH."
-  (sqlite-exec
-   db
-   (string-append "insert into Packages (name, system, output, path, version, 
guix)"
-                  ;; "insert or replace into Packages (name, system, output, 
path, version, guix)"
-                  (format #f " values (~s, ~s, ~s, ~s, ~s, ~s)"
-                          name system output path version guix-version)
-                  ;; " on conflict (path) do nothing"
-                  ))
+  (with-statement
+      db
+      (string-append "insert into Packages (name, system, output, version, 
path, guix)"
+                     " values (:name, :system, :output, :version, :path, 
:guix)")
+      stmt
+    (sqlite-bind-arguments stmt
+                           #: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?
+    (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
      (lambda (file)
        (sqlite-exec
@@ -134,6 +154,8 @@ matches both \"/bin/foo\" and \"/usr/bin/foo\" but not 
\"barbin\"."
                          #:output output
                          #:path path ; Storing /gnu/store for all packages has 
no significant size cost.
                          #:version (package-version package)
+                         #:synopsis (package-synopsis package)
+                         #:description (package-description package)
                          #:guix-version %guix-version
                          #:files (directory-files path)))))
          output-path-pairs)))
@@ -166,6 +188,29 @@ Example patterns:
       (map vector->list
            (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)
   (for-each
    (match-lambda
@@ -213,14 +258,21 @@ Example patterns:
 ;; Measures
 ;;
 ;; Context:
-;; - 14,000 packages
-;; - 1700 store items
+;; - 15005 packages
+;; - 1796 store items
 ;; - CPU 3.5 GHz
 ;; - SSD
 ;;
-;; Results:
+;; Data with synopsis and description:
+;; - Database generation time: 30 seconds.
+;; - Database size: 37 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: 31 MiB.
-;; - Database Zstd-compressed size: 6.1 MiB.
+;; - Database size: 36 MiB.
+;; - Database Zstd-compressed size: 6.0 MiB.
 ;; - Zstd-compression time: 0.13 seconds.
 ;; - FTS queries: < 0.01 seconds.
diff --git a/guix/scripts/schema.sql b/guix/scripts/schema.sql
index ce90de2..5c7925c 100644
--- a/guix/scripts/schema.sql
+++ b/guix/scripts/schema.sql
@@ -9,6 +9,14 @@ create table if not exists Packages (
     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(
     subpath,
     package



reply via email to

[Prev in Thread] Current Thread [Next in Thread]