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?
301 (defconst nnir-version "$Id: nnir.el,v 1.1.6.1.4.3 2004-04-05 23:08:14 yamaoka Exp $"
306 (require 'gnus-group)
309 (require 'gnus-util))
312 (autoload 'read-kbd-macro "edmacro" nil t))
315 (nnoo-define-basics nnir)
317 (gnus-declare-backend "nnir" 'mail)
319 (defvar nnir-imap-search-field "TEXT"
320 "The IMAP search item when doing an nnir search")
322 (defvar nnir-imap-search-arguments
323 '(("Whole message" . "TEXT")
324 ("Subject" . "SUBJECT")
327 (nil . "HEADER \"%s\""))
328 "Mapping from user readable strings to IMAP search items for use in nnir")
330 (defvar nnir-imap-search-argument-history ()
331 "The history for querying search options in nnir")
333 ;;; Developer Extension Variable:
336 `((glimpse nnir-run-glimpse
337 ((group . "Group spec: ")))
338 (wais nnir-run-waissearch
340 (excite nnir-run-excite-search
344 "Search in: " ; Prompt
345 ,nnir-imap-search-arguments ; alist for completing
347 nil ; allow any user input
349 nnir-imap-search-argument-history ; the history to use
350 ,nnir-imap-search-field ; default
352 (swish++ nnir-run-swish++
353 ((group . "Group spec: ")))
354 (swish-e nnir-run-swish-e
355 ((group . "Group spec: ")))
356 (namazu nnir-run-namazu
358 (hyrex nnir-run-hyrex
359 ((group . "Group spec: "))))
360 "Alist of supported search engines.
361 Each element in the alist is a three-element list (ENGINE FUNCTION ARGS).
362 ENGINE is a symbol designating the searching engine. FUNCTION is also
363 a symbol, giving the function that does the search. The third element
364 ARGS is a list of cons pairs (PARAM . PROMPT). When issuing a query,
365 the FUNCTION will issue a query for each of the PARAMs, using PROMPT.
367 The value of `nnir-search-engine' must be one of the ENGINE symbols.
368 For example, use the following line for searching using freeWAIS-sf:
369 (setq nnir-search-engine 'wais)
370 Use the following line if you read your mail via IMAP and your IMAP
371 server supports searching:
372 (setq nnir-search-engine 'imap)
373 Note that you have to set additional variables for most backends. For
374 example, the `wais' backend needs the variables `nnir-wais-program',
375 `nnir-wais-database' and `nnir-wais-remove-prefix'.
377 Add an entry here when adding a new search engine.")
379 ;;; User Customizable Variables:
382 "Search nnmh and nnml groups in Gnus with Glimpse, freeWAIS-sf, or EWS.")
387 ;; If `nil', use server parameters to find out which server to search. CCC
389 (defcustom nnir-mail-backend '(nnml "")
390 "*Specifies which backend should be searched.
391 More precisely, this is used to determine from which backend to fetch the
394 This must be equal to an existing server, so maybe it is best to use
395 something like the following:
396 (setq nnir-mail-backend (nth 0 gnus-secondary-select-methods))
397 The above line works fine if the mail backend you want to search is
398 the first element of gnus-secondary-select-methods (`nth' starts counting
403 ;; Search engine to use.
405 (defcustom nnir-search-engine 'wais
406 "*The search engine to use. Must be a symbol.
407 See `nnir-engines' for a list of supported engines, and for example
408 settings of `nnir-search-engine'."
414 (defcustom nnir-glimpse-program "glimpse"
415 "*Name of Glimpse executable."
419 (defcustom nnir-glimpse-home (getenv "HOME")
420 "*Value of `-H' glimpse option.
421 `~' and environment variables must be expanded, see the functions
422 `expand-file-name' and `substitute-in-file-name'."
426 (defcustom nnir-glimpse-remove-prefix (concat (getenv "HOME") "/Mail/")
427 "*The prefix to remove from each file name returned by Glimpse
428 in order to get a group name (albeit with / instead of .). This is a
431 For example, suppose that Glimpse returns file names such as
432 \"/home/john/Mail/mail/misc/42\". For this example, use the following
433 setting: (setq nnir-glimpse-remove-prefix \"/home/john/Mail/\")
434 Note the trailing slash. Removing this prefix gives \"mail/misc/42\".
435 `nnir' knows to remove the \"/42\" and to replace \"/\" with \".\" to
436 arrive at the correct group name, \"mail.misc\"."
440 (defcustom nnir-glimpse-additional-switches '("-i")
441 "*A list of strings, to be given as additional arguments to glimpse.
442 The switches `-H', `-W', `-l' and `-y' are always used -- calling
443 glimpse without them does not make sense in our situation.
444 Suggested elements to put here are `-i' and `-w'.
446 Note that this should be a list. Ie, do NOT use the following:
447 (setq nnir-glimpse-additional-switches \"-i -w\") ; wrong!
449 (setq nnir-glimpse-additional-switches '(\"-i\" \"-w\"))"
450 :type '(repeat (string))
455 (defcustom nnir-wais-program "waissearch"
456 "*Name of waissearch executable."
460 (defcustom nnir-wais-database (expand-file-name "~/.wais/mail")
461 "*Name of Wais database containing the mail.
463 Note that this should be a file name without extension. For example,
464 if you have a file /home/john/.wais/mail.fmt, use this:
465 (setq nnir-wais-database \"/home/john/.wais/mail\")
466 The string given here is passed to `waissearch -d' as-is."
470 (defcustom nnir-wais-remove-prefix (concat (getenv "HOME") "/Mail/")
471 "*The prefix to remove from each directory name returned by waissearch
472 in order to get a group name (albeit with / instead of .). This is a
475 This variable is similar to `nnir-glimpse-remove-prefix', only for Wais,
480 ;; EWS (Excite for Web Servers) engine.
482 (defcustom nnir-excite-aquery-program "aquery.pl"
483 "*Name of the EWS query program. Should be `aquery.pl' or a path to same."
487 (defcustom nnir-excite-collection "Mail"
488 "*Name of the EWS collection to search."
492 (defcustom nnir-excite-remove-prefix (concat (getenv "HOME") "/Mail/")
493 "*The prefix to remove from each file name returned by EWS
494 in order to get a group name (albeit with / instead of .). This is a
497 This variable is very similar to `nnir-glimpse-remove-prefix', except
498 that it is for EWS, not Glimpse."
502 ;; Swish++. Next three variables Copyright (C) 2000, 2001 Christoph
503 ;; Conrad <christoph.conrad@gmx.de>.
504 ;; Swish++ home page: http://homepage.mac.com/pauljlucas/software/swish/
506 (defcustom nnir-swish++-configuration-file
507 (expand-file-name "~/Mail/swish++.conf")
508 "*Configuration file for swish++."
512 (defcustom nnir-swish++-program "search"
513 "*Name of swish++ search executable."
517 (defcustom nnir-swish++-additional-switches '()
518 "*A list of strings, to be given as additional arguments to swish++.
520 Note that this should be a list. Ie, do NOT use the following:
521 (setq nnir-swish++-additional-switches \"-i -w\") ; wrong
523 (setq nnir-swish++-additional-switches '(\"-i\" \"-w\"))"
524 :type '(repeat (string))
527 (defcustom nnir-swish++-remove-prefix (concat (getenv "HOME") "/Mail/")
528 "*The prefix to remove from each file name returned by swish++
529 in order to get a group name (albeit with / instead of .). This is a
532 This variable is very similar to `nnir-glimpse-remove-prefix', except
533 that it is for swish++, not Glimpse."
537 ;; Swish-E. Next three variables Copyright (C) 2000 Christoph Conrad
538 ;; <christoph.conrad@gmx.de>.
539 ;; URL: http://sunsite.berkeley.edu/SWISH-E/
540 ;; New version: http://www.boe.es/swish-e
542 (defcustom nnir-swish-e-index-file
543 (expand-file-name "~/Mail/index.swish-e")
544 "*Index file for swish-e.
545 This could be a server parameter."
549 (defcustom nnir-swish-e-program "swish-e"
550 "*Name of swish-e search executable.
551 This cannot be a server parameter."
555 (defcustom nnir-swish-e-additional-switches '()
556 "*A list of strings, to be given as additional arguments to swish-e.
558 Note that this should be a list. Ie, do NOT use the following:
559 (setq nnir-swish-e-additional-switches \"-i -w\") ; wrong
561 (setq nnir-swish-e-additional-switches '(\"-i\" \"-w\"))
563 This could be a server parameter."
564 :type '(repeat (string))
567 (defcustom nnir-swish-e-remove-prefix (concat (getenv "HOME") "/Mail/")
568 "*The prefix to remove from each file name returned by swish-e
569 in order to get a group name (albeit with / instead of .). This is a
572 This variable is very similar to `nnir-glimpse-remove-prefix', except
573 that it is for swish-e, not Glimpse.
575 This could be a server parameter."
579 ;; HyREX engine, see <URL:http://ls6-www.cs.uni-dortmund.de/>
581 (defcustom nnir-hyrex-program "nnir-search"
582 "*Name of the nnir-search executable."
586 (defcustom nnir-hyrex-additional-switches '()
587 "*A list of strings, to be given as additional arguments for nnir-search.
588 Note that this should be a list. Ie, do NOT use the following:
589 (setq nnir-hyrex-additional-switches \"-ddl ddl.xml -c nnir\") ; wrong !
591 (setq nnir-hyrex-additional-switches '(\"-ddl\" \"ddl.xml\" \"-c\" \"nnir\"))"
592 :type '(repeat (string))
595 (defcustom nnir-hyrex-index-directory (getenv "HOME")
596 "*Index directory for HyREX."
600 (defcustom nnir-hyrex-remove-prefix (concat (getenv "HOME") "/Mail/")
601 "*The prefix to remove from each file name returned by HyREX
602 in order to get a group name (albeit with / instead of .).
604 For example, suppose that HyREX returns file names such as
605 \"/home/john/Mail/mail/misc/42\". For this example, use the following
606 setting: (setq nnir-hyrex-remove-prefix \"/home/john/Mail/\")
607 Note the trailing slash. Removing this prefix gives \"mail/misc/42\".
608 `nnir' knows to remove the \"/42\" and to replace \"/\" with \".\" to
609 arrive at the correct group name, \"mail.misc\"."
613 ;; Namazu engine, see <URL:http://ww.namazu.org/>
615 (defcustom nnir-namazu-program "namazu"
616 "*Name of Namazu search executable."
620 (defcustom nnir-namazu-index-directory (expand-file-name "~/Mail/namazu/")
621 "*Index directory for Namazu."
625 (defcustom nnir-namazu-additional-switches '()
626 "*A list of strings, to be given as additional arguments to namazu.
627 The switches `-q', `-a', and `-s' are always used, very few other switches
628 make any sense in this context.
630 Note that this should be a list. Ie, do NOT use the following:
631 (setq nnir-namazu-additional-switches \"-i -w\") ; wrong
633 (setq nnir-namazu-additional-switches '(\"-i\" \"-w\"))"
634 :type '(repeat (string))
637 (defcustom nnir-namazu-remove-prefix (concat (getenv "HOME") "/Mail/")
638 "*The prefix to remove from each file name returned by Namazu
639 in order to get a group name (albeit with / instead of .).
641 This variable is very similar to `nnir-glimpse-remove-prefix', except
642 that it is for Namazu, not Glimpse."
646 ;;; Internal Variables:
648 (defvar nnir-current-query nil
649 "Internal: stores current query (= group name).")
651 (defvar nnir-current-server nil
652 "Internal: stores current server (does it ever change?).")
654 (defvar nnir-current-group-marked nil
655 "Internal: stores current list of process-marked groups.")
657 (defvar nnir-artlist nil
658 "Internal: stores search result.")
660 (defvar nnir-tmp-buffer " *nnir*"
661 "Internal: temporary buffer.")
667 (defun gnus-group-make-nnir-group (extra-parms query)
668 "Create an nnir group. Asks for query."
669 (interactive "P\nsQuery: ")
670 (setq nnir-current-query nil
671 nnir-current-server nil
672 nnir-current-group-marked nil
676 (setq parms (nnir-read-parms query))
677 (setq parms (list (cons 'query query))))
678 (gnus-group-read-ephemeral-group
679 (concat "nnir:" (prin1-to-string parms)) '(nnir "") t
680 (cons (current-buffer)
681 gnus-current-window-configuration)
684 ;; Emacs 19 compatibility?
685 (or (fboundp 'kbd) (defalias 'kbd 'read-kbd-macro))
687 (defun nnir-group-mode-hook ()
688 (define-key gnus-group-mode-map
689 (if (fboundp 'read-kbd-macro)
691 "GG") ; XEmacs 19 compat
692 'gnus-group-make-nnir-group))
693 (add-hook 'gnus-group-mode-hook 'nnir-group-mode-hook)
695 (defmacro nnir-group-server (group)
696 "Return the server for a foreign newsgroup GROUP.
697 The returned format is as `gnus-server-to-method' needs it. See
698 `gnus-group-real-prefix' and `gnus-group-real-name'."
699 `(let ((gname ,group))
700 (if (string-match "^\\([^:]+\\):" gname)
701 (setq gname (match-string 1 gname))
703 (if (string-match "^\\([^+]+\\)\\+\\(.+\\)$" gname)
704 (format "%s:%s" (match-string 1 gname) (match-string 2 gname))
705 (concat gname ":"))))
707 ;; Summary mode commands.
709 (defun gnus-summary-nnir-goto-thread ()
710 "Only applies to nnir groups. Go to group this article came from
711 and show thread that contains this article."
713 (unless (eq 'nnir (car (gnus-find-method-for-group gnus-newsgroup-name)))
714 (error "Can't execute this command unless in nnir group."))
715 (let* ((cur (gnus-summary-article-number))
716 (group (nnir-artlist-artitem-group nnir-artlist cur))
717 (backend-number (nnir-artlist-artitem-number nnir-artlist cur))
718 server backend-group)
719 (setq server (nnir-group-server group))
720 (setq backend-group (gnus-group-real-name group))
721 (gnus-group-read-ephemeral-group
723 (gnus-server-to-method server)
725 (cons (current-buffer)
726 'summary) ; window config
728 (list backend-number))
729 (gnus-summary-limit (list backend-number))
730 (gnus-summary-refer-thread)))
732 (if (fboundp 'eval-after-load)
733 (eval-after-load "gnus-sum"
734 '(define-key gnus-summary-goto-map
735 "T" 'gnus-summary-nnir-goto-thread))
736 (add-hook 'gnus-summary-mode-hook
738 (define-key gnus-summary-goto-map
739 "T" 'gnus-summary-nnir-goto-thread)))))
743 ;; Gnus backend interface functions.
745 (deffoo nnir-open-server (server &optional definitions)
746 ;; Just set the server variables appropriately.
747 (nnoo-change-server 'nnir server definitions))
749 (deffoo nnir-request-group (group &optional server fast)
750 "GROUP is the query string."
751 (nnir-possibly-change-server server)
752 ;; Check for cache and return that if appropriate.
753 (if (and (equal group nnir-current-query)
754 (equal gnus-group-marked nnir-current-group-marked)
756 (equal server nnir-current-server)))
759 (setq nnir-artlist (nnir-run-query group)))
761 (set-buffer nntp-server-buffer)
762 (if (zerop (length nnir-artlist))
764 (setq nnir-current-query nil
765 nnir-current-server nil
766 nnir-current-group-marked nil
768 (nnheader-report 'nnir "Search produced empty results."))
769 ;; Remember data for cache.
770 (setq nnir-current-query group)
771 (when server (setq nnir-current-server server))
772 (setq nnir-current-group-marked gnus-group-marked)
773 (nnheader-insert "211 %d %d %d %s\n"
774 (nnir-artlist-length nnir-artlist) ; total #
776 (nnir-artlist-length nnir-artlist) ; last #
777 group)))) ; group name
779 (deffoo nnir-retrieve-headers (articles &optional group server fetch-old)
781 (let ((artlist (copy-sequence articles))
785 (artgroup nil) (artno nil)
792 (while (not (null artlist))
793 (setq art (car artlist))
797 "nnir-retrieve-headers doesn't grok message ids: %s"
799 (setq artitem (nnir-artlist-article nnir-artlist art))
800 (setq artrsv (nnir-artitem-rsv artitem))
801 (setq artfullgroup (nnir-artitem-group artitem))
802 (setq artno (nnir-artitem-number artitem))
803 (setq artgroup (gnus-group-real-name artfullgroup))
804 (setq server (nnir-group-server artfullgroup))
805 ;; retrieve NOV or HEAD data for this article, transform into
806 ;; NOV data and prepend to `novdata'
807 (set-buffer nntp-server-buffer)
808 (nnir-possibly-change-server server)
809 (case (setq foo (gnus-retrieve-headers (list artno) artfullgroup nil))
811 (goto-char (point-min))
812 (setq novitem (nnheader-parse-nov))
814 (pop-to-buffer nntp-server-buffer)
816 "nnheader-parse-nov returned nil for article %s in group %s"
817 artno artfullgroup)))
819 (goto-char (point-min))
820 (setq novitem (nnheader-parse-head))
822 (pop-to-buffer nntp-server-buffer)
824 "nnheader-parse-head returned nil for article %s in group %s"
825 artno artfullgroup)))
826 (t (nnheader-report 'nnir "Don't support header type %s." foo)))
827 ;; replace article number in original group with article number
829 (mail-header-set-number novitem idx)
830 (mail-header-set-from novitem
831 (mail-header-from novitem))
832 (mail-header-set-subject
834 (format "[%d: %s/%d] %s"
835 artrsv artgroup artno
836 (mail-header-subject novitem)))
837 ;;-(mail-header-set-extra novitem nil)
838 (push novitem novdata)
839 (setq artlist (cdr artlist))
841 (setq novdata (nreverse novdata))
842 (set-buffer nntp-server-buffer) (erase-buffer)
843 (mapcar 'nnheader-insert-nov novdata)
846 (deffoo nnir-request-article (article
847 &optional group server to-buffer)
849 (let* ((artitem (nnir-artlist-article nnir-artlist
851 (artfullgroup (nnir-artitem-group artitem))
852 (artno (nnir-artitem-number artitem))
854 ;; Why must we bind nntp-server-buffer here? It won't
855 ;; work if `buf' is used, say. (Of course, the set-buffer
856 ;; line below must then be updated, too.)
857 (nntp-server-buffer (or to-buffer nntp-server-buffer)))
858 (set-buffer nntp-server-buffer)
860 (message "Requesting article %d from group %s"
862 (gnus-request-article artno artfullgroup nntp-server-buffer)
863 (cons artfullgroup artno))))
866 (nnoo-define-skeleton nnir)
868 ;;; Search Engine Interfaces:
870 ;; Glimpse interface.
871 (defun nnir-run-glimpse (query server &optional group)
872 "Run given query against glimpse. Returns a vector of (group name, file name)
873 pairs (also vectors, actually)."
876 (groupspec (cdr (assq 'group query)))
877 (qstring (cdr (assq 'query query)))
878 (prefix (nnir-read-server-parm 'nnir-glimpse-remove-prefix server))
880 (when (and group groupspec)
881 (error (concat "It does not make sense to use a group spec"
882 " with process-marked groups.")))
884 (setq groupspec (gnus-group-real-name group)))
885 (set-buffer (get-buffer-create nnir-tmp-buffer))
888 (message "Doing glimpse query %s on %s..." query groupspec)
889 (message "Doing glimpse query %s..." query))
891 `( ,nnir-glimpse-program
892 nil ; input from /dev/null
894 nil ; don't redisplay
895 "-H" ,(nnir-read-server-parm 'nnir-glimpse-home server) ; search home dir
896 "-W" ; match pattern in file
897 "-l" "-y" ; misc options
898 ,@(nnir-read-server-parm 'nnir-glimpse-additional-switches server)
899 "-F" ,prefix ; restrict output to mail
900 ,qstring ; the query, in glimpse format
904 (message "%s args: %s" nnir-glimpse-program
905 (mapconcat 'identity (cddddr cp-list) " "))
906 (apply 'call-process cp-list))))
907 (unless (or (null exitstatus)
909 (nnheader-report 'nnir "Couldn't run glimpse: %s" exitstatus)
910 ;; Glimpse failure reason is in this buffer, show it if
911 ;; the user wants it.
912 (when (> gnus-verbose 6)
913 (display-buffer nnir-tmp-buffer))))
915 (keep-lines groupspec))
917 (message "Doing glimpse query %s on %s...done" query groupspec)
918 (message "Doing glimpse query %s...done" query))
920 ;; remove superfluous stuff from glimpse output
921 (goto-char (point-min))
922 (delete-non-matching-lines "/[0-9]+$")
923 ;;(delete-matching-lines "\\.overview~?$")
924 (goto-char (point-min))
925 (while (re-search-forward (concat "^" prefix "\\(.+\\)" "/\\([0-9]\\)+$") nil t)
926 ;; replace / with . in group names
927 (setq dirnam (substitute ?. ?/ (match-string 1))
928 artno (match-string 2))
929 (push (vector (nnir-group-full-name dirnam server)
930 (string-to-int artno)) artlist))
933 (function (lambda (x y)
934 (if (string-lessp (nnir-artitem-group x)
935 (nnir-artitem-group y))
937 (< (nnir-artitem-number x)
938 (nnir-artitem-number y))))))
941 ;; freeWAIS-sf interface.
942 (defun nnir-run-waissearch (query server &optional group)
943 "Run given query agains waissearch. Returns vector of (group name, file name)
944 pairs (also vectors, actually)."
946 (error "The freeWAIS-sf backend cannot search specific groups."))
948 (let ((qstring (cdr (assq 'query query)))
949 (prefix (nnir-read-server-parm 'nnir-wais-remove-prefix server))
951 (score nil) (artno nil) (dirnam nil) (group nil))
952 (set-buffer (get-buffer-create nnir-tmp-buffer))
954 (message "Doing WAIS query %s..." query)
955 (call-process nnir-wais-program
956 nil ; input from /dev/null
957 t ; output to current buffer
958 nil ; don't redisplay
959 "-d" (nnir-read-server-parm 'nnir-wais-database server) ; database to search
961 (message "Massaging waissearch output...")
962 ;; remove superfluous lines
963 (keep-lines "Score:")
964 ;; extract data from result lines
965 (goto-char (point-min))
966 (while (re-search-forward
967 "Score: +\\([0-9]+\\).*'\\([0-9]+\\) +\\([^']+\\)/'" nil t)
968 (setq score (match-string 1)
969 artno (match-string 2)
970 dirnam (match-string 3))
971 (unless (string-match prefix dirnam)
972 (nnheader-report 'nnir "Dir name %s doesn't contain prefix %s"
974 (setq group (substitute ?. ?/ (replace-match "" t t dirnam)))
975 (push (vector (nnir-group-full-name group server)
976 (string-to-int artno)
977 (string-to-int score))
979 (message "Massaging waissearch output...done")
982 (function (lambda (x y)
983 (> (nnir-artitem-rsv x)
984 (nnir-artitem-rsv y)))))))))
986 ;; EWS (Excite for Web Servers) interface
987 (defun nnir-run-excite-search (query server &optional group)
988 "Run a given query against EWS. Returns vector of (group name, file name)
989 pairs (also vectors, actually)."
991 (error "Searching specific groups not implemented for EWS."))
993 (let ((qstring (cdr (assq 'query query)))
994 (prefix (nnir-read-server-parm 'nnir-excite-remove-prefix server))
995 artlist group article-num article)
996 (setq nnir-current-query query)
997 (set-buffer (get-buffer-create nnir-tmp-buffer))
999 (message "Doing EWS query %s..." qstring)
1000 (call-process nnir-excite-aquery-program
1001 nil ; input from /dev/null
1002 t ; output to current buffer
1003 nil ; don't redisplay
1004 (nnir-read-server-parm 'nnir-excite-collection server)
1005 (if (string= (substring qstring 0 1) "(")
1007 (format "(concept %s)" qstring)))
1008 (message "Gathering query output...")
1010 (goto-char (point-min))
1011 (while (re-search-forward
1012 "^[0-9]+\\s-[0-9]+\\s-[0-9]+\\s-\\(\\S-*\\)" nil t)
1013 (setq article (match-string 1))
1014 (unless (string-match
1015 (concat "^" (regexp-quote prefix)
1016 "\\(.*\\)/\\([0-9]+\\)") article)
1017 (nnheader-report 'nnir "Dir name %s doesn't contain prefix %s"
1019 (setq group (substitute ?. ?/ (match-string 1 article)))
1020 (setq group (nnir-group-full-name group server))
1021 (setq article-num (match-string 2 article))
1022 (setq artlist (vconcat artlist (vector (vector group
1023 (string-to-int article-num)
1025 (message "Gathering query output...done")
1028 ;; IMAP interface. The following function is Copyright (C) 1998 Simon
1029 ;; Josefsson <jas@pdc.kth.se>.
1031 ;; nnir invokes this two (2) times???!
1032 ;; we should not use nnimap at all but open our own server connection
1033 ;; we should not LIST * but use nnimap-list-pattern from defs
1034 ;; send queries as literals
1037 (defun nnir-run-imap (query srv &optional group-option)
1041 (let ((qstring (cdr (assq 'query query)))
1042 (server (cadr (gnus-server-to-method srv)))
1043 (group (or group-option (gnus-group-group-name)))
1044 (defs (caddr (gnus-server-to-method srv)))
1045 (criteria (or (cdr (assq 'criteria query))
1046 nnir-imap-search-field))
1048 (message "Opening server %s" server)
1050 (when (nnimap-open-server server defs) ;; xxx
1051 (setq buf nnimap-server-buffer) ;; xxx
1052 (message "Searching %s..." group)
1054 (mbx (gnus-group-real-name group)))
1055 (when (imap-mailbox-select mbx nil buf)
1058 (push (vector group artnum 1) artlist)
1059 (setq arts (1+ arts)))
1060 (imap-search (concat criteria " \"" qstring "\"") buf))
1061 (message "Searching %s... %d matches" mbx arts)))
1062 (message "Searching %s...done" group))
1064 (reverse artlist))))
1066 ;; Swish++ interface. The following function is Copyright (C) 2000,
1067 ;; 2001 Christoph Conrad <christoph.conrad@gmx.de>.
1076 (defun nnir-run-swish++ (query server &optional group)
1077 "Run given query against swish++.
1078 Returns a vector of (group name, file name) pairs (also vectors,
1081 Tested with swish++ 4.7 on GNU/Linux and with with swish++ 5.0b2 on
1085 (error "The swish++ backend cannot search specific groups."))
1088 (let ( (qstring (cdr (assq 'query query)))
1089 (groupspec (cdr (assq 'group query)))
1090 (prefix (nnir-read-server-parm 'nnir-swish++-remove-prefix server))
1092 (score nil) (artno nil) (dirnam nil) (group nil) )
1094 (when (equal "" qstring)
1095 (error "swish++: You didn't enter anything."))
1097 (set-buffer (get-buffer-create nnir-tmp-buffer))
1101 (message "Doing swish++ query %s on %s..." qstring groupspec)
1102 (message "Doing swish++ query %s..." qstring))
1104 (let* ((cp-list `( ,nnir-swish++-program
1105 nil ; input from /dev/null
1107 nil ; don't redisplay
1108 "--config-file" ,(nnir-read-server-parm 'nnir-swish++-configuration-file server)
1109 ,@(nnir-read-server-parm 'nnir-swish++-additional-switches server)
1110 ,qstring ; the query, in swish++ format
1114 (message "%s args: %s" nnir-swish++-program
1115 (mapconcat 'identity (cddddr cp-list) " ")) ;; ???
1116 (apply 'call-process cp-list))))
1117 (unless (or (null exitstatus)
1119 (nnheader-report 'nnir "Couldn't run swish++: %s" exitstatus)
1120 ;; swish++ failure reason is in this buffer, show it if
1121 ;; the user wants it.
1122 (when (> gnus-verbose 6)
1123 (display-buffer nnir-tmp-buffer))))
1125 ;; The results are output in the format of:
1127 ;; rank relative-path-name file-size file-title
1129 ;; rank relative-path-name file-size topic??
1130 ;; where rank is an integer from 1 to 100.
1131 (goto-char (point-min))
1132 (while (re-search-forward
1133 "\\(^[0-9]+\\) \\([^ ]+\\) [0-9]+ \\(.*\\)$" nil t)
1134 (setq score (match-string 1)
1135 artno (file-name-nondirectory (match-string 2))
1136 dirnam (file-name-directory (match-string 2)))
1138 ;; don't match directories
1139 (when (string-match "^[0-9]+$" artno)
1140 (when (not (null dirnam))
1142 ;; maybe limit results to matching groups.
1143 (when (or (not groupspec)
1144 (string-match groupspec dirnam))
1146 ;; remove nnir-swish++-remove-prefix from beginning of dirname
1147 (when (string-match (concat "^" prefix)
1149 (setq dirnam (replace-match "" t t dirnam)))
1151 (setq dirnam (substring dirnam 0 -1))
1152 ;; eliminate all ".", "/", "\" from beginning. Always matches.
1153 (string-match "^[./\\]*\\(.*\\)$" dirnam)
1155 (setq group (substitute ?. ?/ (match-string 1 dirnam)))
1157 (setq group (substitute ?. ?\\ group))
1159 (push (vector (nnir-group-full-name group server)
1160 (string-to-int artno)
1161 (string-to-int score))
1164 (message "Massaging swish++ output...done")
1169 (function (lambda (x y)
1170 (> (nnir-artitem-rsv x)
1171 (nnir-artitem-rsv y)))))))))
1173 ;; Swish-E interface. The following function is Copyright (C) 2000,
1174 ;; 2001 by Christoph Conrad <christoph.conrad@gmx.de>.
1175 (defun nnir-run-swish-e (query server &optional group)
1176 "Run given query against swish-e.
1177 Returns a vector of (group name, file name) pairs (also vectors,
1180 Tested with swish-e-2.0.1 on Windows NT 4.0."
1182 ;; swish-e crashes with empty parameter to "-w" on commandline...
1184 (error "The swish-e backend cannot search specific groups."))
1187 (let ((qstring (cdr (assq 'query query)))
1189 (or (nnir-read-server-parm 'nnir-swish-e-remove-prefix server)
1190 (error "Missing parameter `nnir-swish-e-remove-prefix'")))
1192 (score nil) (artno nil) (dirnam nil) (group nil) )
1194 (when (equal "" qstring)
1195 (error "swish-e: You didn't enter anything."))
1197 (set-buffer (get-buffer-create nnir-tmp-buffer))
1200 (message "Doing swish-e query %s..." query)
1202 (or (nnir-read-server-parm
1203 'nnir-swish-e-index-file server)
1204 (error "Missing parameter `nnir-swish-e-index-file'")))
1205 (additional-switches
1206 (nnir-read-server-parm
1207 'nnir-swish-e-additional-switches server))
1208 (cp-list `(,nnir-swish-e-program
1209 nil ; input from /dev/null
1211 nil ; don't redisplay
1213 ,@additional-switches
1215 ,qstring ; the query, in swish-e format
1219 (message "%s args: %s" nnir-swish-e-program
1220 (mapconcat 'identity (cddddr cp-list) " "))
1221 (apply 'call-process cp-list))))
1222 (unless (or (null exitstatus)
1224 (nnheader-report 'nnir "Couldn't run swish-e: %s" exitstatus)
1225 ;; swish-e failure reason is in this buffer, show it if
1226 ;; the user wants it.
1227 (when (> gnus-verbose 6)
1228 (display-buffer nnir-tmp-buffer))))
1230 ;; The results are output in the format of:
1231 ;; rank path-name file-title file-size
1232 (goto-char (point-min))
1233 (while (re-search-forward
1234 "\\(^[0-9]+\\) \\([^ ]+\\) \"\\([^\"]+\\)\" [0-9]+$" nil t)
1235 (setq score (match-string 1)
1236 artno (match-string 3)
1237 dirnam (file-name-directory (match-string 2)))
1239 ;; don't match directories
1240 (when (string-match "^[0-9]+$" artno)
1241 (when (not (null dirnam))
1243 ;; remove nnir-swish-e-remove-prefix from beginning of dirname
1244 (when (string-match (concat "^" prefix) dirnam)
1245 (setq dirnam (replace-match "" t t dirnam)))
1247 (setq dirnam (substring dirnam 0 -1))
1248 ;; eliminate all ".", "/", "\" from beginning. Always matches.
1249 (string-match "^[./\\]*\\(.*\\)$" dirnam)
1251 (setq group (substitute ?. ?/ (match-string 1 dirnam)))
1252 ;; Windows "\\" -> "."
1253 (setq group (substitute ?. ?\\ group))
1255 (push (vector (nnir-group-full-name group server)
1256 (string-to-int artno)
1257 (string-to-int score))
1260 (message "Massaging swish-e output...done")
1265 (function (lambda (x y)
1266 (> (nnir-artitem-rsv x)
1267 (nnir-artitem-rsv y)))))))))
1270 (defun nnir-run-hyrex (query server &optional group)
1273 (groupspec (cdr (assq 'group query)))
1274 (qstring (cdr (assq 'query query)))
1275 (prefix (nnir-read-server-parm 'nnir-hyrex-remove-prefix server))
1277 (when (and group groupspec)
1278 (error (concat "It does not make sense to use a group spec"
1279 " with process-marked groups.")))
1281 (setq groupspec (gnus-group-real-name group)))
1282 (when (and group (not (equal group (nnir-group-full-name groupspec server))))
1283 (message "%s vs. %s" group (nnir-group-full-name groupspec server))
1284 (error "Server with groupspec doesn't match group !"))
1285 (set-buffer (get-buffer-create nnir-tmp-buffer))
1288 (message "Doing hyrex-search query %s on %s..." query groupspec)
1289 (message "Doing hyrex-search query %s..." query))
1291 `( ,nnir-hyrex-program
1292 nil ; input from /dev/null
1294 nil ; don't redisplay
1295 "-i",(nnir-read-server-parm 'nnir-hyrex-index-directory server) ; index directory
1296 ,@(nnir-read-server-parm 'nnir-hyrex-additional-switches server)
1297 ,qstring ; the query, in hyrex-search format
1301 (message "%s args: %s" nnir-hyrex-program
1302 (mapconcat 'identity (cddddr cp-list) " "))
1303 (apply 'call-process cp-list))))
1304 (unless (or (null exitstatus)
1306 (nnheader-report 'nnir "Couldn't run hyrex-search: %s" exitstatus)
1307 ;; nnir-search failure reason is in this buffer, show it if
1308 ;; the user wants it.
1309 (when (> gnus-verbose 6)
1310 (display-buffer nnir-tmp-buffer)))) ;; FIXME: Dont clear buffer !
1312 (message "Doing hyrex-search query \"%s\" on %s...done" qstring groupspec)
1313 (message "Doing hyrex-search query \"%s\"...done" qstring))
1315 ;; nnir-search returns:
1316 ;; for nnml/nnfolder: "filename mailid weigth"
1317 ;; for nnimap: "group mailid weigth"
1318 (goto-char (point-min))
1319 (delete-non-matching-lines "^\\S + [0-9]+ [0-9]+$")
1320 ;; HyREX couldn't search directly in groups -- so filter out here.
1322 (keep-lines groupspec))
1323 ;; extract data from result lines
1324 (goto-char (point-min))
1325 (while (re-search-forward
1326 "\\(\\S +\\) \\([0-9]+\\) \\([0-9]+\\)" nil t)
1327 (setq dirnam (match-string 1)
1328 artno (match-string 2)
1329 score (match-string 3))
1330 (when (string-match prefix dirnam)
1331 (setq dirnam (replace-match "" t t dirnam)))
1332 (push (vector (nnir-group-full-name (substitute ?. ?/ dirnam) server)
1333 (string-to-int artno)
1334 (string-to-int score))
1336 (message "Massaging hyrex-search output...done.")
1339 (function (lambda (x y)
1340 (if (string-lessp (nnir-artitem-group x)
1341 (nnir-artitem-group y))
1343 (< (nnir-artitem-number x)
1344 (nnir-artitem-number y)))))))
1348 (defun nnir-run-namazu (query server &optional group)
1349 "Run given query against Namazu. Returns a vector of (group name, file name)
1350 pairs (also vectors, actually).
1352 Tested with Namazu 2.0.6 on a GNU/Linux system."
1354 (error "The Namazu backend cannot search specific groups"))
1358 (qstring (cdr (assq 'query query)))
1359 (prefix (nnir-read-server-parm 'nnir-namazu-remove-prefix server))
1363 (process-environment (copy-sequence process-environment))
1365 (setenv "LC_MESSAGES" "C")
1366 (set-buffer (get-buffer-create nnir-tmp-buffer))
1369 `( ,nnir-namazu-program
1370 nil ; input from /dev/null
1372 nil ; don't redisplay
1373 "-q" ; don't be verbose
1374 "-a" ; show all matches
1375 "-s" ; use short format
1376 ,@(nnir-read-server-parm 'nnir-namazu-additional-switches server)
1377 ,qstring ; the query, in namazu format
1378 ,(nnir-read-server-parm 'nnir-namazu-index-directory server) ; index directory
1382 (message "%s args: %s" nnir-namazu-program
1383 (mapconcat 'identity (cddddr cp-list) " "))
1384 (apply 'call-process cp-list))))
1385 (unless (or (null exitstatus)
1387 (nnheader-report 'nnir "Couldn't run namazu: %s" exitstatus)
1388 ;; Namazu failure reason is in this buffer, show it if
1389 ;; the user wants it.
1390 (when (> gnus-verbose 6)
1391 (display-buffer nnir-tmp-buffer))))
1393 ;; Namazu output looks something like this:
1394 ;; 2. Re: Gnus agent expire broken (score: 55)
1395 ;; /home/henrik/Mail/mail/sent/1310 (4,138 bytes)
1397 (goto-char (point-min))
1398 (while (re-search-forward
1399 "^\\([0-9]+\\.\\).*\\((score: \\([0-9]+\\)\\))\n\\([^ ]+\\)"
1401 (setq score (match-string 3)
1402 group (file-name-directory (match-string 4))
1403 article (file-name-nondirectory (match-string 4)))
1405 ;; make sure article and group is sane
1406 (when (and (string-match "^[0-9]+$" article)
1408 (when (string-match (concat "^" prefix) group)
1409 (setq group (replace-match "" t t group)))
1411 ;; remove trailing slash from groupname
1412 (setq group (substring group 0 -1))
1414 ;; stuff results into artlist vector
1415 (push (vector (nnir-group-full-name (substitute ?. ?/ group) server)
1416 (string-to-int article)
1417 (string-to-int score)) artlist)))
1419 ;; sort artlist by score
1422 (function (lambda (x y)
1423 (> (nnir-artitem-rsv x)
1424 (nnir-artitem-rsv y)))))))))
1428 (defun nnir-read-parms (query)
1429 "Reads additional search parameters according to `nnir-engines'."
1430 (let ((parmspec (caddr (assoc nnir-search-engine nnir-engines))))
1431 (cons (cons 'query query)
1432 (mapcar 'nnir-read-parm parmspec))))
1434 (defun nnir-read-parm (parmspec)
1435 "Reads a single search parameter.
1436 `parmspec' is a cons cell, the car is a symbol, the cdr is a prompt."
1437 (let ((sym (car parmspec))
1438 (prompt (cdr parmspec)))
1440 (let* ((result (apply 'completing-read prompt))
1441 (mapping (or (assoc result nnir-imap-search-arguments)
1442 (assoc nil nnir-imap-search-arguments))))
1443 (cons sym (format (cdr mapping) result)))
1444 (cons sym (read-string prompt)))))
1446 (defun nnir-run-query (query)
1447 "Invoke appropriate search engine function (see `nnir-engines').
1448 If some groups were process-marked, run the query for each of the groups
1449 and concat the results."
1450 (let ((q (car (read-from-string query))))
1451 (if gnus-group-marked
1454 (let ((server (nnir-group-server x))
1456 (setq search-func (cadr
1458 (nnir-read-server-parm 'nnir-search-engine server) nnir-engines)))
1460 (funcall search-func q server x)
1466 (if (and (equal (cadr x) 'ok) (not (equal (cadar x) "-ephemeral")))
1467 (let ((server (format "%s:%s" (caar x) (cadar x)))
1469 (setq search-func (cadr
1471 (nnir-read-server-parm 'nnir-search-engine server) nnir-engines)))
1473 (funcall search-func q server nil)
1476 gnus-opened-servers)
1480 (defun nnir-read-server-parm (key server)
1481 "Returns the parameter value of for the given server, where server is of
1482 form 'backend:name'."
1483 (let ((method (gnus-server-to-method server)))
1484 (cond ((and method (assq key (cddr method)))
1485 (nth 1 (assq key (cddr method))))
1486 ((and nnir-mail-backend
1487 (gnus-method-equal method nnir-mail-backend))
1489 ((null nnir-mail-backend)
1493 ;; (if (assq key (cddr method))
1494 ;; (nth 1 (assq key (cddr method)))
1495 ;; (symbol-value key))
1496 ;; (symbol-value key))
1499 (defun nnir-group-full-name (shortname server)
1500 "For the given group name, return a full Gnus group name.
1501 The Gnus backend/server information is added."
1502 (gnus-group-prefixed-name shortname (gnus-server-to-method server)))
1504 (defun nnir-possibly-change-server (server)
1505 (unless (and server (nnir-server-opened server))
1506 (nnir-open-server server)))
1509 ;; Data type article list.
1511 (defun nnir-artlist-length (artlist)
1512 "Returns number of articles in artlist."
1515 (defun nnir-artlist-article (artlist n)
1516 "Returns from ARTLIST the Nth artitem (counting starting at 1)."
1517 (elt artlist (1- n)))
1519 (defun nnir-artitem-group (artitem)
1520 "Returns the group from the ARTITEM."
1523 (defun nnir-artlist-artitem-group (artlist n)
1524 "Returns from ARTLIST the group of the Nth artitem (counting from 1)."
1525 (nnir-artitem-group (nnir-artlist-article artlist n)))
1527 (defun nnir-artitem-number (artitem)
1528 "Returns the number from the ARTITEM."
1531 (defun nnir-artlist-artitem-number (artlist n)
1532 "Returns from ARTLIST the number of the Nth artitem (counting from 1)."
1533 (nnir-artitem-number (nnir-artlist-article artlist n)))
1535 (defun nnir-artitem-rsv (artitem)
1536 "Returns the Retrieval Status Value (RSV, score) from the ARTITEM."
1539 (defun nnir-artlist-artitem-rsv (artlist n)
1540 "Returns from ARTLIST the Retrieval Status Value of the Nth artitem
1542 (nnir-artitem-rsv (nnir-artlist-article artlist n)))
1545 (defun nnir-artlist-groups (artlist)
1546 "Returns a list of all groups in the given ARTLIST."
1549 ;; from each artitem, extract group component
1550 (setq with-dups (mapcar 'nnir-artitem-group artlist))
1551 ;; remove duplicates from above
1552 (mapcar (function (lambda (x) (add-to-list 'res x)))