On Sat, 7 Mar 2020 at 14:31, Arun Isaac wrote: > diff --git a/gnu/packages.scm b/gnu/packages.scm > index d22c992bb1..c8e221de68 100644 > --- a/gnu/packages.scm > +++ b/gnu/packages.scm [...] > @@ -426,6 +429,43 @@ reducing the memory footprint." > #:opts '(#:to-file? #t))))) > cache-file) > > +(define %package-search-index > + ;; Location of the package search-index > + "/lib/guix/package-search.index") > + > +(define (generate-package-search-index directory) > + "Generate under DIRECTORY a Xapian index of all the available packages." > + (define db-path > + (string-append directory %package-search-index)) > + > + (mkdir-p (dirname db-path)) > + (call-with-writable-database db-path > + (lambda (db) > + (fold-packages (lambda (package _) > + (let* ((idterm (string-append "Q" (package-name package))) > + (doc (make-document #:data (string-trim-right > + (call-with-output-string > + (cut package->recutils package <>)) > + #\newline) > + #:terms `((,idterm . 0)))) > + (term-generator (make-term-generator #:stem (make-stem "en") > + #:document doc))) > + (for-each (match-lambda > + ((field . weight) > + (match (field package) > + ((? string? str) > + (index-text! term-generator str > + #:wdf-increment weight)) > + ((lst ...) > + (for-each (cut index-text! term-generator <> > + #:wdf-increment weight) > + lst))) > + (replace-document! db idterm doc))) > + %package-metrics))) > + #f))) > + > + db-path) If I understand correctly, the index is stored with a weight coming from '%package-metrics', right? Well, I am not convinced it is the correct way but I have not tried by myself yet. :-)