diff options
author | Christopher Baines <mail@cbaines.net> | 2019-05-12 21:16:10 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2019-05-12 21:16:10 +0100 |
commit | 4a5f42ee5250fdf338c4ac444204e81e58f1f4b9 (patch) | |
tree | d404daa85865f07bc59751a8f5ae7acd12c8e138 | |
parent | 0bdc555ff8645869bdfdf3710038f135403c052c (diff) | |
download | data-service-4a5f42ee5250fdf338c4ac444204e81e58f1f4b9.tar data-service-4a5f42ee5250fdf338c4ac444204e81e58f1f4b9.tar.gz |
Add a function for searching for packages
-rw-r--r-- | guix-data-service/model/package.scm | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/guix-data-service/model/package.scm b/guix-data-service/model/package.scm index 7cb1683..39fa64d 100644 --- a/guix-data-service/model/package.scm +++ b/guix-data-service/model/package.scm @@ -7,6 +7,7 @@ #:use-module (guix-data-service model utils) #:export (select-existing-package-entries select-packages-in-revision + search-packages-in-revision count-packages-in-revision insert-into-package-entries inferior-packages->package-ids)) @@ -69,6 +70,36 @@ WHERE data.name IN (SELECT name FROM package_names);")) (list after-name) '())))) +(define* (search-packages-in-revision conn commit-hash + search-query + #:key limit-results) + (define query + (string-append + " +SELECT packages.name, + packages.version, + package_metadata.synopsis +FROM packages +INNER JOIN package_metadata + ON packages.package_metadata_id = package_metadata.id +WHERE packages.id IN ( + SELECT package_derivations.package_id + FROM package_derivations + INNER JOIN guix_revision_package_derivations + ON package_derivations.id = guix_revision_package_derivations.package_derivation_id + INNER JOIN guix_revisions + ON guix_revision_package_derivations.revision_id = guix_revisions.id + WHERE guix_revisions.commit = $1 +) +AND to_tsvector(name || ' ' || synopsis) @@ plainto_tsquery($2) +ORDER BY ts_rank_cd(to_tsvector(name || ' ' || synopsis), plainto_tsquery($2)) DESC" + (if limit-results + (string-append "\nLIMIT " (number->string limit-results)) + ""))) + + (exec-query conn query + (list commit-hash search-query))) + (define (count-packages-in-revision conn commit-hash) (define query " |