blob: 364dfb5e392f3685a748016853b8331a30534153 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
;;; jao-recoll.el --- Utilities to use recoll -*- lexical-binding: t; -*-
;; Copyright (C) 2025 Jose Antonio Ortega Ruiz
;; Author: Jose Antonio Ortega Ruiz <mail@jao.io>
;; Keywords: mail, text
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Notably, a half-backed backend for Gnus
;;; Code:
(require 'gnus-search)
(defclass gnus-search-recoll (gnus-search-indexed)
((separator :type string :initform ".")
(program :initform "recoll")
(raw-queries-p :initform t)))
(cl-defmethod gnus-search-indexed-extract ((_engine gnus-search-recoll))
(prog1 (and (looking-at "^file://\\(.+\\)$") (list (match-string 1) 100))
(forward-line 1)))
(cl-defmethod gnus-search-transform-expression ((_engine gnus-search-recoll)
expr)
expr)
(cl-defmethod gnus-search-indexed-search-command ((engine gnus-search-recoll)
(qstring string)
query
&optional groups)
(let* ((subdir (slot-value engine 'remove-prefix))
(sep (slot-value engine 'separator))
(gdirs (mapcar (lambda (g)
(let ((g (gnus-group-short-name g)))
(replace-regexp-in-string "\\." sep g)))
(or groups
(and (not (string= "" subdir)) (list subdir)))))
(dirsq (and gdirs
(concat "("
(mapconcat (lambda (d) (format "dir:%s" d))
gdirs " OR ")
")")))
(qstring (if (string-prefix-p "id:" qstring)
(replace-regexp-in-string "<\\|>" "\"" qstring)
qstring))
(qstring (if (cdr (assoc 'thread query))
(concat qstring " OR "
(replace-regexp-in-string "id:\"" "ref:\""
qstring))
qstring))
(qstring (replace-regexp-in-string " or " " OR " qstring))
(qstring (replace-regexp-in-string " and " " AND " qstring))
(q (format "mime:message %s (%s)" dirsq qstring)))
;; (message "query is: %s -- %S" q query)
`("-b" "-t" "-q" ,q)))
(defun jao-recoll-gnus-search-engine (dir)
`(nnml "" (gnus-search-engine gnus-search-recoll (remove-prefix ,dir))))
(provide 'jao-recoll)
;;; jao-recoll.el ends here
|