From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:39489) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBN0V-0002j5-Ur for guix-patches@gnu.org; Mon, 09 Mar 2020 14:20:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBN0U-0002f6-TP for guix-patches@gnu.org; Mon, 09 Mar 2020 14:20:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45474) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jBN0U-0002ee-Pe for guix-patches@gnu.org; Mon, 09 Mar 2020 14:20:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jBN0U-0004PM-KN for guix-patches@gnu.org; Mon, 09 Mar 2020 14:20:02 -0400 Subject: [bug#39258] [PATCH v2 2/3] gnu: Generate Xapian package search index. Resent-Message-ID: MIME-Version: 1.0 References: <20200307133116.11443-1-arunisaac@systemreboot.net> <20200307133116.11443-3-arunisaac@systemreboot.net> In-Reply-To: <20200307133116.11443-3-arunisaac@systemreboot.net> From: zimoun Date: Mon, 9 Mar 2020 19:19:27 +0100 Message-ID: Content-Type: text/plain; charset="UTF-8" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Arun Isaac Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Pierre Neidhardt , 39258@debbugs.gnu.org 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. :-)