Subject: Re: [bug#39258] [PATCH 4/4] gnu: Use xapian index for package search.

From: Pierre Neidhardt <[email-masked]>
Date: Fri, 28 Feb 2020 09:11:31 +0100

Arun Isaac <[email-masked]> writes:

> @@ -453,6 +454,20 @@ reducing the memory footprint."
>  
>    db-path)
>  
> +(define (search-package-index profile querystring)

Maybe `query-string'?

>  
> --- a/guix/scripts/package.scm
> +++ b/guix/scripts/package.scm
> @@ -7,6 +7,7 @@
>  ;;; Copyright © 2016 Benz Schenk <[email-masked]>
>  ;;; Copyright © 2016 Chris Marusich <[email-masked]>
>  ;;; Copyright © 2019 Tobias Geerinckx-Rice <[email-masked]>
> +;;; Copyright © 2020 Arun Isaac <[email-masked]>
>  ;;;
>  ;;; This file is part of GNU Guix.
>  ;;;
> @@ -178,31 +179,40 @@ hooks\" run when building the profile."
>  ;;; Package specifications.
>  ;;;
>  
> -(define (find-packages-by-description regexps)
> +(define (find-packages-by-description patterns)
>    "Return a list of pairs: packages whose name, synopsis, description,
>  or output matches at least one of REGEXPS sorted by relevance, and its
>  non-zero relevance score."

Need to update the docstring.

> -  (let ((matches (fold-packages (lambda (package result)
> -                                  (if (package-superseded package)
> -                                      result
> -                                      (match (package-relevance package
> -                                                                regexps)
> -                                        ((? zero?)
> -                                         result)
> -                                        (score
> -                                         (cons (cons package score)
> -                                               result)))))
> -                                '())))
> -    (sort matches
> -          (lambda (m1 m2)
> -            (match m1
> -              ((package1 . score1)
> -               (match m2
> -                 ((package2 . score2)
> -                  (if (= score1 score2)
> -                      (string>? (package-full-name package1)
> -                                (package-full-name package2))
> -                      (> score1 score2))))))))))
> +  (define (regexp? str)
> +    (string-any
> +     (char-set #\. #\[ #\{ #\} #\( #\) #\\ #\* #\+ #\? #\| #\^ #\$)
> +     str))
> +
> +  (if (and (current-profile)
> +           (not (any regexp? patterns)))

I would not put characters like ".", "$", or "+" here, lest we mistake a
Xapian pattern for a regexp.

As you said, I don't think both are compatible without ambiguity
anyways, so we should probably drop regexp (or at least toggle them with
a command line argument).

-- 
Pierre Neidhardt
https://ambrevar.xyz/