info-gnus-english
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nnir notmuch search on specific groups?


From: Eric Abrahamsen
Subject: Re: nnir notmuch search on specific groups?
Date: Sun, 21 Oct 2018 11:58:47 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Adam Sjøgren <asjo@koldfront.dk> writes:

> Eric writes:
>
>> I vaguely remember that I couldn't even make it work properly on the
>> command line, couldn't figure out why "folder" and "path" returned the
>> results they did.
>
> path:{folder} works for me, using notmuch on the command line.
>
> My email is in nnml format in various folders in ~/Mail/{folder}, and my
> .notmuch-config has:
>
>   [database]
>   path=/home/asjo/Mail
>
> Searching for "Adam" gives me a lot of results:
>
>   asjo@tullinup:~$ time notmuch search Adam | wc -l
>   32911
>
>   real    0m6.574s
>   user    0m5.016s
>   sys     0m1.577s
>
> If I limit the search using path:, I get less, so it looks like it
> works:
>
>   asjo@tullinup:~$ time notmuch search "Adam path:cron" | wc -l
>   507
>
>   real    0m0.148s
>   user    0m0.128s
>   sys     0m0.024s

Beats me what my problem was, then! But no matter.

>> But `nnir-run-notmuch' filters its results same as all the other search
>> routines, so I'm not sure why we can't do the filtering on group name,
>> after the fact. It has this:
>>
>>  ;; maybe limit results to matching groups.
>>  (when (or (not groupspec)
>>            (string-match groupspec dirnam))
>>    (nnir-add-result dirnam artno "" prefix server artlist)))))
>>
>> That should be usable for filtering, right?
>
> Yeah! I guess it could matter when the results are excluded,
> performance-wise, but in practise, I would guess it would be "fast
> enough"™ to do it post hoc.

Sure. It would be preferable to do it up front though!

This whole thing looks a little weird. The "groupspec" filter criteria
above is supposed to come from a "notmuch-group" query parameter (ie
nnir would promppt you for it), but as that parameter doesn't appear in
`nnir-engines', the prompt never happens, and we never get a "groupspec"
at all.

I don't see why we couldn't just use the GROUP argument. I think it
should be optional, because we can't always be sure the user doesn't
have some odd name transformation stuff going on, but for instance in
your case with nnml it seems like it ought to work fine.

Would you try this and see if it does what you'd expect?


(defun nnir-run-notmuch (query server &optional groups)
  "Run QUERY against notmuch.
Returns a vector of (group name, file name) pairs (also vectors,
actually).  If GROUPS is a list of group names, use them to
construct path: search terms."

  (save-excursion
    (let* ((qstring (cdr (assq 'query query)))
           (prefix (nnir-read-server-parm 'nnir-notmuch-remove-prefix server))
           artlist
           (article-pattern (if (string-match "\\`nnmaildir:"
                                              (gnus-group-server server))
                                ":[0-9]+"
                              "^[0-9]+$"))
           (groups (mapcar #'gnus-group-short-name groups))
           (pathquery (when groups
                        (mapconcat (lambda (g)
                                     (format " path:%s" g))
                                   groups " or")))
           artno dirnam filenam)

      (when (equal "" qstring)
        (error "notmuch: You didn't enter anything"))

      (set-buffer (get-buffer-create nnir-tmp-buffer))
      (erase-buffer)

      (if groups
          (message "Doing notmuch query %s on %s..."
                   qstring (mapconcat #'identity groups " "))
        (message "Doing notmuch query %s..." qstring))

      (when groups
        (setq qstring (concat qstring pathquery)))

      (let* ((cp-list `( ,nnir-notmuch-program
                         nil            ; input from /dev/null
                         t              ; output
                         nil            ; don't redisplay
                         "search"
                         "--format=text"
                         "--output=files"
                         ,@(nnir-read-server-parm 
'nnir-notmuch-additional-switches server)
                         ,qstring       ; the query, in notmuch format
                         ))
             (exitstatus
              (progn
                (message "%s args: %s" nnir-notmuch-program
                         (mapconcat #'identity (nthcdr 4 cp-list) " ")) ;; ???
                (apply #'call-process cp-list))))
        (unless (or (null exitstatus)
                    (zerop exitstatus))
          (nnheader-report 'nnir "Couldn't run notmuch: %s" exitstatus)
          ;; notmuch failure reason is in this buffer, show it if
          ;; the user wants it.
          (when (> gnus-verbose 6)
            (display-buffer nnir-tmp-buffer))))

      ;; The results are output in the format of:
      ;; absolute-path-name
      (goto-char (point-min))
      (while (not (eobp))
        (setq filenam (buffer-substring-no-properties (line-beginning-position)
                                                      (line-end-position))
              artno (file-name-nondirectory filenam)
              dirnam (file-name-directory filenam))
        (forward-line 1)

        ;; don't match directories
        (when (string-match article-pattern artno)
          (when (not (null dirnam))

            (nnir-add-result dirnam artno "" prefix server artlist))))

      (message "Massaging notmuch output...done")

      artlist)))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]