From patchwork Sat Mar 7 13:31:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arun Isaac X-Patchwork-Id: 20560 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 7A7C527BBEA; Sat, 7 Mar 2020 13:32:12 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id ED3B127BBEA for ; Sat, 7 Mar 2020 13:32:11 +0000 (GMT) Received: from localhost ([::1]:48826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAZYp-0001zc-C5 for patchwork@mira.cbaines.net; Sat, 07 Mar 2020 08:32:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35191) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAZYh-0001zS-Q8 for guix-patches@gnu.org; Sat, 07 Mar 2020 08:32:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAZYg-00049y-PD for guix-patches@gnu.org; Sat, 07 Mar 2020 08:32:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:40435) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jAZYg-00049m-MO for guix-patches@gnu.org; Sat, 07 Mar 2020 08:32:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jAZYg-0002sA-Hh for guix-patches@gnu.org; Sat, 07 Mar 2020 08:32:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#39258] [PATCH v2 1/3] build-self: Add guile-xapian to Guix dependencies. Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 07 Mar 2020 13:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39258 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 39258@debbugs.gnu.org Cc: Arun Isaac , mail@ambrevar.xyz, ludo@gnu.org, zimon.toutoune@gmail.com Received: via spool by 39258-submit@debbugs.gnu.org id=B39258.158358789910993 (code B ref 39258); Sat, 07 Mar 2020 13:32:02 +0000 Received: (at 39258) by debbugs.gnu.org; 7 Mar 2020 13:31:39 +0000 Received: from localhost ([127.0.0.1]:46402 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jAZYJ-0002rA-D1 for submit@debbugs.gnu.org; Sat, 07 Mar 2020 08:31:39 -0500 Received: from mugam.systemreboot.net ([139.59.75.54]:51814) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jAZYF-0002ql-1D for 39258@debbugs.gnu.org; Sat, 07 Mar 2020 08:31:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=systemreboot.net; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=zoaipT+rHGiH/JjrvRyY6G1OW4AJNxxgAqR1qpbWqoU=; b=S4ZjSUcaRrynOK21fHLL8HOi78 eWcU7+KyrUAk2vQQlnyQiacbpzStQf2nu6Yss1e5f/8jzTKHHc+4FcbAgCHf4Zzh38NuZ6W57HEhF DU/pipBNn0JM4YxvdspB41b7Vk1+iDA3Ri9elgnf0j/VlSGVhhTfDlttYybMIl8ZtF9M=; Received: from [192.168.2.1] (helo=steel.lan) by systemreboot.net with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1jAZY7-002bX3-If; Sat, 07 Mar 2020 19:01:27 +0530 From: Arun Isaac Date: Sat, 7 Mar 2020 19:01:14 +0530 Message-Id: <20200307133116.11443-2-arunisaac@systemreboot.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200307133116.11443-1-arunisaac@systemreboot.net> References: <20200307133116.11443-1-arunisaac@systemreboot.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * build-aux/build-self.scm (build-program): Import fake guile-xapian module. * guix/self.scm (compiled-guix): Add guile-xapian to Guix dependencies. --- build-aux/build-self.scm | 11 +++++++++++ guix/self.scm | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/build-aux/build-self.scm b/build-aux/build-self.scm index f2e785b7f1..05d0353ccf 100644 --- a/build-aux/build-self.scm +++ b/build-aux/build-self.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2014, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès +;;; Copyright © 2020 Arun Isaac ;;; ;;; This file is part of GNU Guix. ;;; @@ -261,6 +262,10 @@ interface (FFI) of Guile.") #~(define-module (gcrypt hash) #:export (sha1 sha256)))) + (define fake-xapian-hash + ;; Fake (xapian xapian) module; see below. + (scheme-file "xapian.scm" #~(define-module (xapian xapian)))) + (define fake-git (scheme-file "git.scm" #~(define-module (git)))) @@ -273,6 +278,12 @@ interface (FFI) of Guile.") ;; adjust %LOAD-PATH later on. ((gcrypt hash) => ,fake-gcrypt-hash) + ;; To avoid relying on 'with-extensions', which was + ;; introduced in 0.15.0, provide a fake (xapian + ;; xapian) just so that we can build modules, and + ;; adjust %LOAD-PATH later on. + ((xapian xapian) => ,fake-xapian-hash) + ;; (guix git-download) depends on (git) but only ;; for peripheral functionality. Provide a dummy ;; (git) to placate it. diff --git a/guix/self.scm b/guix/self.scm index 6b633f9bc0..a4f40574d1 100644 --- a/guix/self.scm +++ b/guix/self.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017, 2018, 2019, 2020 Ludovic Courtès +;;; Copyright © 2020 Arun Isaac ;;; ;;; This file is part of GNU Guix. ;;; @@ -54,6 +55,7 @@ ("guile-git" (ref '(gnu packages guile) 'guile3.0-git)) ("guile-sqlite3" (ref '(gnu packages guile) 'guile3.0-sqlite3)) ("guile-gcrypt" (ref '(gnu packages gnupg) 'guile3.0-gcrypt)) + ("guile-xapian" (ref '(gnu packages guile-xyz) 'guile3.0-xapian)) ("gnutls" (ref '(gnu packages tls) 'guile3.0-gnutls)) ("zlib" (ref '(gnu packages compression) 'zlib)) ("lzlib" (ref '(gnu packages compression) 'lzlib)) @@ -682,6 +684,9 @@ Info manual." (define guile-gcrypt (specification->package "guile-gcrypt")) + (define guile-xapian + (specification->package "guile-xapian")) + (define gnutls (specification->package "gnutls")) @@ -690,7 +695,7 @@ Info manual." (cons (list "x" package) (package-transitive-propagated-inputs package))) (list guile-gcrypt gnutls guile-git guile-json - guile-ssh guile-sqlite3)) + guile-ssh guile-sqlite3 guile-xapian)) (((labels packages _ ...) ...) packages))) From patchwork Sat Mar 7 13:31:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arun Isaac X-Patchwork-Id: 20561 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3D04D27BBEB; Sat, 7 Mar 2020 13:32:14 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 7DCEE27BBE4 for ; Sat, 7 Mar 2020 13:32:13 +0000 (GMT) Received: from localhost ([::1]:48830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAZYr-000210-11 for patchwork@mira.cbaines.net; Sat, 07 Mar 2020 08:32:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35209) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAZYi-0001zT-Gn for guix-patches@gnu.org; Sat, 07 Mar 2020 08:32:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAZYh-0004B2-5p for guix-patches@gnu.org; Sat, 07 Mar 2020 08:32:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:40436) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jAZYh-0004AT-2S for guix-patches@gnu.org; Sat, 07 Mar 2020 08:32:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jAZYg-0002sH-Vy for guix-patches@gnu.org; Sat, 07 Mar 2020 08:32:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#39258] [PATCH v2 2/3] gnu: Generate Xapian package search index. Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 07 Mar 2020 13:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39258 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 39258@debbugs.gnu.org Cc: Arun Isaac , mail@ambrevar.xyz, ludo@gnu.org, zimon.toutoune@gmail.com Received: via spool by 39258-submit@debbugs.gnu.org id=B39258.158358790111003 (code B ref 39258); Sat, 07 Mar 2020 13:32:02 +0000 Received: (at 39258) by debbugs.gnu.org; 7 Mar 2020 13:31:41 +0000 Received: from localhost ([127.0.0.1]:46404 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jAZYK-0002rN-OO for submit@debbugs.gnu.org; Sat, 07 Mar 2020 08:31:41 -0500 Received: from mugam.systemreboot.net ([139.59.75.54]:51824) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jAZYH-0002qq-OF for 39258@debbugs.gnu.org; Sat, 07 Mar 2020 08:31:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=systemreboot.net; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=BO+LbygYA4iKXddmWm8457vAuodCLPfBfiwe5W17c6M=; b=MtA/wa/NxZFTULsqh2b0RUArsg eWJ8ayXVAleRdtv5YcwqDpKcHGZV8bzODSDyObaCalmWNXCnVkMFecRhWdzHoL8Pxrwi2BdySGBKd 8sqvmZYuDRD9FLz56Eaat2gI5t3cZH9VoZo1GsZWOfWqlf6TXtnp6Km/j0CklKgQuark=; Received: from [192.168.2.1] (helo=steel.lan) by systemreboot.net with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1jAZY7-002bX3-Om; Sat, 07 Mar 2020 19:01:27 +0530 From: Arun Isaac Date: Sat, 7 Mar 2020 19:01:15 +0530 Message-Id: <20200307133116.11443-3-arunisaac@systemreboot.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200307133116.11443-1-arunisaac@systemreboot.net> References: <20200307133116.11443-1-arunisaac@systemreboot.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/ui.scm: Export %package-metrics. * gnu/packages.scm (%package-search-index): New variable. (generate-package-search-index): New function. * guix/channels.scm (package-search-index): New function. (%channel-profile-hooks): Add package-search-index. --- gnu/packages.scm | 42 +++++++++++++++++++++++++++++++++++++++++- guix/channels.scm | 34 +++++++++++++++++++++++++++++++++- guix/ui.scm | 2 ++ 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/gnu/packages.scm b/gnu/packages.scm index d22c992bb1..c8e221de68 100644 --- a/gnu/packages.scm +++ b/gnu/packages.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2014 Eric Bavier ;;; Copyright © 2016, 2017 Alex Kost ;;; Copyright © 2016 Mathieu Lirzin +;;; Copyright © 2020 Arun Isaac ;;; ;;; This file is part of GNU Guix. ;;; @@ -43,6 +44,7 @@ #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) #:use-module (srfi srfi-39) + #:use-module (xapian xapian) #:export (search-patch search-patches search-auxiliary-file @@ -64,7 +66,8 @@ specification->location specifications->manifest - generate-package-cache)) + generate-package-cache + generate-package-search-index)) ;;; Commentary: ;;; @@ -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) + (define %sigint-prompt ;; The prompt to jump to upon SIGINT. diff --git a/guix/channels.scm b/guix/channels.scm index f0261dc2da..c70c70938c 100644 --- a/guix/channels.scm +++ b/guix/channels.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2018, 2019, 2020 Ludovic Courtès ;;; Copyright © 2018 Ricardo Wurmus ;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen +;;; Copyright © 2020 Arun Isaac ;;; ;;; This file is part of GNU Guix. ;;; @@ -581,9 +582,40 @@ be used as a profile hook." (hook . package-cache)) #:local-build? #t))) +(define (package-search-index manifest) + "Build a package search index for the instance in MANIFEST. This is meant +to be used as a profile hook." + (mlet %store-monad ((profile (profile-derivation manifest + #:hooks '()))) + + (define build + #~(begin + (use-modules (gnu packages)) + + (if (defined? 'generate-package-search-index) + (begin + ;; Delegate package search index generation to the inferior. + (format (current-error-port) + "Generating package search index for '~a'...~%" + #$profile) + (generate-package-search-index #$output)) + (mkdir #$output)))) + + (gexp->derivation-in-inferior "guix-package-search-index" build + profile + + ;; If the Guix in PROFILE is too old and + ;; lacks 'guix repl', don't build the cache + ;; instead of failing. + #:silent-failure? #t + + #:properties '((type . profile-hook) + (hook . package-search-index)) + #:local-build? #t))) + (define %channel-profile-hooks ;; The default channel profile hooks. - (cons package-cache-file %default-profile-hooks)) + (cons* package-cache-file package-search-index %default-profile-hooks)) (define (channel-instances->derivation instances) "Return the derivation of the profile containing INSTANCES, a list of diff --git a/guix/ui.scm b/guix/ui.scm index fbe2b70485..3bc82111a5 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -14,6 +14,7 @@ ;;; Copyright © 2019 Chris Marusich ;;; Copyright © 2019 Tobias Geerinckx-Rice ;;; Copyright © 2019 Simon Tournier +;;; Copyright © 2020 Arun Isaac ;;; ;;; This file is part of GNU Guix. ;;; @@ -120,6 +121,7 @@ relevance package-relevance display-search-results + %package-metrics with-profile-lock string->generations From patchwork Sat Mar 7 13:31:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arun Isaac X-Patchwork-Id: 20563 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3BC2827BBEA; Sat, 7 Mar 2020 13:32:20 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id A66FB27BBE4 for ; Sat, 7 Mar 2020 13:32:19 +0000 (GMT) Received: from localhost ([::1]:48840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAZYx-0002EF-8Q for patchwork@mira.cbaines.net; Sat, 07 Mar 2020 08:32:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35216) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAZYi-0001zX-Tz for guix-patches@gnu.org; Sat, 07 Mar 2020 08:32:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAZYh-0004C7-K3 for guix-patches@gnu.org; Sat, 07 Mar 2020 08:32:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:40437) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jAZYh-0004Bl-Gg for guix-patches@gnu.org; Sat, 07 Mar 2020 08:32:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jAZYh-0002sP-E0 for guix-patches@gnu.org; Sat, 07 Mar 2020 08:32:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#39258] [PATCH v2 3/3] gnu: Use Xapian index for package search. Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 07 Mar 2020 13:32:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39258 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 39258@debbugs.gnu.org Cc: Arun Isaac , mail@ambrevar.xyz, ludo@gnu.org, zimon.toutoune@gmail.com Received: via spool by 39258-submit@debbugs.gnu.org id=B39258.158358790111010 (code B ref 39258); Sat, 07 Mar 2020 13:32:03 +0000 Received: (at 39258) by debbugs.gnu.org; 7 Mar 2020 13:31:41 +0000 Received: from localhost ([127.0.0.1]:46406 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jAZYL-0002rQ-68 for submit@debbugs.gnu.org; Sat, 07 Mar 2020 08:31:41 -0500 Received: from mugam.systemreboot.net ([139.59.75.54]:51828) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jAZYI-0002qw-Dh for 39258@debbugs.gnu.org; Sat, 07 Mar 2020 08:31:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=systemreboot.net; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=KfB6VaHDc8ym5DA2S5eEW2qMotN8Qo5p82aaen+WX80=; b=m+HoWXLQ5NxJ6zyb8LojJ9A48C uKIVm/VZUYfDwgOcq0wUXVAu3SE9Dl3CJiF+K+r1ez3cSqmOl3oV/maRZc0pyAraYAc8LbE87RKY8 AeAAIpGeI+M1jGJdNltf56QsQ7SIpcIKlUgCJ1f4Ov+78wiK/5ExOGJggNrjiLfDlEdY=; Received: from [192.168.2.1] (helo=steel.lan) by systemreboot.net with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1jAZY7-002bX3-VK; Sat, 07 Mar 2020 19:01:28 +0530 From: Arun Isaac Date: Sat, 7 Mar 2020 19:01:16 +0530 Message-Id: <20200307133116.11443-4-arunisaac@systemreboot.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200307133116.11443-1-arunisaac@systemreboot.net> References: <20200307133116.11443-1-arunisaac@systemreboot.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/packages.scm (search-package-index): New function. * guix/ui.scm (display-package-search-results): New function. * guix/scripts/package.scm (process-query): Search using the Xapian package index if current profile is available. Else, search using regexps. --- gnu/packages.scm | 22 +++++++++++++++++++++- guix/scripts/package.scm | 7 +++++-- guix/ui.scm | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/gnu/packages.scm b/gnu/packages.scm index c8e221de68..3cbd7c63e3 100644 --- a/gnu/packages.scm +++ b/gnu/packages.scm @@ -67,7 +67,8 @@ specifications->manifest generate-package-cache - generate-package-search-index)) + generate-package-search-index + search-package-index)) ;;; Commentary: ;;; @@ -466,6 +467,25 @@ reducing the memory footprint." db-path) +(define (search-package-index profile query-string) + "Search Xapian index in PROFILE for packages matching the Xapian query +QUERY-STRING. Return a list of search result texts each corresponding to one +matching package." + (call-with-database (string-append profile %package-search-index) + (lambda (db) + (let ((query (parse-query query-string #:stemmer (make-stem "en")))) + (mset-fold (lambda (item result) + (let ((search-result-text + (call-with-output-string + (cut format <> "~a~%relevance: ~a~%~%" + (document-data (mset-item-document item)) + ;; Round score to one decimal place. + (/ (round (* 10 (mset-item-weight item))) 10))))) + (append result (list search-result-text)))) + '() + (enquire-mset (enquire db query) + #:maximum-items (database-document-count db))))))) + (define %sigint-prompt ;; The prompt to jump to upon SIGINT. diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index d2f4f1ccd3..91c975b168 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -7,6 +7,7 @@ ;;; Copyright © 2016 Benz Schenk ;;; Copyright © 2016 Chris Marusich ;;; Copyright © 2019 Tobias Geerinckx-Rice +;;; Copyright © 2020 Arun Isaac ;;; ;;; This file is part of GNU Guix. ;;; @@ -781,9 +782,11 @@ processed, #f otherwise." (_ #f)) opts)) (regexps (map (cut make-regexp* <> regexp/icase) patterns)) - (matches (find-packages-by-description regexps))) + (matches (if (current-profile) + (search-package-index (current-profile) (string-join patterns " ")) + (find-packages-by-description regexps)))) (leave-on-EPIPE - (display-search-results matches (current-output-port))) + (display-package-search-results matches (current-output-port))) #t)) (('show requested-name) diff --git a/guix/ui.scm b/guix/ui.scm index 3bc82111a5..163042054c 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -121,6 +121,7 @@ relevance package-relevance display-search-results + display-package-search-results %package-metrics with-profile-lock @@ -1490,6 +1491,40 @@ to view all the results.") (() #t)))) +(define* (display-package-search-results search-results port + #:key + (command "guix search")) + "Display SEARCH-RESULTS, a list of search result texts each corresponding to +one matching package. If PORT is a terminal, print at most a full screen of +results." + (define first-line + (port-line port)) + + (define max-rows + (and first-line (isatty? port) + (terminal-rows port))) + + (define (line-count str) + (string-count str #\newline)) + + (let loop ((search-results search-results)) + (match search-results + ((text rest ...) + (if (and (not (getenv "INSIDE_EMACS")) + max-rows + (> (port-line port) first-line) ;print at least one result + (> (+ 4 (line-count text) (port-line port)) + max-rows)) + (unless (null? rest) + (display-hint (format #f (G_ "Run @code{~a ... | less} \ +to view all the results.") + command))) + (begin + (display text port) + (loop rest)))) + (() + #t)))) + (define (string->generations str) "Return the list of generations matching a pattern in STR. This function