Mercurial > emacs
annotate lisp/gnus/nnir.el @ 110637:494ea2fb03d7
Remove Emacs 21 stuff.
mm-util.el (mm-codepage-iso-8859-list, mm-charset-eval-alist, mm-mime-charset): Comment fix.
rfc2047.el (rfc2047-syntax-table): Comment fix.
utf7.el (utf7-utf-16-coding-system): Comment fix.
nnrss.el (nnrss-read-server-data, nnrss-read-group-data): Use `load' rather than `insert-file-contents' and `eval-region'.
pgg.el (pgg-run-at-time-1): Define it for XEmacs only; fix if/else construction.
time-date.el: No need to require cl for Emacs 21.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Wed, 29 Sep 2010 01:09:50 +0000 |
parents | 5e158658b471 |
children | 2b8ece636433 |
rev | line source |
---|---|
95610 | 1 ;;; nnir.el --- search mail with various search engines -*- coding: iso-8859-1 -*- |
2 | |
95616 | 3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, |
106815 | 4 ;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
95610 | 5 |
6 ;; Author: Kai Großjohann <grossjohann@ls6.cs.uni-dortmund.de> | |
7 ;; Swish-e and Swish++ backends by: | |
8 ;; Christoph Conrad <christoph.conrad@gmx.de>. | |
9 ;; IMAP backend by: Simon Josefsson <jas@pdc.kth.se>. | |
10 ;; IMAP search by: Torsten Hilbrich <torsten.hilbrich <at> gmx.net> | |
11 ;; IMAP search improved by Daniel Pittman <daniel@rimspace.net>. | |
12 ;; nnmaildir support for Swish++ and Namazu backends by: | |
13 ;; Justus Piater <Justus <at> Piater.name> | |
95616 | 14 ;; Keywords: news mail searching ir |
15 | |
16 ;; This file is part of GNU Emacs. | |
17 | |
18 ;; GNU Emacs is free software: you can redistribute it and/or modify | |
19 ;; it under the terms of the GNU General Public License as published by | |
20 ;; the Free Software Foundation, either version 3 of the License, or | |
21 ;; (at your option) any later version. | |
22 | |
23 ;; GNU Emacs is distributed in the hope that it will be useful, | |
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26 ;; GNU General Public License for more details. | |
27 | |
28 ;; You should have received a copy of the GNU General Public License | |
29 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
30 | |
31 ;;; Commentary: | |
95610 | 32 |
33 ;; TODO: Documentation in the Gnus manual | |
34 | |
35 ;; From: Reiner Steib | |
36 ;; Subject: Re: Including nnir.el | |
37 ;; Newsgroups: gmane.emacs.gnus.general | |
38 ;; Message-ID: <v9d5dnp6aq.fsf@marauder.physik.uni-ulm.de> | |
39 ;; Date: 2006-06-05 22:49:01 GMT | |
40 ;; | |
41 ;; On Sun, Jun 04 2006, Sascha Wilde wrote: | |
42 ;; | |
43 ;; > The one thing most hackers like to forget: Documentation. By now the | |
44 ;; > documentation is only in the comments at the head of the source, I | |
45 ;; > would use it as basis to cook up some minimal texinfo docs. | |
46 ;; > | |
47 ;; > Where in the existing gnus manual would this fit best? | |
48 | |
49 ;; Maybe (info "(gnus)Combined Groups") for a general description. | |
50 ;; `gnus-group-make-nnir-group' might be described in (info | |
51 ;; "(gnus)Foreign Groups") as well. | |
52 | |
53 | |
54 ;; The most recent version of this can always be fetched from the Gnus | |
107975
7d805250c222
Synch with Gnus trunk:
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
106815
diff
changeset
|
55 ;; repository. See http://www.gnus.org/ for more information. |
95610 | 56 |
57 ;; This code is still in the development stage but I'd like other | |
58 ;; people to have a look at it. Please do not hesitate to contact me | |
59 ;; with your ideas. | |
60 | |
61 ;; What does it do? Well, it allows you to index your mail using some | |
62 ;; search engine (freeWAIS-sf, swish-e and others -- see later), | |
63 ;; then type `G G' in the Group buffer and issue a query to the search | |
64 ;; engine. You will then get a buffer which shows all articles | |
65 ;; matching the query, sorted by Retrieval Status Value (score). | |
66 | |
67 ;; When looking at the retrieval result (in the Summary buffer) you | |
68 ;; can type `G T' (aka M-x gnus-summary-nnir-goto-thread RET) on an | |
69 ;; article. You will be teleported into the group this article came | |
70 ;; from, showing the thread this article is part of. (See below for | |
71 ;; restrictions.) | |
72 | |
73 ;; The Lisp installation is simple: just put this file on your | |
74 ;; load-path, byte-compile it, and load it from ~/.gnus or something. | |
75 ;; This will install a new command `G G' in your Group buffer for | |
76 ;; searching your mail. Note that you also need to configure a number | |
77 ;; of variables, as described below. | |
78 | |
79 ;; Restrictions: | |
80 ;; | |
81 ;; * If you don't use HyREX as your search engine, this expects that | |
82 ;; you use nnml or another one-file-per-message backend, because the | |
83 ;; others doesn't support nnfolder. | |
84 ;; * It can only search the mail backend's which are supported by one | |
85 ;; search engine, because of different query languages. | |
86 ;; * There are restrictions to the Wais setup. | |
87 ;; * There are restrictions to the imap setup. | |
88 ;; * gnus-summary-nnir-goto-thread: Fetches whole group first, before | |
89 ;; limiting to the right articles. This is much too slow, of | |
90 ;; course. May issue a query for number of articles to fetch; you | |
91 ;; must accept the default of all articles at this point or things | |
92 ;; may break. | |
93 | |
94 ;; The Lisp setup involves setting a few variables and setting up the | |
95 ;; search engine. You can define the variables in the server definition | |
96 ;; like this : | |
97 ;; (setq gnus-secondary-select-methods '( | |
98 ;; (nnimap "" (nnimap-address "localhost") | |
99 ;; (nnir-search-engine hyrex) | |
100 ;; (nnir-hyrex-additional-switches ("-d" "ddl-nnimap.xml")) | |
101 ;; ))) | |
102 ;; Or you can define the global ones. The variables set in the mailer- | |
103 ;; definition will be used first. | |
104 ;; The variable to set is `nnir-search-engine'. Choose one of the engines | |
105 ;; listed in `nnir-engines'. (Actually `nnir-engines' is an alist, | |
106 ;; type `C-h v nnir-engines RET' for more information; this includes | |
107 ;; examples for setting `nnir-search-engine', too.) | |
108 ;; | |
109 ;; The variable nnir-mail-backend isn't used anymore. | |
110 ;; | |
111 | |
112 ;; You must also set up a search engine. I'll tell you about the two | |
113 ;; search engines currently supported: | |
114 | |
115 ;; 1. freeWAIS-sf | |
116 ;; | |
117 ;; As always with freeWAIS-sf, you need a so-called `format file'. I | |
118 ;; use the following file: | |
119 ;; | |
120 ;; ,----- | |
121 ;; | # Kai's format file for freeWAIS-sf for indexing mails. | |
122 ;; | # Each mail is in a file, much like the MH format. | |
123 ;; | | |
124 ;; | # Document separator should never match -- each file is a document. | |
125 ;; | record-sep: /^@this regex should never match@$/ | |
126 ;; | | |
127 ;; | # Searchable fields specification. | |
128 ;; | | |
129 ;; | region: /^[sS]ubject:/ /^[sS]ubject: */ | |
130 ;; | subject "Subject header" stemming TEXT BOTH | |
131 ;; | end: /^[^ \t]/ | |
132 ;; | | |
133 ;; | region: /^([tT][oO]|[cC][cC]):/ /^([tT][oO]|[cC][cC]): */ | |
134 ;; | to "To and Cc headers" SOUNDEX BOTH | |
135 ;; | end: /^[^ \t]/ | |
136 ;; | | |
137 ;; | region: /^[fF][rR][oO][mM]:/ /^[fF][rR][oO][mM]: */ | |
138 ;; | from "From header" SOUNDEX BOTH | |
139 ;; | end: /^[^ \t]/ | |
140 ;; | | |
141 ;; | region: /^$/ | |
142 ;; | stemming TEXT GLOBAL | |
143 ;; | end: /^@this regex should never match@$/ | |
144 ;; `----- | |
145 ;; | |
146 ;; 1998-07-22: waisindex would dump core on me for large articles with | |
147 ;; the above settings. I used /^$/ as the end regex for the global | |
148 ;; field. That seemed to work okay. | |
149 | |
150 ;; There is a Perl module called `WAIS.pm' which is available from | |
151 ;; CPAN as well as ls6-ftp.cs.uni-dortmund.de:/pub/wais/Perl. This | |
152 ;; module comes with a nifty tool called `makedb', which I use for | |
153 ;; indexing. Here's my `makedb.conf': | |
154 ;; | |
155 ;; ,----- | |
156 ;; | # Config file for makedb | |
157 ;; | | |
158 ;; | # Global options | |
159 ;; | waisindex = /usr/local/bin/waisindex | |
160 ;; | wais_opt = -stem -t fields | |
161 ;; | # `-stem' option necessary when `stemming' is specified for the | |
162 ;; | # global field in the *.fmt file | |
163 ;; | | |
164 ;; | # Own variables | |
165 ;; | homedir = /home/kai | |
166 ;; | | |
167 ;; | # The mail database. | |
168 ;; | database = mail | |
169 ;; | files = `find $homedir/Mail -name \*[0-9] -print` | |
170 ;; | dbdir = $homedir/.wais | |
171 ;; | limit = 100 | |
172 ;; `----- | |
173 ;; | |
174 ;; The Lisp setup involves the `nnir-wais-*' variables. The most | |
175 ;; difficult to understand variable is probably | |
176 ;; `nnir-wais-remove-prefix'. Here's what it does: the output of | |
177 ;; `waissearch' basically contains the file name and the (full) | |
178 ;; directory name. As Gnus works with group names rather than | |
179 ;; directory names, the directory name is transformed into a group | |
180 ;; name as follows: first, a prefix is removed from the (full) | |
181 ;; directory name, then all `/' are replaced with `.'. The variable | |
182 ;; `nnir-wais-remove-prefix' should contain a regex matching exactly | |
183 ;; this prefix. It defaults to `$HOME/Mail/' (note the trailing | |
184 ;; slash). | |
185 | |
186 ;; 2. Namazu | |
187 ;; | |
188 ;; The Namazu backend requires you to have one directory containing all | |
189 ;; index files, this is controlled by the `nnir-namazu-index-directory' | |
190 ;; variable. To function the `nnir-namazu-remove-prefix' variable must | |
191 ;; also be correct, see the documentation for `nnir-wais-remove-prefix' | |
192 ;; above. | |
193 ;; | |
194 ;; It is particularly important not to pass any any switches to namazu | |
195 ;; that will change the output format. Good switches to use include | |
196 ;; `--sort', `--ascending', `--early' and `--late'. Refer to the Namazu | |
197 ;; documentation for further information on valid switches. | |
198 ;; | |
199 ;; To index my mail with the `mknmz' program I use the following | |
200 ;; configuration file: | |
201 ;; | |
202 ;; ,---- | |
203 ;; | package conf; # Don't remove this line! | |
204 ;; | | |
205 ;; | # Paths which will not be indexed. Don't use `^' or `$' anchors. | |
206 ;; | $EXCLUDE_PATH = "spam|sent"; | |
207 ;; | | |
208 ;; | # Header fields which should be searchable. case-insensitive | |
209 ;; | $REMAIN_HEADER = "from|date|message-id|subject"; | |
210 ;; | | |
211 ;; | # Searchable fields. case-insensitive | |
212 ;; | $SEARCH_FIELD = "from|date|message-id|subject"; | |
213 ;; | | |
214 ;; | # The max length of a word. | |
215 ;; | $WORD_LENG_MAX = 128; | |
216 ;; | | |
217 ;; | # The max length of a field. | |
218 ;; | $MAX_FIELD_LENGTH = 256; | |
219 ;; `---- | |
220 ;; | |
221 ;; My mail is stored in the directories ~/Mail/mail/, ~/Mail/lists/ and | |
222 ;; ~/Mail/archive/, so to index them I go to the directory set in | |
223 ;; `nnir-namazu-index-directory' and issue the following command. | |
224 ;; | |
225 ;; mknmz --mailnews ~/Mail/archive/ ~/Mail/mail/ ~/Mail/lists/ | |
226 ;; | |
227 ;; For maximum searching efficiency I have a cron job set to run this | |
228 ;; command every four hours. | |
229 | |
230 ;; 3. HyREX | |
231 ;; | |
232 ;; The HyREX backend requires you to have one directory from where all | |
233 ;; your relative paths are to, if you use them. This directory must be | |
234 ;; set in the `nnir-hyrex-index-directory' variable, which defaults to | |
235 ;; your home directory. You must also pass the base, class and | |
236 ;; directory options or simply your dll to the `nnir-hyrex-programm' by | |
237 ;; setting the `nnir-hyrex-additional-switches' variable accordently. | |
238 ;; To function the `nnir-hyrex-remove-prefix' variable must also be | |
239 ;; correct, see the documentation for `nnir-wais-remove-prefix' above. | |
240 | |
241 ;; 4. find-grep | |
242 ;; | |
243 ;; The find-grep engine simply runs find(1) to locate eligible | |
244 ;; articles and searches them with grep(1). This, of course, is much | |
245 ;; slower than using a proper search engine but OTOH doesn't require | |
246 ;; maintenance of an index and is still faster than using any built-in | |
247 ;; means for searching. The method specification of the server to | |
248 ;; search must include a directory for this engine to work (E.g., | |
249 ;; `nnml-directory'). The tools must be POSIX compliant. GNU Find | |
250 ;; prior to version 4.2.12 (4.2.26 on Linux due to incorrect ARG_MAX | |
251 ;; handling) does not work. | |
252 ;; ,---- | |
253 ;; | ;; find-grep configuration for searching the Gnus Cache | |
254 ;; | | |
255 ;; | (nnml "cache" | |
256 ;; | (nnml-get-new-mail nil) | |
257 ;; | (nnir-search-engine find-grep) | |
258 ;; | (nnml-directory "~/News/cache/") | |
259 ;; | (nnml-active-file "~/News/cache/active")) | |
260 ;; `---- | |
261 | |
262 ;; Developer information: | |
263 | |
264 ;; I have tried to make the code expandable. Basically, it is divided | |
265 ;; into two layers. The upper layer is somewhat like the `nnvirtual' | |
110100
8f51744211eb
Remove nndb, nnkiboze and related code.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107978
diff
changeset
|
266 ;; backend: given a specification of what articles to show from |
8f51744211eb
Remove nndb, nnkiboze and related code.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107978
diff
changeset
|
267 ;; another backend, it creates a group containing exactly those |
8f51744211eb
Remove nndb, nnkiboze and related code.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107978
diff
changeset
|
268 ;; articles. The lower layer issues a query to a search engine and |
8f51744211eb
Remove nndb, nnkiboze and related code.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
107978
diff
changeset
|
269 ;; produces such a specification of what articles to show from the |
95610 | 270 ;; other backend. |
271 | |
272 ;; The interface between the two layers consists of the single | |
273 ;; function `nnir-run-query', which just selects the appropriate | |
274 ;; function for the search engine one is using. The input to | |
275 ;; `nnir-run-query' is a string, representing the query as input by | |
276 ;; the user. The output of `nnir-run-query' is supposed to be a | |
277 ;; vector, each element of which should in turn be a three-element | |
278 ;; vector. The first element should be full group name of the article, | |
279 ;; the second element should be the article number, and the third | |
280 ;; element should be the Retrieval Status Value (RSV) as returned from | |
281 ;; the search engine. An RSV is the score assigned to the document by | |
282 ;; the search engine. For Boolean search engines, the | |
283 ;; RSV is always 1000 (or 1 or 100, or whatever you like). | |
284 | |
285 ;; The sorting order of the articles in the summary buffer created by | |
286 ;; nnir is based on the order of the articles in the above mentioned | |
287 ;; vector, so that's where you can do the sorting you'd like. Maybe | |
288 ;; it would be nice to have a way of displaying the search result | |
289 ;; sorted differently? | |
290 | |
291 ;; So what do you need to do when you want to add another search | |
292 ;; engine? You write a function that executes the query. Temporary | |
293 ;; data from the search engine can be put in `nnir-tmp-buffer'. This | |
294 ;; function should return the list of articles as a vector, as | |
295 ;; described above. Then, you need to register this backend in | |
296 ;; `nnir-engines'. Then, users can choose the backend by setting | |
297 ;; `nnir-search-engine'. | |
298 | |
299 ;; Todo, or future ideas: | |
300 | |
301 ;; * It should be possible to restrict search to certain groups. | |
302 ;; | |
303 ;; * There is currently no error checking. | |
304 ;; | |
305 ;; * The summary buffer display is currently really ugly, with all the | |
306 ;; added information in the subjects. How could I make this | |
307 ;; prettier? | |
308 ;; | |
309 ;; * A function which can be called from an nnir summary buffer which | |
310 ;; teleports you into the group the current article came from and | |
311 ;; shows you the whole thread this article is part of. | |
312 ;; Implementation suggestions? | |
313 ;; (1998-07-24: There is now a preliminary implementation, but | |
314 ;; it is much too slow and quite fragile.) | |
315 ;; | |
316 ;; * Support other mail backends. In particular, probably quite a few | |
317 ;; people use nnfolder. How would one go about searching nnfolders | |
318 ;; and producing the right data needed? The group name and the RSV | |
319 ;; are simple, but what about the article number? | |
320 ;; - The article number is encoded in the `X-Gnus-Article-Number' | |
321 ;; header of each mail. | |
322 ;; - The HyREX engine supports nnfolder. | |
323 ;; | |
324 ;; * Support compressed mail files. Probably, just stripping off the | |
325 ;; `.gz' or `.Z' file name extension is sufficient. | |
326 ;; | |
327 ;; * At least for imap, the query is performed twice. | |
328 ;; | |
329 | |
330 ;; Have you got other ideas? | |
331 | |
332 ;;; Setup Code: | |
333 | |
334 (require 'nnoo) | |
335 (require 'gnus-group) | |
336 (require 'gnus-sum) | |
337 (require 'message) | |
338 (require 'gnus-util) | |
104584
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
339 (eval-when-compile |
95610 | 340 (require 'cl)) |
341 | |
342 (nnoo-declare nnir) | |
343 (nnoo-define-basics nnir) | |
344 | |
345 (gnus-declare-backend "nnir" 'mail) | |
346 | |
347 (defvar nnir-imap-search-field "TEXT" | |
110569
5e158658b471
nnir.el (nnir-run-imap): Allow sending IMAP search patterns directly.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110517
diff
changeset
|
348 "The IMAP search item when doing an nnir search. To use raw |
5e158658b471
nnir.el (nnir-run-imap): Allow sending IMAP search patterns directly.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110517
diff
changeset
|
349 imap queries by default set this to \"\"") |
95610 | 350 |
351 (defvar nnir-imap-search-arguments | |
352 '(("Whole message" . "TEXT") | |
353 ("Subject" . "SUBJECT") | |
354 ("To" . "TO") | |
355 ("From" . "FROM") | |
110569
5e158658b471
nnir.el (nnir-run-imap): Allow sending IMAP search patterns directly.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110517
diff
changeset
|
356 ("Head" . "HEADER \"%s\"") |
5e158658b471
nnir.el (nnir-run-imap): Allow sending IMAP search patterns directly.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110517
diff
changeset
|
357 (nil . "")) |
95610 | 358 "Mapping from user readable strings to IMAP search items for use in nnir") |
359 | |
360 (defvar nnir-imap-search-argument-history () | |
361 "The history for querying search options in nnir") | |
362 | |
107473 | 363 (defvar nnir-get-article-nov-override-function nil |
364 "If non-nil, a function that will be passed each search result. This | |
365 should return a message's headers in NOV format. | |
366 | |
367 If this variable is nil, or if the provided function returns nil for a search | |
368 result, `gnus-retrieve-headers' will be called instead.") | |
369 | |
370 | |
95610 | 371 ;;; Developer Extension Variable: |
372 | |
373 (defvar nnir-engines | |
374 `((wais nnir-run-waissearch | |
375 ()) | |
376 (imap nnir-run-imap | |
95616 | 377 ((criteria |
95610 | 378 "Search in: " ; Prompt |
379 ,nnir-imap-search-arguments ; alist for completing | |
380 nil ; no filtering | |
381 nil ; allow any user input | |
382 nil ; initial value | |
383 nnir-imap-search-argument-history ; the history to use | |
384 ,nnir-imap-search-field ; default | |
385 ))) | |
386 (swish++ nnir-run-swish++ | |
387 ((group . "Group spec: "))) | |
388 (swish-e nnir-run-swish-e | |
389 ((group . "Group spec: "))) | |
390 (namazu nnir-run-namazu | |
391 ()) | |
392 (hyrex nnir-run-hyrex | |
393 ((group . "Group spec: "))) | |
394 (find-grep nnir-run-find-grep | |
395 ((grep-options . "Grep options: ")))) | |
396 "Alist of supported search engines. | |
397 Each element in the alist is a three-element list (ENGINE FUNCTION ARGS). | |
398 ENGINE is a symbol designating the searching engine. FUNCTION is also | |
399 a symbol, giving the function that does the search. The third element | |
400 ARGS is a list of cons pairs (PARAM . PROMPT). When issuing a query, | |
401 the FUNCTION will issue a query for each of the PARAMs, using PROMPT. | |
402 | |
403 The value of `nnir-search-engine' must be one of the ENGINE symbols. | |
404 For example, use the following line for searching using freeWAIS-sf: | |
405 (setq nnir-search-engine 'wais) | |
406 Use the following line if you read your mail via IMAP and your IMAP | |
407 server supports searching: | |
408 (setq nnir-search-engine 'imap) | |
409 Note that you have to set additional variables for most backends. For | |
410 example, the `wais' backend needs the variables `nnir-wais-program', | |
411 `nnir-wais-database' and `nnir-wais-remove-prefix'. | |
412 | |
413 Add an entry here when adding a new search engine.") | |
414 | |
415 ;;; User Customizable Variables: | |
416 | |
417 (defgroup nnir nil | |
418 "Search nnmh and nnml groups in Gnus with swish-e, freeWAIS-sf, or EWS." | |
419 :group 'gnus) | |
420 | |
421 ;; Mail backend. | |
422 | |
423 ;; TODO: | |
424 ;; If `nil', use server parameters to find out which server to search. CCC | |
425 ;; | |
426 (defcustom nnir-mail-backend '(nnml "") | |
427 "*Specifies which backend should be searched. | |
428 More precisely, this is used to determine from which backend to fetch the | |
429 messages found. | |
430 | |
431 This must be equal to an existing server, so maybe it is best to use | |
432 something like the following: | |
433 (setq nnir-mail-backend (nth 0 gnus-secondary-select-methods)) | |
434 The above line works fine if the mail backend you want to search is | |
435 the first element of gnus-secondary-select-methods (`nth' starts counting | |
436 at zero)." | |
437 :type '(sexp) | |
438 :group 'nnir) | |
439 | |
440 ;; Search engine to use. | |
441 | |
442 (defcustom nnir-search-engine 'wais | |
443 "*The search engine to use. Must be a symbol. | |
444 See `nnir-engines' for a list of supported engines, and for example | |
445 settings of `nnir-search-engine'." | |
446 :type '(sexp) | |
447 :group 'nnir) | |
448 | |
449 ;; freeWAIS-sf. | |
450 | |
451 (defcustom nnir-wais-program "waissearch" | |
452 "*Name of waissearch executable." | |
453 :type '(string) | |
454 :group 'nnir) | |
455 | |
456 (defcustom nnir-wais-database (expand-file-name "~/.wais/mail") | |
457 "*Name of Wais database containing the mail. | |
458 | |
459 Note that this should be a file name without extension. For example, | |
460 if you have a file /home/john/.wais/mail.fmt, use this: | |
461 (setq nnir-wais-database \"/home/john/.wais/mail\") | |
462 The string given here is passed to `waissearch -d' as-is." | |
463 :type '(file) | |
464 :group 'nnir) | |
465 | |
466 (defcustom nnir-wais-remove-prefix (concat (getenv "HOME") "/Mail/") | |
467 "*The prefix to remove from each directory name returned by waissearch | |
468 in order to get a group name (albeit with / instead of .). This is a | |
469 regular expression. | |
470 | |
471 For example, suppose that Wais returns file names such as | |
472 \"/home/john/Mail/mail/misc/42\". For this example, use the following | |
473 setting: (setq nnir-wais-remove-prefix \"/home/john/Mail/\") | |
474 Note the trailing slash. Removing this prefix gives \"mail/misc/42\". | |
475 `nnir' knows to remove the \"/42\" and to replace \"/\" with \".\" to | |
476 arrive at the correct group name, \"mail.misc\"." | |
477 :type '(regexp) | |
478 :group 'nnir) | |
479 | |
480 (defcustom nnir-swish++-configuration-file | |
481 (expand-file-name "~/Mail/swish++.conf") | |
482 "*Configuration file for swish++." | |
483 :type '(file) | |
484 :group 'nnir) | |
485 | |
486 (defcustom nnir-swish++-program "search" | |
487 "*Name of swish++ search executable." | |
488 :type '(string) | |
489 :group 'nnir) | |
490 | |
491 (defcustom nnir-swish++-additional-switches '() | |
492 "*A list of strings, to be given as additional arguments to swish++. | |
493 | |
494 Note that this should be a list. Ie, do NOT use the following: | |
495 (setq nnir-swish++-additional-switches \"-i -w\") ; wrong | |
496 Instead, use this: | |
497 (setq nnir-swish++-additional-switches '(\"-i\" \"-w\"))" | |
498 :type '(repeat (string)) | |
499 :group 'nnir) | |
500 | |
501 (defcustom nnir-swish++-remove-prefix (concat (getenv "HOME") "/Mail/") | |
502 "*The prefix to remove from each file name returned by swish++ | |
503 in order to get a group name (albeit with / instead of .). This is a | |
504 regular expression. | |
505 | |
506 This variable is very similar to `nnir-wais-remove-prefix', except | |
507 that it is for swish++, not Wais." | |
508 :type '(regexp) | |
509 :group 'nnir) | |
510 | |
511 ;; Swish-E. | |
512 ;; URL: http://sunsite.berkeley.edu/SWISH-E/ | |
513 ;; New version: http://www.boe.es/swish-e | |
514 ;; Variables `nnir-swish-e-index-file', `nnir-swish-e-program' and | |
515 ;; `nnir-swish-e-additional-switches' | |
516 | |
517 (make-obsolete-variable 'nnir-swish-e-index-file | |
104700
9866b069527c
* spam.el (spam-ifile-path, spam-bogofilter-path, spam-sa-learn-path)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104584
diff
changeset
|
518 'nnir-swish-e-index-files "Emacs 23.1") |
95610 | 519 (defcustom nnir-swish-e-index-file |
520 (expand-file-name "~/Mail/index.swish-e") | |
521 "*Index file for swish-e. | |
522 This could be a server parameter. | |
523 It is never consulted once `nnir-swish-e-index-files', which should be | |
524 used instead, has been customized." | |
525 :type '(file) | |
526 :group 'nnir) | |
527 | |
528 (defcustom nnir-swish-e-index-files | |
529 (list nnir-swish-e-index-file) | |
530 "*List of index files for swish-e. | |
531 This could be a server parameter." | |
532 :type '(repeat (file)) | |
533 :group 'nnir) | |
534 | |
535 (defcustom nnir-swish-e-program "swish-e" | |
536 "*Name of swish-e search executable. | |
537 This cannot be a server parameter." | |
538 :type '(string) | |
539 :group 'nnir) | |
540 | |
541 (defcustom nnir-swish-e-additional-switches '() | |
542 "*A list of strings, to be given as additional arguments to swish-e. | |
543 | |
544 Note that this should be a list. Ie, do NOT use the following: | |
545 (setq nnir-swish-e-additional-switches \"-i -w\") ; wrong | |
546 Instead, use this: | |
547 (setq nnir-swish-e-additional-switches '(\"-i\" \"-w\")) | |
548 | |
549 This could be a server parameter." | |
550 :type '(repeat (string)) | |
551 :group 'nnir) | |
552 | |
553 (defcustom nnir-swish-e-remove-prefix (concat (getenv "HOME") "/Mail/") | |
554 "*The prefix to remove from each file name returned by swish-e | |
555 in order to get a group name (albeit with / instead of .). This is a | |
556 regular expression. | |
557 | |
558 This variable is very similar to `nnir-wais-remove-prefix', except | |
559 that it is for swish-e, not Wais. | |
560 | |
561 This could be a server parameter." | |
562 :type '(regexp) | |
563 :group 'nnir) | |
564 | |
565 ;; HyREX engine, see <URL:http://ls6-www.cs.uni-dortmund.de/> | |
566 | |
567 (defcustom nnir-hyrex-program "nnir-search" | |
568 "*Name of the nnir-search executable." | |
569 :type '(string) | |
570 :group 'nnir) | |
571 | |
572 (defcustom nnir-hyrex-additional-switches '() | |
573 "*A list of strings, to be given as additional arguments for nnir-search. | |
574 Note that this should be a list. Ie, do NOT use the following: | |
575 (setq nnir-hyrex-additional-switches \"-ddl ddl.xml -c nnir\") ; wrong ! | |
576 Instead, use this: | |
577 (setq nnir-hyrex-additional-switches '(\"-ddl\" \"ddl.xml\" \"-c\" \"nnir\"))" | |
578 :type '(repeat (string)) | |
579 :group 'nnir) | |
580 | |
581 (defcustom nnir-hyrex-index-directory (getenv "HOME") | |
582 "*Index directory for HyREX." | |
583 :type '(directory) | |
584 :group 'nnir) | |
585 | |
586 (defcustom nnir-hyrex-remove-prefix (concat (getenv "HOME") "/Mail/") | |
587 "*The prefix to remove from each file name returned by HyREX | |
588 in order to get a group name (albeit with / instead of .). | |
589 | |
590 For example, suppose that HyREX returns file names such as | |
591 \"/home/john/Mail/mail/misc/42\". For this example, use the following | |
592 setting: (setq nnir-hyrex-remove-prefix \"/home/john/Mail/\") | |
593 Note the trailing slash. Removing this prefix gives \"mail/misc/42\". | |
594 `nnir' knows to remove the \"/42\" and to replace \"/\" with \".\" to | |
595 arrive at the correct group name, \"mail.misc\"." | |
596 :type '(directory) | |
597 :group 'nnir) | |
598 | |
599 ;; Namazu engine, see <URL:http://ww.namazu.org/> | |
600 | |
601 (defcustom nnir-namazu-program "namazu" | |
602 "*Name of Namazu search executable." | |
603 :type '(string) | |
604 :group 'nnir) | |
605 | |
606 (defcustom nnir-namazu-index-directory (expand-file-name "~/Mail/namazu/") | |
607 "*Index directory for Namazu." | |
608 :type '(directory) | |
609 :group 'nnir) | |
610 | |
611 (defcustom nnir-namazu-additional-switches '() | |
612 "*A list of strings, to be given as additional arguments to namazu. | |
613 The switches `-q', `-a', and `-s' are always used, very few other switches | |
614 make any sense in this context. | |
615 | |
616 Note that this should be a list. Ie, do NOT use the following: | |
617 (setq nnir-namazu-additional-switches \"-i -w\") ; wrong | |
618 Instead, use this: | |
619 (setq nnir-namazu-additional-switches '(\"-i\" \"-w\"))" | |
620 :type '(repeat (string)) | |
621 :group 'nnir) | |
622 | |
623 (defcustom nnir-namazu-remove-prefix (concat (getenv "HOME") "/Mail/") | |
624 "*The prefix to remove from each file name returned by Namazu | |
625 in order to get a group name (albeit with / instead of .). | |
626 | |
627 This variable is very similar to `nnir-wais-remove-prefix', except | |
628 that it is for Namazu, not Wais." | |
629 :type '(directory) | |
630 :group 'nnir) | |
631 | |
632 ;;; Internal Variables: | |
633 | |
634 (defvar nnir-current-query nil | |
635 "Internal: stores current query (= group name).") | |
636 | |
637 (defvar nnir-current-server nil | |
638 "Internal: stores current server (does it ever change?).") | |
639 | |
640 (defvar nnir-current-group-marked nil | |
641 "Internal: stores current list of process-marked groups.") | |
642 | |
643 (defvar nnir-artlist nil | |
644 "Internal: stores search result.") | |
645 | |
646 (defvar nnir-tmp-buffer " *nnir*" | |
647 "Internal: temporary buffer.") | |
648 | |
649 ;;; Code: | |
650 | |
651 ;; Gnus glue. | |
652 | |
653 (defun gnus-group-make-nnir-group (extra-parms query) | |
654 "Create an nnir group. Asks for query." | |
655 (interactive "P\nsQuery: ") | |
656 (setq nnir-current-query nil | |
657 nnir-current-server nil | |
658 nnir-current-group-marked nil | |
659 nnir-artlist nil) | |
660 (let ((parms nil)) | |
661 (if extra-parms | |
662 (setq parms (nnir-read-parms query)) | |
663 (setq parms (list (cons 'query query)))) | |
664 (add-to-list 'parms (cons 'unique-id (message-unique-id)) t) | |
665 (gnus-group-read-ephemeral-group | |
666 (concat "nnir:" (prin1-to-string parms)) '(nnir "") t | |
667 (cons (current-buffer) | |
668 gnus-current-window-configuration) | |
669 nil))) | |
670 | |
95830 | 671 (eval-when-compile |
672 (when (featurep 'xemacs) | |
673 ;; The `kbd' macro requires that the `read-kbd-macro' macro is available. | |
674 (require 'edmacro))) | |
675 | |
95610 | 676 (defun nnir-group-mode-hook () |
677 (define-key gnus-group-mode-map (kbd "G G") | |
678 'gnus-group-make-nnir-group)) | |
679 (add-hook 'gnus-group-mode-hook 'nnir-group-mode-hook) | |
680 | |
681 ;; Why is this needed? Is this for compatibility with old/new gnusae? Using | |
682 ;; gnus-group-server instead works for me. -- Justus Piater | |
683 (defmacro nnir-group-server (group) | |
684 "Return the server for a newsgroup GROUP. | |
685 The returned format is as `gnus-server-to-method' needs it. See | |
686 `gnus-group-real-prefix' and `gnus-group-real-name'." | |
687 `(let ((gname ,group)) | |
688 (if (string-match "^\\([^:]+\\):" gname) | |
689 (progn | |
690 (setq gname (match-string 1 gname)) | |
691 (if (string-match "^\\([^+]+\\)\\+\\(.+\\)$" gname) | |
692 (format "%s:%s" (match-string 1 gname) (match-string 2 gname)) | |
693 (concat gname ":"))) | |
694 (format "%s:%s" (car gnus-select-method) (cadr gnus-select-method))))) | |
695 | |
696 ;; Summary mode commands. | |
697 | |
698 (defun gnus-summary-nnir-goto-thread () | |
699 "Only applies to nnir groups. Go to group this article came from | |
700 and show thread that contains this article." | |
701 (interactive) | |
702 (unless (eq 'nnir (car (gnus-find-method-for-group gnus-newsgroup-name))) | |
105167
e14dfafc8256
* gnus-art.el (gnus-article-encrypt-body):
Juanma Barranquero <lekktu@gmail.com>
parents:
104700
diff
changeset
|
703 (error "Can't execute this command unless in nnir group")) |
95610 | 704 (let* ((cur (gnus-summary-article-number)) |
705 (group (nnir-artlist-artitem-group nnir-artlist cur)) | |
706 (backend-number (nnir-artlist-artitem-number nnir-artlist cur)) | |
707 server backend-group) | |
708 (setq server (nnir-group-server group)) | |
709 (setq backend-group (gnus-group-real-name group)) | |
710 (gnus-group-read-ephemeral-group | |
711 backend-group | |
712 (gnus-server-to-method server) | |
713 t ; activate | |
714 (cons (current-buffer) | |
715 'summary) ; window config | |
716 nil | |
717 (list backend-number)) | |
718 (gnus-summary-limit (list backend-number)) | |
719 (gnus-summary-refer-thread))) | |
720 | |
721 (if (fboundp 'eval-after-load) | |
722 (eval-after-load "gnus-sum" | |
723 '(define-key gnus-summary-goto-map | |
724 "T" 'gnus-summary-nnir-goto-thread)) | |
725 (add-hook 'gnus-summary-mode-hook | |
726 (function (lambda () | |
727 (define-key gnus-summary-goto-map | |
728 "T" 'gnus-summary-nnir-goto-thread))))) | |
729 | |
730 | |
731 | |
732 ;; Gnus backend interface functions. | |
733 | |
734 (deffoo nnir-open-server (server &optional definitions) | |
735 ;; Just set the server variables appropriately. | |
736 (nnoo-change-server 'nnir server definitions)) | |
737 | |
110422
93e093c035a0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110410
diff
changeset
|
738 (deffoo nnir-request-group (group &optional server fast info) |
95610 | 739 "GROUP is the query string." |
740 (nnir-possibly-change-server server) | |
741 ;; Check for cache and return that if appropriate. | |
742 (if (and (equal group nnir-current-query) | |
743 (equal gnus-group-marked nnir-current-group-marked) | |
744 (or (null server) | |
745 (equal server nnir-current-server))) | |
746 nnir-artlist | |
747 ;; Cache miss. | |
748 (setq nnir-artlist (nnir-run-query group))) | |
110410
f2e111723c3a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110111
diff
changeset
|
749 (with-current-buffer nntp-server-buffer |
95610 | 750 (if (zerop (length nnir-artlist)) |
751 (progn | |
752 (setq nnir-current-query nil | |
753 nnir-current-server nil | |
754 nnir-current-group-marked nil | |
755 nnir-artlist nil) | |
756 (nnheader-report 'nnir "Search produced empty results.")) | |
757 ;; Remember data for cache. | |
758 (setq nnir-current-query group) | |
759 (when server (setq nnir-current-server server)) | |
760 (setq nnir-current-group-marked gnus-group-marked) | |
761 (nnheader-insert "211 %d %d %d %s\n" | |
762 (nnir-artlist-length nnir-artlist) ; total # | |
763 1 ; first # | |
764 (nnir-artlist-length nnir-artlist) ; last # | |
765 group)))) ; group name | |
766 | |
767 (deffoo nnir-retrieve-headers (articles &optional group server fetch-old) | |
768 (save-excursion | |
769 (let ((artlist (copy-sequence articles)) | |
770 art artitem artgroup artno artrsv artfullgroup | |
771 novitem novdata foo server) | |
772 (while (not (null artlist)) | |
773 (setq art (car artlist)) | |
774 (or (numberp art) | |
775 (nnheader-report | |
776 'nnir | |
777 "nnir-retrieve-headers doesn't grok message ids: %s" | |
778 art)) | |
779 (setq artitem (nnir-artlist-article nnir-artlist art)) | |
780 (setq artrsv (nnir-artitem-rsv artitem)) | |
781 (setq artfullgroup (nnir-artitem-group artitem)) | |
782 (setq artno (nnir-artitem-number artitem)) | |
783 (setq artgroup (gnus-group-real-name artfullgroup)) | |
784 (setq server (nnir-group-server artfullgroup)) | |
785 ;; retrieve NOV or HEAD data for this article, transform into | |
786 ;; NOV data and prepend to `novdata' | |
787 (set-buffer nntp-server-buffer) | |
788 (nnir-possibly-change-server server) | |
789 (let ((gnus-override-method | |
790 (gnus-server-to-method server))) | |
107473 | 791 ;; if nnir-get-article-nov-override-function is set, use it |
792 (if nnir-get-article-nov-override-function | |
793 (setq novitem (funcall nnir-get-article-nov-override-function | |
794 artitem)) | |
795 ;; else, set novitem through nnheader-parse-nov/nnheader-parse-head | |
110111
5b9f64b04a04
Delete all trailing white space.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110102
diff
changeset
|
796 (case (setq foo (gnus-retrieve-headers (list artno) |
107473 | 797 artfullgroup nil)) |
798 (nov | |
799 (goto-char (point-min)) | |
800 (setq novitem (nnheader-parse-nov)) | |
801 (unless novitem | |
802 (pop-to-buffer nntp-server-buffer) | |
803 (error | |
804 "nnheader-parse-nov returned nil for article %s in group %s" | |
805 artno artfullgroup))) | |
806 (headers | |
807 (goto-char (point-min)) | |
808 (setq novitem (nnheader-parse-head)) | |
809 (unless novitem | |
810 (pop-to-buffer nntp-server-buffer) | |
811 (error | |
812 "nnheader-parse-head returned nil for article %s in group %s" | |
813 artno artfullgroup))) | |
814 (t (error "Unknown header type %s while requesting article %s of group %s" | |
815 foo artno artfullgroup))))) | |
95610 | 816 ;; replace article number in original group with article number |
817 ;; in nnir group | |
818 (mail-header-set-number novitem art) | |
819 (mail-header-set-from novitem | |
820 (mail-header-from novitem)) | |
821 (mail-header-set-subject | |
822 novitem | |
823 (format "[%d: %s/%d] %s" | |
824 artrsv artgroup artno | |
825 (mail-header-subject novitem))) | |
826 ;;-(mail-header-set-extra novitem nil) | |
827 (push novitem novdata) | |
828 (setq artlist (cdr artlist))) | |
829 (setq novdata (nreverse novdata)) | |
830 (set-buffer nntp-server-buffer) (erase-buffer) | |
831 (mapc 'nnheader-insert-nov novdata) | |
832 'nov))) | |
833 | |
834 (deffoo nnir-request-article (article | |
835 &optional group server to-buffer) | |
836 (if (stringp article) | |
837 (nnheader-report | |
838 'nnir | |
839 "nnir-retrieve-headers doesn't grok message ids: %s" | |
840 article) | |
841 (save-excursion | |
842 (let* ((artitem (nnir-artlist-article nnir-artlist | |
843 article)) | |
844 (artfullgroup (nnir-artitem-group artitem)) | |
845 (artno (nnir-artitem-number artitem)) | |
846 ;; Bug? | |
847 ;; Why must we bind nntp-server-buffer here? It won't | |
848 ;; work if `buf' is used, say. (Of course, the set-buffer | |
849 ;; line below must then be updated, too.) | |
850 (nntp-server-buffer (or to-buffer nntp-server-buffer))) | |
851 (set-buffer nntp-server-buffer) | |
852 (erase-buffer) | |
853 (message "Requesting article %d from group %s" | |
854 artno artfullgroup) | |
855 (gnus-request-article artno artfullgroup nntp-server-buffer) | |
856 (cons artfullgroup artno))))) | |
857 | |
858 | |
859 (nnoo-define-skeleton nnir) | |
860 | |
861 | |
862 (defmacro nnir-add-result (dirnam artno score prefix server artlist) | |
95616 | 863 "Ask `nnir-compose-result' to construct a result vector, |
95610 | 864 and if it is non-nil, add it to artlist." |
865 `(let ((result (nnir-compose-result ,dirnam ,artno ,score ,prefix ,server))) | |
866 (when (not (null result)) | |
867 (push result ,artlist)))) | |
868 | |
869 (autoload 'nnmaildir-base-name-to-article-number "nnmaildir") | |
870 | |
871 ;; Helper function currently used by the Swish++ and Namazu backends; | |
872 ;; perhaps useful for other backends as well | |
873 (defun nnir-compose-result (dirnam article score prefix server) | |
874 "Extract the group from dirnam, and create a result vector | |
875 ready to be added to the list of search results." | |
876 | |
877 ;; remove nnir-*-remove-prefix from beginning of dirnam filename | |
878 (when (string-match (concat "^" prefix) dirnam) | |
879 (setq dirnam (replace-match "" t t dirnam))) | |
880 | |
881 (when (file-readable-p (concat prefix dirnam article)) | |
882 ;; remove trailing slash and, for nnmaildir, cur/new/tmp | |
883 (setq dirnam | |
884 (substring dirnam 0 (if (string= server "nnmaildir:") -5 -1))) | |
885 | |
886 ;; Set group to dirnam without any leading dots or slashes, | |
887 ;; and with all subsequent slashes replaced by dots | |
888 (let ((group (gnus-replace-in-string | |
889 (gnus-replace-in-string dirnam "^[./\\]" "" t) | |
890 "[/\\]" "." t))) | |
891 | |
892 (vector (nnir-group-full-name group server) | |
893 (if (string= server "nnmaildir:") | |
894 (nnmaildir-base-name-to-article-number | |
895 (substring article 0 (string-match ":" article)) | |
896 group nil) | |
897 (string-to-number article)) | |
898 (string-to-number score))))) | |
899 | |
900 ;;; Search Engine Interfaces: | |
901 | |
902 ;; freeWAIS-sf interface. | |
903 (defun nnir-run-waissearch (query server &optional group) | |
904 "Run given query agains waissearch. Returns vector of (group name, file name) | |
905 pairs (also vectors, actually)." | |
906 (when group | |
105167
e14dfafc8256
* gnus-art.el (gnus-article-encrypt-body):
Juanma Barranquero <lekktu@gmail.com>
parents:
104700
diff
changeset
|
907 (error "The freeWAIS-sf backend cannot search specific groups")) |
95610 | 908 (save-excursion |
909 (let ((qstring (cdr (assq 'query query))) | |
910 (prefix (nnir-read-server-parm 'nnir-wais-remove-prefix server)) | |
911 artlist score artno dirnam) | |
912 (set-buffer (get-buffer-create nnir-tmp-buffer)) | |
913 (erase-buffer) | |
914 (message "Doing WAIS query %s..." query) | |
915 (call-process nnir-wais-program | |
916 nil ; input from /dev/null | |
917 t ; output to current buffer | |
918 nil ; don't redisplay | |
919 "-d" (nnir-read-server-parm 'nnir-wais-database server) ; database to search | |
920 qstring) | |
921 (message "Massaging waissearch output...") | |
922 ;; remove superfluous lines | |
923 (keep-lines "Score:") | |
924 ;; extract data from result lines | |
925 (goto-char (point-min)) | |
926 (while (re-search-forward | |
927 "Score: +\\([0-9]+\\).*'\\([0-9]+\\) +\\([^']+\\)/'" nil t) | |
928 (setq score (match-string 1) | |
929 artno (match-string 2) | |
930 dirnam (match-string 3)) | |
931 (unless (string-match prefix dirnam) | |
932 (nnheader-report 'nnir "Dir name %s doesn't contain prefix %s" | |
933 dirnam prefix)) | |
104584
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
934 (setq group (gnus-replace-in-string |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
935 (replace-match "" t t dirnam) "/" ".")) |
95610 | 936 (push (vector (nnir-group-full-name group server) |
937 (string-to-number artno) | |
938 (string-to-number score)) | |
939 artlist)) | |
940 (message "Massaging waissearch output...done") | |
941 (apply 'vector | |
104584
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
942 (sort artlist |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
943 (function (lambda (x y) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
944 (> (nnir-artitem-rsv x) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
945 (nnir-artitem-rsv y))))))))) |
95610 | 946 |
947 ;; IMAP interface. | |
948 ;; todo: | |
949 ;; nnir invokes this two (2) times???! | |
950 ;; we should not use nnimap at all but open our own server connection | |
951 ;; we should not LIST * but use nnimap-list-pattern from defs | |
952 ;; send queries as literals | |
953 ;; handle errors | |
954 | |
955 (autoload 'nnimap-open-server "nnimap") | |
956 (defvar nnimap-server-buffer) ;; nnimap.el | |
957 (autoload 'imap-mailbox-select "imap") | |
958 (autoload 'imap-search "imap") | |
959 (autoload 'imap-quote-specials "imap") | |
960 | |
110517
64945cefe6a6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110516
diff
changeset
|
961 (eval-when-compile |
64945cefe6a6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110516
diff
changeset
|
962 (autoload 'nnimap-buffer "nnimap") |
64945cefe6a6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110516
diff
changeset
|
963 (autoload 'nnimap-command "nnimap") |
64945cefe6a6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110516
diff
changeset
|
964 (autoload 'nnimap-possibly-change-group "nnimap")) |
64945cefe6a6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110516
diff
changeset
|
965 |
95610 | 966 (defun nnir-run-imap (query srv &optional group-option) |
967 "Run a search against an IMAP back-end server. | |
968 This uses a custom query language parser; see `nnir-imap-make-query' for | |
969 details on the language and supported extensions" | |
970 (save-excursion | |
971 (let ((qstring (cdr (assq 'query query))) | |
972 (server (cadr (gnus-server-to-method srv))) | |
973 (group (or group-option (gnus-group-group-name))) | |
974 (defs (caddr (gnus-server-to-method srv))) | |
975 (criteria (or (cdr (assq 'criteria query)) | |
976 nnir-imap-search-field)) | |
110516
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
977 (gnus-inhibit-demon t) |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
978 artlist) |
95610 | 979 (message "Opening server %s" server) |
980 (condition-case () | |
110516
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
981 (when (nnimap-possibly-change-group (gnus-group-short-name group) server) |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
982 (with-current-buffer (nnimap-buffer) |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
983 (message "Searching %s..." group) |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
984 (let ((arts 0) |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
985 (result |
110569
5e158658b471
nnir.el (nnir-run-imap): Allow sending IMAP search patterns directly.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110517
diff
changeset
|
986 (nnimap-command "UID SEARCH %s" |
5e158658b471
nnir.el (nnir-run-imap): Allow sending IMAP search patterns directly.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110517
diff
changeset
|
987 (if (string= criteria "") |
5e158658b471
nnir.el (nnir-run-imap): Allow sending IMAP search patterns directly.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110517
diff
changeset
|
988 qstring |
5e158658b471
nnir.el (nnir-run-imap): Allow sending IMAP search patterns directly.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110517
diff
changeset
|
989 (nnir-imap-make-query criteria qstring) |
5e158658b471
nnir.el (nnir-run-imap): Allow sending IMAP search patterns directly.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110517
diff
changeset
|
990 )))) |
110516
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
991 (mapc |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
992 (lambda (artnum) |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
993 (push (vector group artnum 1) artlist) |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
994 (setq arts (1+ arts))) |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
995 (and (car result) |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
996 (delete 0 (mapcar #'string-to-number |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
997 (cdr (assoc "SEARCH" (cdr result))))))) |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
998 (message "Searching %s... %d matches" group arts))) |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
999 (message "Searching %s...done" group)) |
4d2f8b81bb01
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110475
diff
changeset
|
1000 (quit nil)) |
95610 | 1001 (reverse artlist)))) |
1002 | |
1003 (defun nnir-imap-make-query (criteria qstring) | |
1004 "Parse the query string and criteria into an appropriate IMAP search | |
1005 expression, returning the string query to make. | |
1006 | |
1007 This implements a little language designed to return the expected results | |
1008 to an arbitrary query string to the end user. | |
1009 | |
1010 The search is always case-insensitive, as defined by RFC2060, and supports | |
95616 | 1011 the following features (inspired by the Google search input language): |
95610 | 1012 |
1013 Automatic \"and\" queries | |
1014 If you specify multiple words then they will be treated as an \"and\" | |
1015 expression intended to match all components. | |
1016 | |
1017 Phrase searches | |
1018 If you wrap your query in double-quotes then it will be treated as a | |
1019 literal string. | |
1020 | |
1021 Negative terms | |
1022 If you precede a term with \"-\" then it will negate that. | |
1023 | |
1024 \"OR\" queries | |
1025 If you include an upper-case \"OR\" in your search it will cause the | |
1026 term before it and the term after it to be treated as alternatives. | |
1027 | |
1028 In future the following will be added to the language: | |
1029 * support for date matches | |
1030 * support for location of text matching within the query | |
1031 * from/to/etc headers | |
1032 * additional search terms | |
1033 * flag based searching | |
1034 * anything else that the RFC supports, basically." | |
1035 ;; Walk through the query and turn it into an IMAP query string. | |
1036 (nnir-imap-query-to-imap criteria (nnir-imap-parse-query qstring))) | |
1037 | |
1038 | |
1039 (defun nnir-imap-query-to-imap (criteria query) | |
1040 "Turn a s-expression format query into IMAP." | |
1041 (mapconcat | |
1042 ;; Turn the expressions into IMAP text | |
1043 (lambda (item) | |
1044 (nnir-imap-expr-to-imap criteria item)) | |
1045 ;; The query, already in s-expr format. | |
1046 query | |
1047 ;; Append a space between each expression | |
1048 " ")) | |
1049 | |
1050 | |
1051 (defun nnir-imap-expr-to-imap (criteria expr) | |
1052 "Convert EXPR into an IMAP search expression on CRITERIA" | |
1053 ;; What sort of expression is this, eh? | |
1054 (cond | |
1055 ;; Simple string term | |
1056 ((stringp expr) | |
1057 (format "%s \"%s\"" criteria (imap-quote-specials expr))) | |
1058 ;; Trivial term: and | |
1059 ((eq expr 'and) nil) | |
1060 ;; Composite term: or expression | |
1061 ((eq (car-safe expr) 'or) | |
1062 (format "OR %s %s" | |
1063 (nnir-imap-expr-to-imap criteria (second expr)) | |
1064 (nnir-imap-expr-to-imap criteria (third expr)))) | |
1065 ;; Composite term: just the fax, mam | |
1066 ((eq (car-safe expr) 'not) | |
1067 (format "NOT (%s)" (nnir-imap-query-to-imap criteria (rest expr)))) | |
1068 ;; Composite term: just expand it all. | |
1069 ((and (not (null expr)) (listp expr)) | |
1070 (format "(%s)" (nnir-imap-query-to-imap criteria expr))) | |
1071 ;; Complex value, give up for now. | |
1072 (t (error "Unhandled input: %S" expr)))) | |
1073 | |
1074 | |
1075 (defun nnir-imap-parse-query (string) | |
1076 "Turn STRING into an s-expression based query based on the IMAP | |
1077 query language as defined in `nnir-imap-make-query'. | |
1078 | |
1079 This involves turning individual tokens into higher level terms | |
1080 that the search language can then understand and use." | |
1081 (with-temp-buffer | |
1082 ;; Set up the parsing environment. | |
1083 (insert string) | |
1084 (goto-char (point-min)) | |
1085 ;; Now, collect the output terms and return them. | |
1086 (let (out) | |
1087 (while (not (nnir-imap-end-of-input)) | |
1088 (push (nnir-imap-next-expr) out)) | |
1089 (reverse out)))) | |
1090 | |
1091 | |
1092 (defun nnir-imap-next-expr (&optional count) | |
1093 "Return the next expression from the current buffer." | |
1094 (let ((term (nnir-imap-next-term count)) | |
1095 (next (nnir-imap-peek-symbol))) | |
1096 ;; Are we looking at an 'or' expression? | |
1097 (cond | |
1098 ;; Handle 'expr or expr' | |
1099 ((eq next 'or) | |
1100 (list 'or term (nnir-imap-next-expr 2))) | |
1101 ;; Anything else | |
1102 (t term)))) | |
1103 | |
1104 | |
1105 (defun nnir-imap-next-term (&optional count) | |
1106 "Return the next TERM from the current buffer." | |
1107 (let ((term (nnir-imap-next-symbol count))) | |
1108 ;; What sort of term is this? | |
1109 (cond | |
1110 ;; and -- just ignore it | |
1111 ((eq term 'and) 'and) | |
1112 ;; negated term | |
1113 ((eq term 'not) (list 'not (nnir-imap-next-expr))) | |
1114 ;; generic term | |
1115 (t term)))) | |
1116 | |
1117 | |
1118 (defun nnir-imap-peek-symbol () | |
1119 "Return the next symbol from the current buffer, but don't consume it." | |
1120 (save-excursion | |
1121 (nnir-imap-next-symbol))) | |
1122 | |
1123 (defun nnir-imap-next-symbol (&optional count) | |
1124 "Return the next symbol from the current buffer, or nil if we are | |
1125 at the end of the buffer. If supplied COUNT skips some symbols before | |
1126 returning the one at the supplied position." | |
1127 (when (and (numberp count) (> count 1)) | |
1128 (nnir-imap-next-symbol (1- count))) | |
1129 (let ((case-fold-search t)) | |
1130 ;; end of input stream? | |
1131 (unless (nnir-imap-end-of-input) | |
1132 ;; No, return the next symbol from the stream. | |
1133 (cond | |
1134 ;; negated expression -- return it and advance one char. | |
1135 ((looking-at "-") (forward-char 1) 'not) | |
1136 ;; quoted string | |
1137 ((looking-at "\"") (nnir-imap-delimited-string "\"")) | |
1138 ;; list expression -- we parse the content and return this as a list. | |
1139 ((looking-at "(") | |
1140 (nnir-imap-parse-query (nnir-imap-delimited-string ")"))) | |
1141 ;; keyword input -- return a symbol version | |
1142 ((looking-at "\\band\\b") (forward-char 3) 'and) | |
1143 ((looking-at "\\bor\\b") (forward-char 2) 'or) | |
1144 ((looking-at "\\bnot\\b") (forward-char 3) 'not) | |
1145 ;; Simple, boring keyword | |
1146 (t (let ((start (point)) | |
1147 (end (if (search-forward-regexp "[[:blank:]]" nil t) | |
1148 (prog1 | |
1149 (match-beginning 0) | |
1150 ;; unskip if we hit a non-blank terminal character. | |
1151 (when (string-match "[^[:blank:]]" (match-string 0)) | |
1152 (backward-char 1))) | |
1153 (goto-char (point-max))))) | |
1154 (buffer-substring start end))))))) | |
1155 | |
1156 (defun nnir-imap-delimited-string (delimiter) | |
1157 "Return a delimited string from the current buffer." | |
1158 (let ((start (point)) end) | |
1159 (forward-char 1) ; skip the first delimiter. | |
1160 (while (not end) | |
1161 (unless (search-forward delimiter nil t) | |
1162 (error "Unmatched delimited input with %s in query" delimiter)) | |
1163 (let ((here (point))) | |
1164 (unless (equal (buffer-substring (- here 2) (- here 1)) "\\") | |
1165 (setq end (point))))) | |
1166 (buffer-substring (1+ start) (1- end)))) | |
1167 | |
1168 (defun nnir-imap-end-of-input () | |
1169 "Are we at the end of input?" | |
1170 (skip-chars-forward "[[:blank:]]") | |
1171 (looking-at "$")) | |
95616 | 1172 |
95610 | 1173 |
1174 ;; Swish++ interface. | |
1175 ;; -cc- Todo | |
1176 ;; Search by | |
1177 ;; - group | |
1178 ;; Sort by | |
1179 ;; - rank (default) | |
1180 ;; - article number | |
1181 ;; - file size | |
1182 ;; - group | |
1183 (defun nnir-run-swish++ (query server &optional group) | |
1184 "Run QUERY against swish++. | |
1185 Returns a vector of (group name, file name) pairs (also vectors, | |
1186 actually). | |
1187 | |
1188 Tested with swish++ 4.7 on GNU/Linux and with swish++ 5.0b2 on | |
1189 Windows NT 4.0." | |
1190 | |
1191 (when group | |
105167
e14dfafc8256
* gnus-art.el (gnus-article-encrypt-body):
Juanma Barranquero <lekktu@gmail.com>
parents:
104700
diff
changeset
|
1192 (error "The swish++ backend cannot search specific groups")) |
95610 | 1193 |
1194 (save-excursion | |
1195 (let ( (qstring (cdr (assq 'query query))) | |
1196 (groupspec (cdr (assq 'group query))) | |
1197 (prefix (nnir-read-server-parm 'nnir-swish++-remove-prefix server)) | |
1198 artlist | |
1199 ;; nnml-use-compressed-files might be any string, but probably this | |
1200 ;; is sufficient. Note that we can't only use the value of | |
1201 ;; nnml-use-compressed-files because old articles might have been | |
1202 ;; saved with a different value. | |
1203 (article-pattern (if (string= server "nnmaildir:") | |
1204 ":[0-9]+" | |
1205 "^[0-9]+\\(\\.[a-z0-9]+\\)?$")) | |
1206 score artno dirnam filenam) | |
1207 | |
1208 (when (equal "" qstring) | |
105167
e14dfafc8256
* gnus-art.el (gnus-article-encrypt-body):
Juanma Barranquero <lekktu@gmail.com>
parents:
104700
diff
changeset
|
1209 (error "swish++: You didn't enter anything")) |
95610 | 1210 |
1211 (set-buffer (get-buffer-create nnir-tmp-buffer)) | |
1212 (erase-buffer) | |
1213 | |
1214 (if groupspec | |
1215 (message "Doing swish++ query %s on %s..." qstring groupspec) | |
1216 (message "Doing swish++ query %s..." qstring)) | |
1217 | |
1218 (let* ((cp-list `( ,nnir-swish++-program | |
1219 nil ; input from /dev/null | |
1220 t ; output | |
1221 nil ; don't redisplay | |
1222 "--config-file" ,(nnir-read-server-parm 'nnir-swish++-configuration-file server) | |
1223 ,@(nnir-read-server-parm 'nnir-swish++-additional-switches server) | |
1224 ,qstring ; the query, in swish++ format | |
1225 )) | |
1226 (exitstatus | |
1227 (progn | |
1228 (message "%s args: %s" nnir-swish++-program | |
1229 (mapconcat 'identity (cddddr cp-list) " ")) ;; ??? | |
1230 (apply 'call-process cp-list)))) | |
1231 (unless (or (null exitstatus) | |
1232 (zerop exitstatus)) | |
1233 (nnheader-report 'nnir "Couldn't run swish++: %s" exitstatus) | |
1234 ;; swish++ failure reason is in this buffer, show it if | |
1235 ;; the user wants it. | |
1236 (when (> gnus-verbose 6) | |
1237 (display-buffer nnir-tmp-buffer)))) | |
1238 | |
1239 ;; The results are output in the format of: | |
1240 ;; V 4.7 Linux | |
1241 ;; rank relative-path-name file-size file-title | |
1242 ;; V 5.0b2: | |
1243 ;; rank relative-path-name file-size topic?? | |
1244 ;; where rank is an integer from 1 to 100. | |
1245 (goto-char (point-min)) | |
1246 (while (re-search-forward | |
1247 "\\(^[0-9]+\\) \\([^ ]+\\) [0-9]+ \\(.*\\)$" nil t) | |
1248 (setq score (match-string 1) | |
1249 filenam (match-string 2) | |
1250 artno (file-name-nondirectory filenam) | |
1251 dirnam (file-name-directory filenam)) | |
1252 | |
1253 ;; don't match directories | |
1254 (when (string-match article-pattern artno) | |
1255 (when (not (null dirnam)) | |
1256 | |
1257 ;; maybe limit results to matching groups. | |
1258 (when (or (not groupspec) | |
1259 (string-match groupspec dirnam)) | |
1260 (nnir-add-result dirnam artno score prefix server artlist))))) | |
1261 | |
1262 (message "Massaging swish++ output...done") | |
1263 | |
1264 ;; Sort by score | |
1265 (apply 'vector | |
104584
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1266 (sort artlist |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1267 (function (lambda (x y) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1268 (> (nnir-artitem-rsv x) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1269 (nnir-artitem-rsv y))))))))) |
95610 | 1270 |
1271 ;; Swish-E interface. | |
1272 (defun nnir-run-swish-e (query server &optional group) | |
1273 "Run given query against swish-e. | |
1274 Returns a vector of (group name, file name) pairs (also vectors, | |
1275 actually). | |
1276 | |
1277 Tested with swish-e-2.0.1 on Windows NT 4.0." | |
1278 | |
1279 ;; swish-e crashes with empty parameter to "-w" on commandline... | |
1280 (when group | |
105167
e14dfafc8256
* gnus-art.el (gnus-article-encrypt-body):
Juanma Barranquero <lekktu@gmail.com>
parents:
104700
diff
changeset
|
1281 (error "The swish-e backend cannot search specific groups")) |
95610 | 1282 |
1283 (save-excursion | |
1284 (let ((qstring (cdr (assq 'query query))) | |
1285 (prefix | |
1286 (or (nnir-read-server-parm 'nnir-swish-e-remove-prefix server) | |
1287 (error "Missing parameter `nnir-swish-e-remove-prefix'"))) | |
1288 artlist score artno dirnam group ) | |
1289 | |
1290 (when (equal "" qstring) | |
105167
e14dfafc8256
* gnus-art.el (gnus-article-encrypt-body):
Juanma Barranquero <lekktu@gmail.com>
parents:
104700
diff
changeset
|
1291 (error "swish-e: You didn't enter anything")) |
95610 | 1292 |
1293 (set-buffer (get-buffer-create nnir-tmp-buffer)) | |
1294 (erase-buffer) | |
1295 | |
1296 (message "Doing swish-e query %s..." query) | |
1297 (let* ((index-files | |
1298 (or (nnir-read-server-parm | |
1299 'nnir-swish-e-index-files server) | |
1300 (error "Missing parameter `nnir-swish-e-index-files'"))) | |
1301 (additional-switches | |
1302 (nnir-read-server-parm | |
1303 'nnir-swish-e-additional-switches server)) | |
1304 (cp-list `(,nnir-swish-e-program | |
1305 nil ; input from /dev/null | |
1306 t ; output | |
1307 nil ; don't redisplay | |
1308 "-f" ,@index-files | |
1309 ,@additional-switches | |
1310 "-w" | |
1311 ,qstring ; the query, in swish-e format | |
1312 )) | |
1313 (exitstatus | |
1314 (progn | |
1315 (message "%s args: %s" nnir-swish-e-program | |
1316 (mapconcat 'identity (cddddr cp-list) " ")) | |
1317 (apply 'call-process cp-list)))) | |
1318 (unless (or (null exitstatus) | |
1319 (zerop exitstatus)) | |
1320 (nnheader-report 'nnir "Couldn't run swish-e: %s" exitstatus) | |
1321 ;; swish-e failure reason is in this buffer, show it if | |
1322 ;; the user wants it. | |
1323 (when (> gnus-verbose 6) | |
1324 (display-buffer nnir-tmp-buffer)))) | |
1325 | |
1326 ;; The results are output in the format of: | |
1327 ;; rank path-name file-title file-size | |
1328 (goto-char (point-min)) | |
1329 (while (re-search-forward | |
1330 "\\(^[0-9]+\\) \\([^ ]+\\) \"\\([^\"]+\\)\" [0-9]+$" nil t) | |
1331 (setq score (match-string 1) | |
1332 artno (match-string 3) | |
1333 dirnam (file-name-directory (match-string 2))) | |
1334 | |
1335 ;; don't match directories | |
1336 (when (string-match "^[0-9]+$" artno) | |
1337 (when (not (null dirnam)) | |
1338 | |
1339 ;; remove nnir-swish-e-remove-prefix from beginning of dirname | |
1340 (when (string-match (concat "^" prefix) dirnam) | |
1341 (setq dirnam (replace-match "" t t dirnam))) | |
1342 | |
1343 (setq dirnam (substring dirnam 0 -1)) | |
1344 ;; eliminate all ".", "/", "\" from beginning. Always matches. | |
1345 (string-match "^[./\\]*\\(.*\\)$" dirnam) | |
1346 ;; "/" -> "." | |
104584
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1347 (setq group (gnus-replace-in-string (match-string 1 dirnam) "/" ".")) |
95610 | 1348 ;; Windows "\\" -> "." |
104584
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1349 (setq group (gnus-replace-in-string group "\\\\" ".")) |
95610 | 1350 |
1351 (push (vector (nnir-group-full-name group server) | |
1352 (string-to-number artno) | |
1353 (string-to-number score)) | |
1354 artlist)))) | |
1355 | |
1356 (message "Massaging swish-e output...done") | |
1357 | |
1358 ;; Sort by score | |
1359 (apply 'vector | |
104584
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1360 (sort artlist |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1361 (function (lambda (x y) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1362 (> (nnir-artitem-rsv x) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1363 (nnir-artitem-rsv y))))))))) |
95610 | 1364 |
1365 ;; HyREX interface | |
1366 (defun nnir-run-hyrex (query server &optional group) | |
1367 (save-excursion | |
1368 (let ((artlist nil) | |
1369 (groupspec (cdr (assq 'group query))) | |
1370 (qstring (cdr (assq 'query query))) | |
1371 (prefix (nnir-read-server-parm 'nnir-hyrex-remove-prefix server)) | |
1372 score artno dirnam) | |
1373 (when (and group groupspec) | |
1374 (error (concat "It does not make sense to use a group spec" | |
1375 " with process-marked groups."))) | |
1376 (when group | |
1377 (setq groupspec (gnus-group-real-name group))) | |
1378 (when (and group (not (equal group (nnir-group-full-name groupspec server)))) | |
1379 (message "%s vs. %s" group (nnir-group-full-name groupspec server)) | |
1380 (error "Server with groupspec doesn't match group !")) | |
1381 (set-buffer (get-buffer-create nnir-tmp-buffer)) | |
1382 (erase-buffer) | |
1383 (if groupspec | |
1384 (message "Doing hyrex-search query %s on %s..." query groupspec) | |
1385 (message "Doing hyrex-search query %s..." query)) | |
1386 (let* ((cp-list | |
1387 `( ,nnir-hyrex-program | |
1388 nil ; input from /dev/null | |
1389 t ; output | |
1390 nil ; don't redisplay | |
1391 "-i",(nnir-read-server-parm 'nnir-hyrex-index-directory server) ; index directory | |
1392 ,@(nnir-read-server-parm 'nnir-hyrex-additional-switches server) | |
1393 ,qstring ; the query, in hyrex-search format | |
1394 )) | |
1395 (exitstatus | |
1396 (progn | |
1397 (message "%s args: %s" nnir-hyrex-program | |
1398 (mapconcat 'identity (cddddr cp-list) " ")) | |
1399 (apply 'call-process cp-list)))) | |
1400 (unless (or (null exitstatus) | |
1401 (zerop exitstatus)) | |
1402 (nnheader-report 'nnir "Couldn't run hyrex-search: %s" exitstatus) | |
1403 ;; nnir-search failure reason is in this buffer, show it if | |
1404 ;; the user wants it. | |
1405 (when (> gnus-verbose 6) | |
1406 (display-buffer nnir-tmp-buffer)))) ;; FIXME: Dont clear buffer ! | |
1407 (if groupspec | |
1408 (message "Doing hyrex-search query \"%s\" on %s...done" qstring groupspec) | |
1409 (message "Doing hyrex-search query \"%s\"...done" qstring)) | |
1410 (sit-for 0) | |
1411 ;; nnir-search returns: | |
1412 ;; for nnml/nnfolder: "filename mailid weigth" | |
1413 ;; for nnimap: "group mailid weigth" | |
1414 (goto-char (point-min)) | |
1415 (delete-non-matching-lines "^\\S + [0-9]+ [0-9]+$") | |
1416 ;; HyREX couldn't search directly in groups -- so filter out here. | |
1417 (when groupspec | |
1418 (keep-lines groupspec)) | |
1419 ;; extract data from result lines | |
1420 (goto-char (point-min)) | |
1421 (while (re-search-forward | |
1422 "\\(\\S +\\) \\([0-9]+\\) \\([0-9]+\\)" nil t) | |
1423 (setq dirnam (match-string 1) | |
1424 artno (match-string 2) | |
1425 score (match-string 3)) | |
1426 (when (string-match prefix dirnam) | |
1427 (setq dirnam (replace-match "" t t dirnam))) | |
104584
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1428 (push (vector (nnir-group-full-name |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1429 (gnus-replace-in-string dirnam "/" ".") server) |
95610 | 1430 (string-to-number artno) |
1431 (string-to-number score)) | |
1432 artlist)) | |
1433 (message "Massaging hyrex-search output...done.") | |
1434 (apply 'vector | |
104584
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1435 (sort artlist |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1436 (function (lambda (x y) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1437 (if (string-lessp (nnir-artitem-group x) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1438 (nnir-artitem-group y)) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1439 t |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1440 (< (nnir-artitem-number x) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1441 (nnir-artitem-number y))))))) |
95610 | 1442 ))) |
1443 | |
1444 ;; Namazu interface | |
1445 (defun nnir-run-namazu (query server &optional group) | |
1446 "Run given query against Namazu. Returns a vector of (group name, file name) | |
1447 pairs (also vectors, actually). | |
1448 | |
1449 Tested with Namazu 2.0.6 on a GNU/Linux system." | |
1450 (when group | |
1451 (error "The Namazu backend cannot search specific groups")) | |
1452 (save-excursion | |
1453 (let ((article-pattern (if (string= server "nnmaildir:") | |
1454 ":[0-9]+" | |
1455 "^[0-9]+$")) | |
1456 artlist | |
1457 (qstring (cdr (assq 'query query))) | |
1458 (prefix (nnir-read-server-parm 'nnir-namazu-remove-prefix server)) | |
1459 score group article | |
1460 (process-environment (copy-sequence process-environment))) | |
1461 (setenv "LC_MESSAGES" "C") | |
1462 (set-buffer (get-buffer-create nnir-tmp-buffer)) | |
1463 (erase-buffer) | |
1464 (let* ((cp-list | |
1465 `( ,nnir-namazu-program | |
1466 nil ; input from /dev/null | |
1467 t ; output | |
1468 nil ; don't redisplay | |
1469 "-q" ; don't be verbose | |
1470 "-a" ; show all matches | |
1471 "-s" ; use short format | |
1472 ,@(nnir-read-server-parm 'nnir-namazu-additional-switches server) | |
1473 ,qstring ; the query, in namazu format | |
1474 ,(nnir-read-server-parm 'nnir-namazu-index-directory server) ; index directory | |
1475 )) | |
1476 (exitstatus | |
1477 (progn | |
1478 (message "%s args: %s" nnir-namazu-program | |
1479 (mapconcat 'identity (cddddr cp-list) " ")) | |
1480 (apply 'call-process cp-list)))) | |
1481 (unless (or (null exitstatus) | |
1482 (zerop exitstatus)) | |
1483 (nnheader-report 'nnir "Couldn't run namazu: %s" exitstatus) | |
1484 ;; Namazu failure reason is in this buffer, show it if | |
1485 ;; the user wants it. | |
1486 (when (> gnus-verbose 6) | |
1487 (display-buffer nnir-tmp-buffer)))) | |
1488 | |
1489 ;; Namazu output looks something like this: | |
1490 ;; 2. Re: Gnus agent expire broken (score: 55) | |
1491 ;; /home/henrik/Mail/mail/sent/1310 (4,138 bytes) | |
1492 | |
1493 (goto-char (point-min)) | |
1494 (while (re-search-forward | |
1495 "^\\([0-9]+\\.\\).*\\((score: \\([0-9]+\\)\\))\n\\([^ ]+\\)" | |
1496 nil t) | |
1497 (setq score (match-string 3) | |
1498 group (file-name-directory (match-string 4)) | |
1499 article (file-name-nondirectory (match-string 4))) | |
1500 | |
1501 ;; make sure article and group is sane | |
1502 (when (and (string-match article-pattern article) | |
1503 (not (null group))) | |
1504 (nnir-add-result group article score prefix server artlist))) | |
1505 | |
1506 ;; sort artlist by score | |
1507 (apply 'vector | |
104584
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1508 (sort artlist |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1509 (function (lambda (x y) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1510 (> (nnir-artitem-rsv x) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1511 (nnir-artitem-rsv y))))))))) |
95610 | 1512 |
1513 (defun nnir-run-find-grep (query server &optional group) | |
1514 "Run find and grep to obtain matching articles." | |
1515 (let* ((method (gnus-server-to-method server)) | |
1516 (sym (intern | |
1517 (concat (symbol-name (car method)) "-directory"))) | |
1518 (directory (cadr (assoc sym (cddr method)))) | |
1519 (regexp (cdr (assoc 'query query))) | |
1520 (grep-options (cdr (assoc 'grep-options query))) | |
1521 artlist) | |
1522 (unless directory | |
1523 (error "No directory found in method specification of server %s" | |
1524 server)) | |
1525 (message "Searching %s using find-grep..." (or group server)) | |
1526 (save-window-excursion | |
1527 (set-buffer (get-buffer-create nnir-tmp-buffer)) | |
1528 (erase-buffer) | |
1529 (if (> gnus-verbose 6) | |
1530 (pop-to-buffer (current-buffer))) | |
1531 (cd directory) ; Using relative paths simplifies postprocessing. | |
1532 (let ((group | |
1533 (if (not group) | |
1534 "." | |
1535 ;; Try accessing the group literally as well as | |
1536 ;; interpreting dots as directory separators so the | |
104584
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1537 ;; engine works with plain nnml as well as the Gnus Cache. |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1538 (let ((group (gnus-group-real-name group))) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1539 ;; Replace cl-func find-if. |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1540 (if (file-directory-p group) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1541 group |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1542 (if (file-directory-p |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1543 (setq group (gnus-replace-in-string group "\\." "/" t))) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1544 group)))))) |
95610 | 1545 (unless group |
1546 (error "Cannot locate directory for group")) | |
1547 (save-excursion | |
1548 (apply | |
1549 'call-process "find" nil t | |
1550 "find" group "-type" "f" "-name" "[0-9]*" "-exec" | |
1551 "grep" | |
95830 | 1552 `("-l" ,@(and grep-options |
110475
ab3a38ccb842
Remove Emacs 21 stuff.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110422
diff
changeset
|
1553 (split-string grep-options "\\s-" t)) |
95610 | 1554 "-e" ,regexp "{}" "+")))) |
1555 | |
1556 ;; Translate relative paths to group names. | |
1557 (while (not (eobp)) | |
110475
ab3a38ccb842
Remove Emacs 21 stuff.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110422
diff
changeset
|
1558 (let* ((path (split-string |
ab3a38ccb842
Remove Emacs 21 stuff.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110422
diff
changeset
|
1559 (buffer-substring (point) (line-end-position)) "/" t)) |
95610 | 1560 (art (string-to-number (car (last path))))) |
1561 (while (string= "." (car path)) | |
1562 (setq path (cdr path))) | |
104584
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1563 (let ((group (mapconcat 'identity |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1564 ;; Replace cl-func: (subseq path 0 -1) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1565 (let ((end (1- (length path))) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1566 res) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1567 (while (>= (setq end (1- end)) 0) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1568 (push (pop path) res)) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1569 (nreverse res)) |
f540e84a920d
(top-level): Don't require cl at run-time.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1570 "."))) |
95610 | 1571 (push (vector (nnir-group-full-name group server) art 0) |
1572 artlist)) | |
1573 (forward-line 1))) | |
1574 (message "Searching %s using find-grep...done" (or group server)) | |
1575 artlist))) | |
1576 | |
1577 ;;; Util Code: | |
1578 | |
1579 (defun nnir-read-parms (query) | |
1580 "Reads additional search parameters according to `nnir-engines'." | |
1581 (let ((parmspec (caddr (assoc nnir-search-engine nnir-engines)))) | |
1582 (cons (cons 'query query) | |
1583 (mapcar 'nnir-read-parm parmspec)))) | |
1584 | |
1585 (defun nnir-read-parm (parmspec) | |
1586 "Reads a single search parameter. | |
1587 `parmspec' is a cons cell, the car is a symbol, the cdr is a prompt." | |
1588 (let ((sym (car parmspec)) | |
1589 (prompt (cdr parmspec))) | |
1590 (if (listp prompt) | |
1591 (let* ((result (apply 'completing-read prompt)) | |
1592 (mapping (or (assoc result nnir-imap-search-arguments) | |
1593 (assoc nil nnir-imap-search-arguments)))) | |
1594 (cons sym (format (cdr mapping) result))) | |
1595 (cons sym (read-string prompt))))) | |
1596 | |
1597 (defun nnir-run-query (query) | |
1598 "Invoke appropriate search engine function (see `nnir-engines'). | |
1599 If some groups were process-marked, run the query for each of the groups | |
1600 and concat the results." | |
1601 (let ((q (car (read-from-string query)))) | |
1602 (if gnus-group-marked | |
1603 (apply 'vconcat | |
1604 (mapcar (lambda (x) | |
1605 (let ((server (nnir-group-server x)) | |
1606 search-func) | |
1607 (setq search-func (cadr | |
1608 (assoc | |
1609 (nnir-read-server-parm 'nnir-search-engine server) nnir-engines))) | |
1610 (if search-func | |
1611 (funcall search-func q server x) | |
1612 nil))) | |
1613 gnus-group-marked) | |
1614 ) | |
1615 (apply 'vconcat | |
1616 (mapcar (lambda (x) | |
1617 (if (and (equal (cadr x) 'ok) (not (equal (cadar x) "-ephemeral"))) | |
1618 (let ((server (format "%s:%s" (caar x) (cadar x))) | |
1619 search-func) | |
1620 (setq search-func (cadr | |
1621 (assoc | |
1622 (nnir-read-server-parm 'nnir-search-engine server) nnir-engines))) | |
1623 (if search-func | |
1624 (funcall search-func q server nil) | |
1625 nil)) | |
1626 nil)) | |
1627 gnus-opened-servers) | |
1628 )) | |
1629 )) | |
1630 | |
1631 (defun nnir-read-server-parm (key server) | |
1632 "Returns the parameter value of for the given server, where server is of | |
1633 form 'backend:name'." | |
1634 (let ((method (gnus-server-to-method server))) | |
1635 (cond ((and method (assq key (cddr method))) | |
1636 (nth 1 (assq key (cddr method)))) | |
1637 ((and nnir-mail-backend | |
1638 (gnus-server-equal method nnir-mail-backend)) | |
1639 (symbol-value key)) | |
1640 (t nil)))) | |
1641 ;; (if method | |
1642 ;; (if (assq key (cddr method)) | |
1643 ;; (nth 1 (assq key (cddr method))) | |
1644 ;; (symbol-value key)) | |
1645 ;; (symbol-value key)) | |
1646 ;; )) | |
1647 | |
1648 (defun nnir-group-full-name (shortname server) | |
1649 "For the given group name, return a full Gnus group name. | |
1650 The Gnus backend/server information is added." | |
1651 (gnus-group-prefixed-name shortname (gnus-server-to-method server))) | |
1652 | |
1653 (defun nnir-possibly-change-server (server) | |
1654 (unless (and server (nnir-server-opened server)) | |
1655 (nnir-open-server server))) | |
1656 | |
1657 | |
1658 ;; Data type article list. | |
1659 | |
1660 (defun nnir-artlist-length (artlist) | |
1661 "Returns number of articles in artlist." | |
1662 (length artlist)) | |
1663 | |
1664 (defun nnir-artlist-article (artlist n) | |
1665 "Returns from ARTLIST the Nth artitem (counting starting at 1)." | |
1666 (elt artlist (1- n))) | |
1667 | |
1668 (defun nnir-artitem-group (artitem) | |
1669 "Returns the group from the ARTITEM." | |
1670 (elt artitem 0)) | |
1671 | |
1672 (defun nnir-artlist-artitem-group (artlist n) | |
1673 "Returns from ARTLIST the group of the Nth artitem (counting from 1)." | |
1674 (nnir-artitem-group (nnir-artlist-article artlist n))) | |
1675 | |
1676 (defun nnir-artitem-number (artitem) | |
1677 "Returns the number from the ARTITEM." | |
1678 (elt artitem 1)) | |
1679 | |
1680 (defun nnir-artlist-artitem-number (artlist n) | |
1681 "Returns from ARTLIST the number of the Nth artitem (counting from 1)." | |
1682 (nnir-artitem-number (nnir-artlist-article artlist n))) | |
1683 | |
1684 (defun nnir-artitem-rsv (artitem) | |
1685 "Returns the Retrieval Status Value (RSV, score) from the ARTITEM." | |
1686 (elt artitem 2)) | |
1687 | |
1688 (defun nnir-artlist-artitem-rsv (artlist n) | |
1689 "Returns from ARTLIST the Retrieval Status Value of the Nth artitem | |
1690 \(counting from 1)." | |
1691 (nnir-artitem-rsv (nnir-artlist-article artlist n))) | |
1692 | |
1693 ;; unused? | |
1694 (defun nnir-artlist-groups (artlist) | |
1695 "Returns a list of all groups in the given ARTLIST." | |
1696 (let ((res nil) | |
1697 (with-dups nil)) | |
1698 ;; from each artitem, extract group component | |
1699 (setq with-dups (mapcar 'nnir-artitem-group artlist)) | |
1700 ;; remove duplicates from above | |
1701 (mapc (function (lambda (x) (add-to-list 'res x))) | |
1702 with-dups) | |
1703 res)) | |
1704 | |
1705 | |
1706 ;; The end. | |
1707 (provide 'nnir) | |
1708 | |
95616 | 1709 ;;; nnir.el ends here |