1 ;;; nnir.el --- search mail with various search engines -*- coding: iso-8859-1 -*-
2 ;; Copyright (C) 1998 Kai Großjohann
4 ;; Author: Kai Großjohann <grossjohann@ls6.cs.uni-dortmund.de>
5 ;; Keywords: news, mail, searching, ir, glimpse, wais, hyrex
7 ;; This file is not part of GNU Emacs.
9 ;; This is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; The most recent version of this can always be fetched from the Gnus
27 ;; CVS repository. See http://www.gnus.org/ for more information.
29 ;; This code is still in the development stage but I'd like other
30 ;; people to have a look at it. Please do not hesitate to contact me
33 ;; What does it do? Well, it allows you to index your mail using some
34 ;; search engine (freeWAIS-sf, Glimpse and others -- see later),
35 ;; then type `G G' in the Group buffer and issue a query to the search
36 ;; engine. You will then get a buffer which shows all articles
37 ;; matching the query, sorted by Retrieval Status Value (score).
39 ;; When looking at the retrieval result (in the Summary buffer) you
40 ;; can type `G T' (aka M-x gnus-summary-nnir-goto-thread RET) on an
41 ;; article. You will be teleported into the group this article came
42 ;; from, showing the thread this article is part of. (See below for
45 ;; The Lisp installation is simple: just put this file on your
46 ;; load-path, byte-compile it, and load it from ~/.gnus or something.
47 ;; This will install a new command `G G' in your Group buffer for
48 ;; searching your mail. Note that you also need to configure a number
49 ;; of variables, as described below.
53 ;; * If you don't use HyREX as your search engine, this expects that
54 ;; you use nnml or another one-file-per-message backend, because the
55 ;; others doesn't support nnfolder.
56 ;; * It can only search the mail backend's which are supported by one
57 ;; search engine, because of different query languages.
58 ;; * There are restrictions to the Glimpse setup.
59 ;; * There are restrictions to the Wais setup.
60 ;; * There are restrictions to the imap setup.
61 ;; * gnus-summary-nnir-goto-thread: Fetches whole group first, before
62 ;; limiting to the right articles. This is much too slow, of
63 ;; course. May issue a query for number of articles to fetch; you
64 ;; must accept the default of all articles at this point or things
67 ;; The Lisp setup involves setting a few variables and setting up the
68 ;; search engine. You can define the variables in the server definition
70 ;; (setq gnus-secondary-select-methods '(
71 ;; (nnimap "" (nnimap-address "localhost")
72 ;; (nnir-search-engine hyrex)
73 ;; (nnir-hyrex-additional-switches ("-d" "ddl-nnimap.xml"))
75 ;; Or you can define the global ones. The variables set in the mailer-
76 ;; definition will be used first.
77 ;; The variable to set is `nnir-search-engine'. Choose one of the engines
78 ;; listed in `nnir-engines'. (Actually `nnir-engines' is an alist,
79 ;; type `C-h v nnir-engines RET' for more information; this includes
80 ;; examples for setting `nnir-search-engine', too.)
82 ;; The variable nnir-mail-backend isn't used anymore.
85 ;; You must also set up a search engine. I'll tell you about the two
86 ;; search engines currently supported:
90 ;; As always with freeWAIS-sf, you need a so-called `format file'. I
91 ;; use the following file:
94 ;; | # Kai's format file for freeWAIS-sf for indexing mails.
95 ;; | # Each mail is in a file, much like the MH format.
97 ;; | # Document separator should never match -- each file is a document.
98 ;; | record-sep: /^@this regex should never match@$/
100 ;; | # Searchable fields specification.
102 ;; | region: /^[sS]ubject:/ /^[sS]ubject: */
103 ;; | subject "Subject header" stemming TEXT BOTH
106 ;; | region: /^([tT][oO]|[cC][cC]):/ /^([tT][oO]|[cC][cC]): */
107 ;; | to "To and Cc headers" SOUNDEX BOTH
110 ;; | region: /^[fF][rR][oO][mM]:/ /^[fF][rR][oO][mM]: */
111 ;; | from "From header" SOUNDEX BOTH
115 ;; | stemming TEXT GLOBAL
116 ;; | end: /^@this regex should never match@$/
119 ;; 1998-07-22: waisindex would dump core on me for large articles with
120 ;; the above settings. I used /^$/ as the end regex for the global
121 ;; field. That seemed to work okay.
123 ;; There is a Perl module called `WAIS.pm' which is available from
124 ;; CPAN as well as ls6-ftp.cs.uni-dortmund.de:/pub/wais/Perl. This
125 ;; module comes with a nifty tool called `makedb', which I use for
126 ;; indexing. Here's my `makedb.conf':
129 ;; | # Config file for makedb
131 ;; | # Global options
132 ;; | waisindex = /usr/local/bin/waisindex
133 ;; | wais_opt = -stem -t fields
134 ;; | # `-stem' option necessary when `stemming' is specified for the
135 ;; | # global field in the *.fmt file
138 ;; | homedir = /home/kai
140 ;; | # The mail database.
142 ;; | files = `find $homedir/Mail -name \*[0-9] -print`
143 ;; | dbdir = $homedir/.wais
147 ;; The Lisp setup involves the `nnir-wais-*' variables. The most
148 ;; difficult to understand variable is probably
149 ;; `nnir-wais-remove-prefix'. Here's what it does: the output of
150 ;; `waissearch' basically contains the file name and the (full)
151 ;; directory name. As Gnus works with group names rather than
152 ;; directory names, the directory name is transformed into a group
153 ;; name as follows: first, a prefix is removed from the (full)
154 ;; directory name, then all `/' are replaced with `.'. The variable
155 ;; `nnir-wais-remove-prefix' should contain a regex matching exactly
156 ;; this prefix. It defaults to `$HOME/Mail/' (note the trailing
161 ;; The code expects you to have one Glimpse index which contains all
162 ;; your mail files. The Lisp setup involves setting the
163 ;; `nnir-glimpse-*' variables. The most difficult to understand
164 ;; variable is probably `nnir-glimpse-remove-prefix', it corresponds
165 ;; to `nnir-wais-remove-prefix', see above. The `nnir-glimpse-home'
166 ;; variable should be set to the value of the `-H' option which allows
167 ;; one to search this Glimpse index. I have indexed my whole home
168 ;; directory with Glimpse, so I assume a default of `$HOME'.
172 ;; The Namazu backend requires you to have one directory containing all
173 ;; index files, this is controlled by the `nnir-namazu-index-directory'
174 ;; variable. To function the `nnir-namazu-remove-prefix' variable must
175 ;; also be correct, see the documentation for `nnir-wais-remove-prefix'
178 ;; It is particularly important not to pass any any switches to namazu
179 ;; that will change the output format. Good switches to use include
180 ;; `--sort', `--ascending', `--early' and `--late'. Refer to the Namazu
181 ;; documentation for further information on valid switches.
183 ;; To index my mail with the `mknmz' program I use the following
184 ;; configuration file:
187 ;; | package conf; # Don't remove this line!
189 ;; | # Paths which will not be indexed. Don't use `^' or `$' anchors.
190 ;; | $EXCLUDE_PATH = "spam|sent";
192 ;; | # Header fields which should be searchable. case-insensitive
193 ;; | $REMAIN_HEADER = "from|date|message-id|subject";
195 ;; | # Searchable fields. case-insensitive
196 ;; | $SEARCH_FIELD = "from|date|message-id|subject";
198 ;; | # The max length of a word.
199 ;; | $WORD_LENG_MAX = 128;
201 ;; | # The max length of a field.
202 ;; | $MAX_FIELD_LENGTH = 256;
205 ;; My mail is stored in the directories ~/Mail/mail/, ~/Mail/lists/ and
206 ;; ~/Mail/archive/, so to index them I go to the directory set in
207 ;; `nnir-namazu-index-directory' and issue the following command.
209 ;; mknmz --mailnews ~/Mail/archive/ ~/Mail/mail/ ~/Mail/lists/
211 ;; For maximum searching efficiency I have a cron job set to run this
212 ;; command every four hours.
216 ;; The HyREX backend requires you to have one directory from where all
217 ;; your relative paths are to, if you use them. This directory must be
218 ;; set in the `nnir-hyrex-index-directory' variable, which defaults to
219 ;; your home directory. You must also pass the base, class and
220 ;; directory options or simply your dll to the `nnir-hyrex-programm' by
221 ;; setting the `nnir-hyrex-additional-switches' variable accordently.
222 ;; To function the `nnir-hyrex-remove-prefix' variable must also be
223 ;; correct, see the documentation for `nnir-wais-remove-prefix' above.
225 ;; Developer information:
227 ;; I have tried to make the code expandable. Basically, it is divided
228 ;; into two layers. The upper layer is somewhat like the `nnvirtual'
229 ;; or `nnkiboze' backends: given a specification of what articles to
230 ;; show from another backend, it creates a group containing exactly
231 ;; those articles. The lower layer issues a query to a search engine
232 ;; and produces such a specification of what articles to show from the
235 ;; The interface between the two layers consists of the single
236 ;; function `nnir-run-query', which just selects the appropriate
237 ;; function for the search engine one is using. The input to
238 ;; `nnir-run-query' is a string, representing the query as input by
239 ;; the user. The output of `nnir-run-query' is supposed to be a
240 ;; vector, each element of which should in turn be a three-element
241 ;; vector. The first element should be full group name of the article,
242 ;; the second element should be the article number, and the third
243 ;; element should be the Retrieval Status Value (RSV) as returned from
244 ;; the search engine. An RSV is the score assigned to the document by
245 ;; the search engine. For Boolean search engines like Glimpse, the
246 ;; RSV is always 1000 (or 1 or 100, or whatever you like).
248 ;; The sorting order of the articles in the summary buffer created by
249 ;; nnir is based on the order of the articles in the above mentioned
250 ;; vector, so that's where you can do the sorting you'd like. Maybe
251 ;; it would be nice to have a way of displaying the search result
252 ;; sorted differently?
254 ;; So what do you need to do when you want to add another search
255 ;; engine? You write a function that executes the query. Temporary
256 ;; data from the search engine can be put in `nnir-tmp-buffer'. This
257 ;; function should return the list of articles as a vector, as
258 ;; described above. Then, you need to register this backend in
259 ;; `nnir-engines'. Then, users can choose the backend by setting
260 ;; `nnir-search-engine'.
262 ;; Todo, or future ideas:
264 ;; * Make it so that Glimpse can also be called without `-F'.
266 ;; * It should be possible to restrict search to certain groups.
268 ;; * There is currently no error checking.
270 ;; * The summary buffer display is currently really ugly, with all the
271 ;; added information in the subjects. How could I make this
274 ;; * A function which can be called from an nnir summary buffer which
275 ;; teleports you into the group the current article came from and
276 ;; shows you the whole thread this article is part of.
277 ;; Implementation suggestions?
278 ;; (1998-07-24: There is now a preliminary implementation, but
279 ;; it is much too slow and quite fragile.)
281 ;; * Support other mail backends. In particular, probably quite a few
282 ;; people use nnfolder. How would one go about searching nnfolders
283 ;; and producing the right data needed? The group name and the RSV
284 ;; are simple, but what about the article number?
285 ;; - The article number is encoded in the `X-Gnus-Article-Number'
286 ;; header of each mail.
287 ;; - The HyREX engine supports nnfolder.
289 ;; * Support compressed mail files. Probably, just stripping off the
290 ;; `.gz' or `.Z' file name extension is sufficient.
292 ;; * Support a find/grep combination.
294 ;; * At least for imap, the query is performed twice.
297 ;; Have you got other ideas?
303 (require 'gnus-group)
306 (require 'gnus-util))
309 (autoload 'read-kbd-macro "edmacro" nil t))
312 (nnoo-define-basics nnir)
314 (gnus-declare-backend "nnir" 'mail)
316 (defvar nnir-imap-search-field "TEXT"
317 "The IMAP search item when doing an nnir search")
319 (defvar nnir-imap-search-arguments
320 '(("Whole message" . "TEXT")
321 ("Subject" . "SUBJECT")
324 (nil . "HEADER \"%s\""))
325 "Mapping from user readable strings to IMAP search items for use in nnir")
327 (defvar nnir-imap-search-argument-history ()
328 "The history for querying search options in nnir")
330 ;;; Developer Extension Variable:
333 `((glimpse nnir-run-glimpse
334 ((group . "Group spec: ")))
335 (wais nnir-run-waissearch
337 (excite nnir-run-excite-search
341 "Search in: " ; Prompt
342 ,nnir-imap-search-arguments ; alist for completing
344 nil ; allow any user input
346 nnir-imap-search-argument-history ; the history to use
347 ,nnir-imap-search-field ; default
349 (swish++ nnir-run-swish++
350 ((group . "Group spec: ")))
351 (swish-e nnir-run-swish-e
352 ((group . "Group spec: ")))
353 (namazu nnir-run-namazu
355 (hyrex nnir-run-hyrex
356 ((group . "Group spec: "))))
357 "Alist of supported search engines.
358 Each element in the alist is a three-element list (ENGINE FUNCTION ARGS).
359 ENGINE is a symbol designating the searching engine. FUNCTION is also
360 a symbol, giving the function that does the search. The third element
361 ARGS is a list of cons pairs (PARAM . PROMPT). When issuing a query,
362 the FUNCTION will issue a query for each of the PARAMs, using PROMPT.
364 The value of `nnir-search-engine' must be one of the ENGINE symbols.
365 For example, use the following line for searching using freeWAIS-sf:
366 (setq nnir-search-engine 'wais)
367 Use the following line if you read your mail via IMAP and your IMAP
368 server supports searching:
369 (setq nnir-search-engine 'imap)
370 Note that you have to set additional variables for most backends. For
371 example, the `wais' backend needs the variables `nnir-wais-program',
372 `nnir-wais-database' and `nnir-wais-remove-prefix'.
374 Add an entry here when adding a new search engine.")
376 ;;; User Customizable Variables:
379 "Search nnmh and nnml groups in Gnus with Glimpse, freeWAIS-sf, or EWS."
385 ;; If `nil', use server parameters to find out which server to search. CCC
387 (defcustom nnir-mail-backend '(nnml "")
388 "*Specifies which backend should be searched.
389 More precisely, this is used to determine from which backend to fetch the
392 This must be equal to an existing server, so maybe it is best to use
393 something like the following:
394 (setq nnir-mail-backend (nth 0 gnus-secondary-select-methods))
395 The above line works fine if the mail backend you want to search is
396 the first element of gnus-secondary-select-methods (`nth' starts counting
401 ;; Search engine to use.
403 (defcustom nnir-search-engine 'wais
404 "*The search engine to use. Must be a symbol.
405 See `nnir-engines' for a list of supported engines, and for example
406 settings of `nnir-search-engine'."
412 (defcustom nnir-glimpse-program "glimpse"
413 "*Name of Glimpse executable."
417 (defcustom nnir-glimpse-home (getenv "HOME")
418 "*Value of `-H' glimpse option.
419 `~' and environment variables must be expanded, see the functions
420 `expand-file-name' and `substitute-in-file-name'."
424 (defcustom nnir-glimpse-remove-prefix (concat (getenv "HOME") "/Mail/")
425 "*The prefix to remove from each file name returned by Glimpse
426 in order to get a group name (albeit with / instead of .). This is a
429 For example, suppose that Glimpse returns file names such as
430 \"/home/john/Mail/mail/misc/42\". For this example, use the following
431 setting: (setq nnir-glimpse-remove-prefix \"/home/john/Mail/\")
432 Note the trailing slash. Removing this prefix gives \"mail/misc/42\".
433 `nnir' knows to remove the \"/42\" and to replace \"/\" with \".\" to
434 arrive at the correct group name, \"mail.misc\"."
438 (defcustom nnir-glimpse-additional-switches '("-i")
439 "*A list of strings, to be given as additional arguments to glimpse.
440 The switches `-H', `-W', `-l' and `-y' are always used -- calling
441 glimpse without them does not make sense in our situation.
442 Suggested elements to put here are `-i' and `-w'.
444 Note that this should be a list. Ie, do NOT use the following:
445 (setq nnir-glimpse-additional-switches \"-i -w\") ; wrong!
447 (setq nnir-glimpse-additional-switches '(\"-i\" \"-w\"))"
448 :type '(repeat (string))
453 (defcustom nnir-wais-program "waissearch"
454 "*Name of waissearch executable."
458 (defcustom nnir-wais-database (expand-file-name "~/.wais/mail")
459 "*Name of Wais database containing the mail.
461 Note that this should be a file name without extension. For example,
462 if you have a file /home/john/.wais/mail.fmt, use this:
463 (setq nnir-wais-database \"/home/john/.wais/mail\")
464 The string given here is passed to `waissearch -d' as-is."
468 (defcustom nnir-wais-remove-prefix (concat (getenv "HOME") "/Mail/")
469 "*The prefix to remove from each directory name returned by waissearch
470 in order to get a group name (albeit with / instead of .). This is a
473 This variable is similar to `nnir-glimpse-remove-prefix', only for Wais,
478 ;; EWS (Excite for Web Servers) engine.
480 (defcustom nnir-excite-aquery-program "aquery.pl"
481 "*Name of the EWS query program. Should be `aquery.pl' or a path to same."
485 (defcustom nnir-excite-collection "Mail"
486 "*Name of the EWS collection to search."
490 (defcustom nnir-excite-remove-prefix (concat (getenv "HOME") "/Mail/")
491 "*The prefix to remove from each file name returned by EWS
492 in order to get a group name (albeit with / instead of .). This is a
495 This variable is very similar to `nnir-glimpse-remove-prefix', except
496 that it is for EWS, not Glimpse."
500 ;; Swish++. Next three variables Copyright (C) 2000, 2001 Christoph
501 ;; Conrad <christoph.conrad@gmx.de>.
502 ;; Swish++ home page: http://homepage.mac.com/pauljlucas/software/swish/
504 (defcustom nnir-swish++-configuration-file
505 (expand-file-name "~/Mail/swish++.conf")
506 "*Configuration file for swish++."
510 (defcustom nnir-swish++-program "search"
511 "*Name of swish++ search executable."
515 (defcustom nnir-swish++-additional-switches '()
516 "*A list of strings, to be given as additional arguments to swish++.
518 Note that this should be a list. Ie, do NOT use the following:
519 (setq nnir-swish++-additional-switches \"-i -w\") ; wrong
521 (setq nnir-swish++-additional-switches '(\"-i\" \"-w\"))"
522 :type '(repeat (string))
525 (defcustom nnir-swish++-remove-prefix (concat (getenv "HOME") "/Mail/")
526 "*The prefix to remove from each file name returned by swish++
527 in order to get a group name (albeit with / instead of .). This is a
530 This variable is very similar to `nnir-glimpse-remove-prefix', except
531 that it is for swish++, not Glimpse."
535 ;; Swish-E. Next three variables Copyright (C) 2000 Christoph Conrad
536 ;; <christoph.conrad@gmx.de>.
537 ;; URL: http://sunsite.berkeley.edu/SWISH-E/
538 ;; New version: http://www.boe.es/swish-e
540 (defcustom nnir-swish-e-index-file
541 (expand-file-name "~/Mail/index.swish-e")
542 "*Index file for swish-e.
543 This could be a server parameter."
547 (defcustom nnir-swish-e-program "swish-e"
548 "*Name of swish-e search executable.
549 This cannot be a server parameter."
553 (defcustom nnir-swish-e-additional-switches '()
554 "*A list of strings, to be given as additional arguments to swish-e.
556 Note that this should be a list. Ie, do NOT use the following:
557 (setq nnir-swish-e-additional-switches \"-i -w\") ; wrong
559 (setq nnir-swish-e-additional-switches '(\"-i\" \"-w\"))
561 This could be a server parameter."
562 :type '(repeat (string))
565 (defcustom nnir-swish-e-remove-prefix (concat (getenv "HOME") "/Mail/")
566 "*The prefix to remove from each file name returned by swish-e
567 in order to get a group name (albeit with / instead of .). This is a
570 This variable is very similar to `nnir-glimpse-remove-prefix', except
571 that it is for swish-e, not Glimpse.
573 This could be a server parameter."
577 ;; HyREX engine, see <URL:http://ls6-www.cs.uni-dortmund.de/>
579 (defcustom nnir-hyrex-program "nnir-search"
580 "*Name of the nnir-search executable."
584 (defcustom nnir-hyrex-additional-switches '()
585 "*A list of strings, to be given as additional arguments for nnir-search.
586 Note that this should be a list. Ie, do NOT use the following:
587 (setq nnir-hyrex-additional-switches \"-ddl ddl.xml -c nnir\") ; wrong !
589 (setq nnir-hyrex-additional-switches '(\"-ddl\" \"ddl.xml\" \"-c\" \"nnir\"))"
590 :type '(repeat (string))
593 (defcustom nnir-hyrex-index-directory (getenv "HOME")
594 "*Index directory for HyREX."
598 (defcustom nnir-hyrex-remove-prefix (concat (getenv "HOME") "/Mail/")
599 "*The prefix to remove from each file name returned by HyREX
600 in order to get a group name (albeit with / instead of .).
602 For example, suppose that HyREX returns file names such as
603 \"/home/john/Mail/mail/misc/42\". For this example, use the following
604 setting: (setq nnir-hyrex-remove-prefix \"/home/john/Mail/\")
605 Note the trailing slash. Removing this prefix gives \"mail/misc/42\".
606 `nnir' knows to remove the \"/42\" and to replace \"/\" with \".\" to
607 arrive at the correct group name, \"mail.misc\"."
611 ;; Namazu engine, see <URL:http://ww.namazu.org/>
613 (defcustom nnir-namazu-program "namazu"
614 "*Name of Namazu search executable."
618 (defcustom nnir-namazu-index-directory (expand-file-name "~/Mail/namazu/")
619 "*Index directory for Namazu."
623 (defcustom nnir-namazu-additional-switches '()
624 "*A list of strings, to be given as additional arguments to namazu.
625 The switches `-q', `-a', and `-s' are always used, very few other switches
626 make any sense in this context.
628 Note that this should be a list. Ie, do NOT use the following:
629 (setq nnir-namazu-additional-switches \"-i -w\") ; wrong
631 (setq nnir-namazu-additional-switches '(\"-i\" \"-w\"))"
632 :type '(repeat (string))
635 (defcustom nnir-namazu-remove-prefix (concat (getenv "HOME") "/Mail/")
636 "*The prefix to remove from each file name returned by Namazu
637 in order to get a group name (albeit with / instead of .).
639 This variable is very similar to `nnir-glimpse-remove-prefix', except
640 that it is for Namazu, not Glimpse."
644 ;;; Internal Variables:
646 (defvar nnir-current-query nil
647 "Internal: stores current query (= group name).")
649 (defvar nnir-current-server nil
650 "Internal: stores current server (does it ever change?).")
652 (defvar nnir-current-group-marked nil
653 "Internal: stores current list of process-marked groups.")
655 (defvar nnir-artlist nil
656 "Internal: stores search result.")
658 (defvar nnir-tmp-buffer " *nnir*"
659 "Internal: temporary buffer.")
665 (defun gnus-group-make-nnir-group (extra-parms query)
666 "Create an nnir group. Asks for query."
667 (interactive "P\nsQuery: ")
668 (setq nnir-current-query nil
669 nnir-current-server nil
670 nnir-current-group-marked nil
674 (setq parms (nnir-read-parms query))
675 (setq parms (list (cons 'query query))))
676 (gnus-group-read-ephemeral-group
677 (concat "nnir:" (prin1-to-string parms)) '(nnir "") t
678 (cons (current-buffer)
679 gnus-current-window-configuration)
682 ;; Emacs 19 compatibility?
683 (or (fboundp 'kbd) (defalias 'kbd 'read-kbd-macro))
685 (defun nnir-group-mode-hook ()
686 (define-key gnus-group-mode-map
687 (if (fboundp 'read-kbd-macro)
689 "GG") ; XEmacs 19 compat
690 'gnus-group-make-nnir-group))
691 (add-hook 'gnus-group-mode-hook 'nnir-group-mode-hook)
693 (defmacro nnir-group-server (group)
694 "Return the server for a foreign newsgroup GROUP.
695 The returned format is as `gnus-server-to-method' needs it. See
696 `gnus-group-real-prefix' and `gnus-group-real-name'."
697 `(let ((gname ,group))
698 (if (string-match "^\\([^:]+\\):" gname)
699 (setq gname (match-string 1 gname))
701 (if (string-match "^\\([^+]+\\)\\+\\(.+\\)$" gname)
702 (format "%s:%s" (match-string 1 gname) (match-string 2 gname))
703 (concat gname ":"))))
705 ;; Summary mode commands.
707 (defun gnus-summary-nnir-goto-thread ()
708 "Only applies to nnir groups. Go to group this article came from
709 and show thread that contains this article."
711 (unless (eq 'nnir (car (gnus-find-method-for-group gnus-newsgroup-name)))
712 (error "Can't execute this command unless in nnir group."))
713 (let* ((cur (gnus-summary-article-number))
714 (group (nnir-artlist-artitem-group nnir-artlist cur))
715 (backend-number (nnir-artlist-artitem-number nnir-artlist cur))
716 server backend-group)
717 (setq server (nnir-group-server group))
718 (setq backend-group (gnus-group-real-name group))
719 (gnus-group-read-ephemeral-group
721 (gnus-server-to-method server)
723 (cons (current-buffer)
724 'summary) ; window config
726 (list backend-number))
727 (gnus-summary-limit (list backend-number))
728 (gnus-summary-refer-thread)))
730 (if (fboundp 'eval-after-load)
731 (eval-after-load "gnus-sum"
732 '(define-key gnus-summary-goto-map
733 "T" 'gnus-summary-nnir-goto-thread))
734 (add-hook 'gnus-summary-mode-hook
736 (define-key gnus-summary-goto-map
737 "T" 'gnus-summary-nnir-goto-thread)))))
741 ;; Gnus backend interface functions.
743 (deffoo nnir-open-server (server &optional definitions)
744 ;; Just set the server variables appropriately.
745 (nnoo-change-server 'nnir server definitions))
747 (deffoo nnir-request-group (group &optional server fast)
748 "GROUP is the query string."
749 (nnir-possibly-change-server server)
750 ;; Check for cache and return that if appropriate.
751 (if (and (equal group nnir-current-query)
752 (equal gnus-group-marked nnir-current-group-marked)
754 (equal server nnir-current-server)))
757 (setq nnir-artlist (nnir-run-query group)))
759 (set-buffer nntp-server-buffer)
760 (if (zerop (length nnir-artlist))
762 (setq nnir-current-query nil
763 nnir-current-server nil
764 nnir-current-group-marked nil
766 (nnheader-report 'nnir "Search produced empty results."))
767 ;; Remember data for cache.
768 (setq nnir-current-query group)
769 (when server (setq nnir-current-server server))
770 (setq nnir-current-group-marked gnus-group-marked)
771 (nnheader-insert "211 %d %d %d %s\n"
772 (nnir-artlist-length nnir-artlist) ; total #
774 (nnir-artlist-length nnir-artlist) ; last #
775 group)))) ; group name
777 (deffoo nnir-retrieve-headers (articles &optional group server fetch-old)
779 (let ((artlist (copy-sequence articles))
783 (artgroup nil) (artno nil)
790 (while (not (null artlist))
791 (setq art (car artlist))
795 "nnir-retrieve-headers doesn't grok message ids: %s"
797 (setq artitem (nnir-artlist-article nnir-artlist art))
798 (setq artrsv (nnir-artitem-rsv artitem))
799 (setq artfullgroup (nnir-artitem-group artitem))
800 (setq artno (nnir-artitem-number artitem))
801 (setq artgroup (gnus-group-real-name artfullgroup))
802 (setq server (nnir-group-server artfullgroup))
803 ;; retrieve NOV or HEAD data for this article, transform into
804 ;; NOV data and prepend to `novdata'
805 (set-buffer nntp-server-buffer)
806 (nnir-possibly-change-server server)
807 (case (setq foo (gnus-retrieve-headers (list artno) artfullgroup nil))
809 (goto-char (point-min))
810 (setq novitem (nnheader-parse-nov))
812 (pop-to-buffer nntp-server-buffer)
814 "nnheader-parse-nov returned nil for article %s in group %s"
815 artno artfullgroup)))
817 (goto-char (point-min))
818 (setq novitem (nnheader-parse-head))
820 (pop-to-buffer nntp-server-buffer)
822 "nnheader-parse-head returned nil for article %s in group %s"
823 artno artfullgroup)))
824 (t (nnheader-report 'nnir "Don't support header type %s." foo)))
825 ;; replace article number in original group with article number
827 (mail-header-set-number novitem idx)
828 (mail-header-set-from novitem
829 (mail-header-from novitem))
830 (mail-header-set-subject
832 (format "[%d: %s/%d] %s"
833 artrsv artgroup artno
834 (mail-header-subject novitem)))
835 ;;-(mail-header-set-extra novitem nil)
836 (push novitem novdata)
837 (setq artlist (cdr artlist))
839 (setq novdata (nreverse novdata))
840 (set-buffer nntp-server-buffer) (erase-buffer)
841 (mapcar 'nnheader-insert-nov novdata)
844 (deffoo nnir-request-article (article
845 &optional group server to-buffer)
847 (let* ((artitem (nnir-artlist-article nnir-artlist
849 (artfullgroup (nnir-artitem-group artitem))
850 (artno (nnir-artitem-number artitem))
852 ;; Why must we bind nntp-server-buffer here? It won't
853 ;; work if `buf' is used, say. (Of course, the set-buffer
854 ;; line below must then be updated, too.)
855 (nntp-server-buffer (or to-buffer nntp-server-buffer)))
856 (set-buffer nntp-server-buffer)
858 (message "Requesting article %d from group %s"
860 (gnus-request-article artno artfullgroup nntp-server-buffer)
861 (cons artfullgroup artno))))
864 (nnoo-define-skeleton nnir)
866 ;;; Search Engine Interfaces:
868 ;; Glimpse interface.
869 (defun nnir-run-glimpse (query server &optional group)
870 "Run given query against glimpse. Returns a vector of (group name, file name)
871 pairs (also vectors, actually)."
874 (groupspec (cdr (assq 'group query)))
875 (qstring (cdr (assq 'query query)))
876 (prefix (nnir-read-server-parm 'nnir-glimpse-remove-prefix server))
878 (when (and group groupspec)
879 (error (concat "It does not make sense to use a group spec"
880 " with process-marked groups.")))
882 (setq groupspec (gnus-group-real-name group)))
883 (set-buffer (get-buffer-create nnir-tmp-buffer))
886 (message "Doing glimpse query %s on %s..." query groupspec)
887 (message "Doing glimpse query %s..." query))
889 `( ,nnir-glimpse-program
890 nil ; input from /dev/null
892 nil ; don't redisplay
893 "-H" ,(nnir-read-server-parm 'nnir-glimpse-home server) ; search home dir
894 "-W" ; match pattern in file
895 "-l" "-y" ; misc options
896 ,@(nnir-read-server-parm 'nnir-glimpse-additional-switches server)
897 "-F" ,prefix ; restrict output to mail
898 ,qstring ; the query, in glimpse format
902 (message "%s args: %s" nnir-glimpse-program
903 (mapconcat 'identity (cddddr cp-list) " "))
904 (apply 'call-process cp-list))))
905 (unless (or (null exitstatus)
907 (nnheader-report 'nnir "Couldn't run glimpse: %s" exitstatus)
908 ;; Glimpse failure reason is in this buffer, show it if
909 ;; the user wants it.
910 (when (> gnus-verbose 6)
911 (display-buffer nnir-tmp-buffer))))
913 (keep-lines groupspec))
915 (message "Doing glimpse query %s on %s...done" query groupspec)
916 (message "Doing glimpse query %s...done" query))
918 ;; remove superfluous stuff from glimpse output
919 (goto-char (point-min))
920 (delete-non-matching-lines "/[0-9]+$")
921 ;;(delete-matching-lines "\\.overview~?$")
922 (goto-char (point-min))
923 (while (re-search-forward (concat "^" prefix "\\(.+\\)" "/\\([0-9]\\)+$") nil t)
924 ;; replace / with . in group names
925 (setq dirnam (substitute ?. ?/ (match-string 1))
926 artno (match-string 2))
927 (push (vector (nnir-group-full-name dirnam server)
928 (string-to-int artno)) artlist))
931 (function (lambda (x y)
932 (if (string-lessp (nnir-artitem-group x)
933 (nnir-artitem-group y))
935 (< (nnir-artitem-number x)
936 (nnir-artitem-number y))))))
939 ;; freeWAIS-sf interface.
940 (defun nnir-run-waissearch (query server &optional group)
941 "Run given query agains waissearch. Returns vector of (group name, file name)
942 pairs (also vectors, actually)."
944 (error "The freeWAIS-sf backend cannot search specific groups."))
946 (let ((qstring (cdr (assq 'query query)))
947 (prefix (nnir-read-server-parm 'nnir-wais-remove-prefix server))
949 (score nil) (artno nil) (dirnam nil) (group nil))
950 (set-buffer (get-buffer-create nnir-tmp-buffer))
952 (message "Doing WAIS query %s..." query)
953 (call-process nnir-wais-program
954 nil ; input from /dev/null
955 t ; output to current buffer
956 nil ; don't redisplay
957 "-d" (nnir-read-server-parm 'nnir-wais-database server) ; database to search
959 (message "Massaging waissearch output...")
960 ;; remove superfluous lines
961 (keep-lines "Score:")
962 ;; extract data from result lines
963 (goto-char (point-min))
964 (while (re-search-forward
965 "Score: +\\([0-9]+\\).*'\\([0-9]+\\) +\\([^']+\\)/'" nil t)
966 (setq score (match-string 1)
967 artno (match-string 2)
968 dirnam (match-string 3))
969 (unless (string-match prefix dirnam)
970 (nnheader-report 'nnir "Dir name %s doesn't contain prefix %s"
972 (setq group (substitute ?. ?/ (replace-match "" t t dirnam)))
973 (push (vector (nnir-group-full-name group server)
974 (string-to-int artno)
975 (string-to-int score))
977 (message "Massaging waissearch output...done")
980 (function (lambda (x y)
981 (> (nnir-artitem-rsv x)
982 (nnir-artitem-rsv y)))))))))
984 ;; EWS (Excite for Web Servers) interface
985 (defun nnir-run-excite-search (query server &optional group)
986 "Run a given query against EWS. Returns vector of (group name, file name)
987 pairs (also vectors, actually)."
989 (error "Searching specific groups not implemented for EWS."))
991 (let ((qstring (cdr (assq 'query query)))
992 (prefix (nnir-read-server-parm 'nnir-excite-remove-prefix server))
993 artlist group article-num article)
994 (setq nnir-current-query query)
995 (set-buffer (get-buffer-create nnir-tmp-buffer))
997 (message "Doing EWS query %s..." qstring)
998 (call-process nnir-excite-aquery-program
999 nil ; input from /dev/null
1000 t ; output to current buffer
1001 nil ; don't redisplay
1002 (nnir-read-server-parm 'nnir-excite-collection server)
1003 (if (string= (substring qstring 0 1) "(")
1005 (format "(concept %s)" qstring)))
1006 (message "Gathering query output...")
1008 (goto-char (point-min))
1009 (while (re-search-forward
1010 "^[0-9]+\\s-[0-9]+\\s-[0-9]+\\s-\\(\\S-*\\)" nil t)
1011 (setq article (match-string 1))
1012 (unless (string-match
1013 (concat "^" (regexp-quote prefix)
1014 "\\(.*\\)/\\([0-9]+\\)") article)
1015 (nnheader-report 'nnir "Dir name %s doesn't contain prefix %s"
1017 (setq group (substitute ?. ?/ (match-string 1 article)))
1018 (setq group (nnir-group-full-name group server))
1019 (setq article-num (match-string 2 article))
1020 (setq artlist (vconcat artlist (vector (vector group
1021 (string-to-int article-num)
1023 (message "Gathering query output...done")
1026 ;; IMAP interface. The following function is Copyright (C) 1998 Simon
1027 ;; Josefsson <jas@pdc.kth.se>.
1029 ;; nnir invokes this two (2) times???!
1030 ;; we should not use nnimap at all but open our own server connection
1031 ;; we should not LIST * but use nnimap-list-pattern from defs
1032 ;; send queries as literals
1035 (defun nnir-run-imap (query srv &optional group-option)
1039 (let ((qstring (cdr (assq 'query query)))
1040 (server (cadr (gnus-server-to-method srv)))
1041 (group (or group-option (gnus-group-group-name)))
1042 (defs (caddr (gnus-server-to-method srv)))
1043 (criteria (or (cdr (assq 'criteria query))
1044 nnir-imap-search-field))
1046 (message "Opening server %s" server)
1048 (when (nnimap-open-server server defs) ;; xxx
1049 (setq buf nnimap-server-buffer) ;; xxx
1050 (message "Searching %s..." group)
1052 (mbx (gnus-group-real-name group)))
1053 (when (imap-mailbox-select mbx nil buf)
1056 (push (vector group artnum 1) artlist)
1057 (setq arts (1+ arts)))
1058 (imap-search (concat criteria " \"" qstring "\"") buf))
1059 (message "Searching %s... %d matches" mbx arts)))
1060 (message "Searching %s...done" group))
1062 (reverse artlist))))
1064 ;; Swish++ interface. The following function is Copyright (C) 2000,
1065 ;; 2001 Christoph Conrad <christoph.conrad@gmx.de>.
1074 (defun nnir-run-swish++ (query server &optional group)
1075 "Run given query against swish++.
1076 Returns a vector of (group name, file name) pairs (also vectors,
1079 Tested with swish++ 4.7 on GNU/Linux and with with swish++ 5.0b2 on
1083 (error "The swish++ backend cannot search specific groups."))
1086 (let ( (qstring (cdr (assq 'query query)))
1087 (groupspec (cdr (assq 'group query)))
1088 (prefix (nnir-read-server-parm 'nnir-swish++-remove-prefix server))
1090 (score nil) (artno nil) (dirnam nil) (group nil) )
1092 (when (equal "" qstring)
1093 (error "swish++: You didn't enter anything."))
1095 (set-buffer (get-buffer-create nnir-tmp-buffer))
1099 (message "Doing swish++ query %s on %s..." qstring groupspec)
1100 (message "Doing swish++ query %s..." qstring))
1102 (let* ((cp-list `( ,nnir-swish++-program
1103 nil ; input from /dev/null
1105 nil ; don't redisplay
1106 "--config-file" ,(nnir-read-server-parm 'nnir-swish++-configuration-file server)
1107 ,@(nnir-read-server-parm 'nnir-swish++-additional-switches server)
1108 ,qstring ; the query, in swish++ format
1112 (message "%s args: %s" nnir-swish++-program
1113 (mapconcat 'identity (cddddr cp-list) " ")) ;; ???
1114 (apply 'call-process cp-list))))
1115 (unless (or (null exitstatus)
1117 (nnheader-report 'nnir "Couldn't run swish++: %s" exitstatus)
1118 ;; swish++ failure reason is in this buffer, show it if
1119 ;; the user wants it.
1120 (when (> gnus-verbose 6)
1121 (display-buffer nnir-tmp-buffer))))
1123 ;; The results are output in the format of:
1125 ;; rank relative-path-name file-size file-title
1127 ;; rank relative-path-name file-size topic??
1128 ;; where rank is an integer from 1 to 100.
1129 (goto-char (point-min))
1130 (while (re-search-forward
1131 "\\(^[0-9]+\\) \\([^ ]+\\) [0-9]+ \\(.*\\)$" nil t)
1132 (setq score (match-string 1)
1133 artno (file-name-nondirectory (match-string 2))
1134 dirnam (file-name-directory (match-string 2)))
1136 ;; don't match directories
1137 (when (string-match "^[0-9]+$" artno)
1138 (when (not (null dirnam))
1140 ;; maybe limit results to matching groups.
1141 (when (or (not groupspec)
1142 (string-match groupspec dirnam))
1144 ;; remove nnir-swish++-remove-prefix from beginning of dirname
1145 (when (string-match (concat "^" prefix)
1147 (setq dirnam (replace-match "" t t dirnam)))
1149 (setq dirnam (substring dirnam 0 -1))
1150 ;; eliminate all ".", "/", "\" from beginning. Always matches.
1151 (string-match "^[./\\]*\\(.*\\)$" dirnam)
1153 (setq group (substitute ?. ?/ (match-string 1 dirnam)))
1155 (setq group (substitute ?. ?\\ group))
1157 (push (vector (nnir-group-full-name group server)
1158 (string-to-int artno)
1159 (string-to-int score))
1162 (message "Massaging swish++ output...done")
1167 (function (lambda (x y)
1168 (> (nnir-artitem-rsv x)
1169 (nnir-artitem-rsv y)))))))))
1171 ;; Swish-E interface. The following function is Copyright (C) 2000,
1172 ;; 2001 by Christoph Conrad <christoph.conrad@gmx.de>.
1173 (defun nnir-run-swish-e (query server &optional group)
1174 "Run given query against swish-e.
1175 Returns a vector of (group name, file name) pairs (also vectors,
1178 Tested with swish-e-2.0.1 on Windows NT 4.0."
1180 ;; swish-e crashes with empty parameter to "-w" on commandline...
1182 (error "The swish-e backend cannot search specific groups."))
1185 (let ((qstring (cdr (assq 'query query)))
1187 (or (nnir-read-server-parm 'nnir-swish-e-remove-prefix server)
1188 (error "Missing parameter `nnir-swish-e-remove-prefix'")))
1190 (score nil) (artno nil) (dirnam nil) (group nil) )
1192 (when (equal "" qstring)
1193 (error "swish-e: You didn't enter anything."))
1195 (set-buffer (get-buffer-create nnir-tmp-buffer))
1198 (message "Doing swish-e query %s..." query)
1200 (or (nnir-read-server-parm
1201 'nnir-swish-e-index-file server)
1202 (error "Missing parameter `nnir-swish-e-index-file'")))
1203 (additional-switches
1204 (nnir-read-server-parm
1205 'nnir-swish-e-additional-switches server))
1206 (cp-list `(,nnir-swish-e-program
1207 nil ; input from /dev/null
1209 nil ; don't redisplay
1211 ,@additional-switches
1213 ,qstring ; the query, in swish-e format
1217 (message "%s args: %s" nnir-swish-e-program
1218 (mapconcat 'identity (cddddr cp-list) " "))
1219 (apply 'call-process cp-list))))
1220 (unless (or (null exitstatus)
1222 (nnheader-report 'nnir "Couldn't run swish-e: %s" exitstatus)
1223 ;; swish-e failure reason is in this buffer, show it if
1224 ;; the user wants it.
1225 (when (> gnus-verbose 6)
1226 (display-buffer nnir-tmp-buffer))))
1228 ;; The results are output in the format of:
1229 ;; rank path-name file-title file-size
1230 (goto-char (point-min))
1231 (while (re-search-forward
1232 "\\(^[0-9]+\\) \\([^ ]+\\) \"\\([^\"]+\\)\" [0-9]+$" nil t)
1233 (setq score (match-string 1)
1234 artno (match-string 3)
1235 dirnam (file-name-directory (match-string 2)))
1237 ;; don't match directories
1238 (when (string-match "^[0-9]+$" artno)
1239 (when (not (null dirnam))
1241 ;; remove nnir-swish-e-remove-prefix from beginning of dirname
1242 (when (string-match (concat "^" prefix) dirnam)
1243 (setq dirnam (replace-match "" t t dirnam)))
1245 (setq dirnam (substring dirnam 0 -1))
1246 ;; eliminate all ".", "/", "\" from beginning. Always matches.
1247 (string-match "^[./\\]*\\(.*\\)$" dirnam)
1249 (setq group (substitute ?. ?/ (match-string 1 dirnam)))
1250 ;; Windows "\\" -> "."
1251 (setq group (substitute ?. ?\\ group))
1253 (push (vector (nnir-group-full-name group server)
1254 (string-to-int artno)
1255 (string-to-int score))
1258 (message "Massaging swish-e output...done")
1263 (function (lambda (x y)
1264 (> (nnir-artitem-rsv x)
1265 (nnir-artitem-rsv y)))))))))
1268 (defun nnir-run-hyrex (query server &optional group)
1271 (groupspec (cdr (assq 'group query)))
1272 (qstring (cdr (assq 'query query)))
1273 (prefix (nnir-read-server-parm 'nnir-hyrex-remove-prefix server))
1275 (when (and group groupspec)
1276 (error (concat "It does not make sense to use a group spec"
1277 " with process-marked groups.")))
1279 (setq groupspec (gnus-group-real-name group)))
1280 (when (and group (not (equal group (nnir-group-full-name groupspec server))))
1281 (message "%s vs. %s" group (nnir-group-full-name groupspec server))
1282 (error "Server with groupspec doesn't match group !"))
1283 (set-buffer (get-buffer-create nnir-tmp-buffer))
1286 (message "Doing hyrex-search query %s on %s..." query groupspec)
1287 (message "Doing hyrex-search query %s..." query))
1289 `( ,nnir-hyrex-program
1290 nil ; input from /dev/null
1292 nil ; don't redisplay
1293 "-i",(nnir-read-server-parm 'nnir-hyrex-index-directory server) ; index directory
1294 ,@(nnir-read-server-parm 'nnir-hyrex-additional-switches server)
1295 ,qstring ; the query, in hyrex-search format
1299 (message "%s args: %s" nnir-hyrex-program
1300 (mapconcat 'identity (cddddr cp-list) " "))
1301 (apply 'call-process cp-list))))
1302 (unless (or (null exitstatus)
1304 (nnheader-report 'nnir "Couldn't run hyrex-search: %s" exitstatus)
1305 ;; nnir-search failure reason is in this buffer, show it if
1306 ;; the user wants it.
1307 (when (> gnus-verbose 6)
1308 (display-buffer nnir-tmp-buffer)))) ;; FIXME: Dont clear buffer !
1310 (message "Doing hyrex-search query \"%s\" on %s...done" qstring groupspec)
1311 (message "Doing hyrex-search query \"%s\"...done" qstring))
1313 ;; nnir-search returns:
1314 ;; for nnml/nnfolder: "filename mailid weigth"
1315 ;; for nnimap: "group mailid weigth"
1316 (goto-char (point-min))
1317 (delete-non-matching-lines "^\\S + [0-9]+ [0-9]+$")
1318 ;; HyREX couldn't search directly in groups -- so filter out here.
1320 (keep-lines groupspec))
1321 ;; extract data from result lines
1322 (goto-char (point-min))
1323 (while (re-search-forward
1324 "\\(\\S +\\) \\([0-9]+\\) \\([0-9]+\\)" nil t)
1325 (setq dirnam (match-string 1)
1326 artno (match-string 2)
1327 score (match-string 3))
1328 (when (string-match prefix dirnam)
1329 (setq dirnam (replace-match "" t t dirnam)))
1330 (push (vector (nnir-group-full-name (substitute ?. ?/ dirnam) server)
1331 (string-to-int artno)
1332 (string-to-int score))
1334 (message "Massaging hyrex-search output...done.")
1337 (function (lambda (x y)
1338 (if (string-lessp (nnir-artitem-group x)
1339 (nnir-artitem-group y))
1341 (< (nnir-artitem-number x)
1342 (nnir-artitem-number y)))))))
1346 (defun nnir-run-namazu (query server &optional group)
1347 "Run given query against Namazu. Returns a vector of (group name, file name)
1348 pairs (also vectors, actually).
1350 Tested with Namazu 2.0.6 on a GNU/Linux system."
1352 (error "The Namazu backend cannot search specific groups"))
1356 (qstring (cdr (assq 'query query)))
1357 (prefix (nnir-read-server-parm 'nnir-namazu-remove-prefix server))
1361 (process-environment (copy-sequence process-environment))
1363 (setenv "LC_MESSAGES" "C")
1364 (set-buffer (get-buffer-create nnir-tmp-buffer))
1367 `( ,nnir-namazu-program
1368 nil ; input from /dev/null
1370 nil ; don't redisplay
1371 "-q" ; don't be verbose
1372 "-a" ; show all matches
1373 "-s" ; use short format
1374 ,@(nnir-read-server-parm 'nnir-namazu-additional-switches server)
1375 ,qstring ; the query, in namazu format
1376 ,(nnir-read-server-parm 'nnir-namazu-index-directory server) ; index directory
1380 (message "%s args: %s" nnir-namazu-program
1381 (mapconcat 'identity (cddddr cp-list) " "))
1382 (apply 'call-process cp-list))))
1383 (unless (or (null exitstatus)
1385 (nnheader-report 'nnir "Couldn't run namazu: %s" exitstatus)
1386 ;; Namazu failure reason is in this buffer, show it if
1387 ;; the user wants it.
1388 (when (> gnus-verbose 6)
1389 (display-buffer nnir-tmp-buffer))))
1391 ;; Namazu output looks something like this:
1392 ;; 2. Re: Gnus agent expire broken (score: 55)
1393 ;; /home/henrik/Mail/mail/sent/1310 (4,138 bytes)
1395 (goto-char (point-min))
1396 (while (re-search-forward
1397 "^\\([0-9]+\\.\\).*\\((score: \\([0-9]+\\)\\))\n\\([^ ]+\\)"
1399 (setq score (match-string 3)
1400 group (file-name-directory (match-string 4))
1401 article (file-name-nondirectory (match-string 4)))
1403 ;; make sure article and group is sane
1404 (when (and (string-match "^[0-9]+$" article)
1406 (when (string-match (concat "^" prefix) group)
1407 (setq group (replace-match "" t t group)))
1409 ;; remove trailing slash from groupname
1410 (setq group (substring group 0 -1))
1412 ;; stuff results into artlist vector
1413 (push (vector (nnir-group-full-name (substitute ?. ?/ group) server)
1414 (string-to-int article)
1415 (string-to-int score)) artlist)))
1417 ;; sort artlist by score
1420 (function (lambda (x y)
1421 (> (nnir-artitem-rsv x)
1422 (nnir-artitem-rsv y)))))))))
1426 (defun nnir-read-parms (query)
1427 "Reads additional search parameters according to `nnir-engines'."
1428 (let ((parmspec (caddr (assoc nnir-search-engine nnir-engines))))
1429 (cons (cons 'query query)
1430 (mapcar 'nnir-read-parm parmspec))))
1432 (defun nnir-read-parm (parmspec)
1433 "Reads a single search parameter.
1434 `parmspec' is a cons cell, the car is a symbol, the cdr is a prompt."
1435 (let ((sym (car parmspec))
1436 (prompt (cdr parmspec)))
1438 (let* ((result (apply 'completing-read prompt))
1439 (mapping (or (assoc result nnir-imap-search-arguments)
1440 (assoc nil nnir-imap-search-arguments))))
1441 (cons sym (format (cdr mapping) result)))
1442 (cons sym (read-string prompt)))))
1444 (defun nnir-run-query (query)
1445 "Invoke appropriate search engine function (see `nnir-engines').
1446 If some groups were process-marked, run the query for each of the groups
1447 and concat the results."
1448 (let ((q (car (read-from-string query))))
1449 (if gnus-group-marked
1452 (let ((server (nnir-group-server x))
1454 (setq search-func (cadr
1456 (nnir-read-server-parm 'nnir-search-engine server) nnir-engines)))
1458 (funcall search-func q server x)
1464 (if (and (equal (cadr x) 'ok) (not (equal (cadar x) "-ephemeral")))
1465 (let ((server (format "%s:%s" (caar x) (cadar x)))
1467 (setq search-func (cadr
1469 (nnir-read-server-parm 'nnir-search-engine server) nnir-engines)))
1471 (funcall search-func q server nil)
1474 gnus-opened-servers)
1478 (defun nnir-read-server-parm (key server)
1479 "Returns the parameter value of for the given server, where server is of
1480 form 'backend:name'."
1481 (let ((method (gnus-server-to-method server)))
1482 (cond ((and method (assq key (cddr method)))
1483 (nth 1 (assq key (cddr method))))
1484 ((and nnir-mail-backend
1485 (gnus-method-equal method nnir-mail-backend))
1487 ((null nnir-mail-backend)
1491 ;; (if (assq key (cddr method))
1492 ;; (nth 1 (assq key (cddr method)))
1493 ;; (symbol-value key))
1494 ;; (symbol-value key))
1497 (defun nnir-group-full-name (shortname server)
1498 "For the given group name, return a full Gnus group name.
1499 The Gnus backend/server information is added."
1500 (gnus-group-prefixed-name shortname (gnus-server-to-method server)))
1502 (defun nnir-possibly-change-server (server)
1503 (unless (and server (nnir-server-opened server))
1504 (nnir-open-server server)))
1507 ;; Data type article list.
1509 (defun nnir-artlist-length (artlist)
1510 "Returns number of articles in artlist."
1513 (defun nnir-artlist-article (artlist n)
1514 "Returns from ARTLIST the Nth artitem (counting starting at 1)."
1515 (elt artlist (1- n)))
1517 (defun nnir-artitem-group (artitem)
1518 "Returns the group from the ARTITEM."
1521 (defun nnir-artlist-artitem-group (artlist n)
1522 "Returns from ARTLIST the group of the Nth artitem (counting from 1)."
1523 (nnir-artitem-group (nnir-artlist-article artlist n)))
1525 (defun nnir-artitem-number (artitem)
1526 "Returns the number from the ARTITEM."
1529 (defun nnir-artlist-artitem-number (artlist n)
1530 "Returns from ARTLIST the number of the Nth artitem (counting from 1)."
1531 (nnir-artitem-number (nnir-artlist-article artlist n)))
1533 (defun nnir-artitem-rsv (artitem)
1534 "Returns the Retrieval Status Value (RSV, score) from the ARTITEM."
1537 (defun nnir-artlist-artitem-rsv (artlist n)
1538 "Returns from ARTLIST the Retrieval Status Value of the Nth artitem
1540 (nnir-artitem-rsv (nnir-artlist-article artlist n)))
1543 (defun nnir-artlist-groups (artlist)
1544 "Returns a list of all groups in the given ARTLIST."
1547 ;; from each artitem, extract group component
1548 (setq with-dups (mapcar 'nnir-artitem-group artlist))
1549 ;; remove duplicates from above
1550 (mapcar (function (lambda (x) (add-to-list 'res x)))