File: nnir.el.html
What does it do? Well, it searches your mail using some search
engine (imap, namazu, swish-e, gmane and others -- see later).
The Lisp setup may involve setting a few variables and setting up the
search engine. You can define the variables in the server definition
like this :
(setq gnus-secondary-select-methods '(
(nnimap "" (nnimap-address "localhost")
(nnir-search-engine namazu)
)))
The main variable to set is nnir-search-engine. Choose one of
the engines listed in nnir-engines. (Actually nnir-engines is
an alist, type C-h v nnir-engines RET for more information; this
includes examples for setting nnir-search-engine, too.)
The entry to searching is the single function nnir-run-query,
which dispatches the search to the proper search function. The
argument of nnir-run-query is an alist with two keys:
'nnir-query-spec and 'nnir-group-spec. The value for
'nnir-query-spec is an alist. The only required key/value pair is
(query . "query") specifying the search string to pass to the query
engine. Individual engines may have other elements. The value of
'nnir-group-spec is a list with the specification of the
groups/servers to search. The format of the 'nnir-group-spec is
(("server1" ("group11" "group12")) ("server2" ("group21"
"group22"))). If any of the group lists is absent then all groups
on that server are searched.
The output of nnir-run-query is a vector, each element of which
should in turn be a three-element vector with the form: [fully
prefixed group-name of the article; the article number; the
Retrieval Status Value (RSV)] as returned from the search engine.
An RSV is the score assigned to the document by the search engine.
For Boolean search engines, the RSV is always 1000 (or 1 or 100, or
whatever you like).
A vector of this form is used by the nnselect backend to create virtual groups. So nnir-run-query is a suitable function to use in nnselect groups.
The default sorting order of articles in an nnselect summary buffer is based on the order of the articles in the above mentioned vector, so that's where you can do the sorting you'd like. Maybe it would be nice to have a way of displaying the search result sorted differently?
So what do you need to do when you want to add another search
engine? You write a function that executes the query. Temporary
data from the search engine can be put in nnir-tmp-buffer. This
function should return the list of articles as a vector, as
described above. Then, you need to register this backend in
nnir-engines. Then, users can choose the backend by setting
nnir-search-engine as a server variable.
If you use one of the local indices (namazu, find-grep, swish) you must also set up a search engine backend.
1. Namazu
The Namazu backend requires you to have one directory containing all
index files, this is controlled by the nnir-namazu-index-directory
variable. To function the nnir-namazu-remove-prefix variable must
also be correct, see the documentation for nnir-namazu-remove-prefix
above.
It is particularly important not to pass any switches to namazu
that will change the output format. Good switches to use include
--sort, --ascending, --early and --late. Refer to the Namazu
documentation for further information on valid switches.
To index my mail with the mknmz program I use the following
configuration file:
,----
| package conf; # Don't remove this line!
|
| # Paths which will not be indexed. Don't use ^ or $ anchors.
| $EXCLUDE_PATH = "spam|sent";
|
| # Header fields which should be searchable. case-insensitive
| $REMAIN_HEADER = "from|date|message-id|subject";
|
| # Searchable fields. case-insensitive
| $SEARCH_FIELD = "from|date|message-id|subject";
|
| # The max length of a word.
| $WORD_LENG_MAX = 128;
|
| # The max length of a field.
| $MAX_FIELD_LENGTH = 256;
`----
My mail is stored in the directories ~/Mail/mail/, ~/Mail/lists/ and
~/Mail/archive/, so to index them I go to the directory set in
nnir-namazu-index-directory and issue the following command.
mknmz --mailnews ~/Mail/archive/ ~/Mail/mail/ ~/Mail/lists/
For maximum searching efficiency I have a cron job set to run this command every four hours.
2. find-grep
The find-grep engine simply runs find(1) to locate eligible
articles and searches them with grep(1). This, of course, is much
slower than using a proper search engine but OTOH doesn't require
maintenance of an index and is still faster than using any built-in
means for searching. The method specification of the server to
search must include a directory for this engine to work (E.g.,
nnml-directory). The tools must be POSIX compliant. GNU Find
prior to version 4.2.12 (4.2.26 on Linux due to incorrect ARG_MAX
handling) does not work.
,----
| ;; find-grep configuration for searching the Gnus Cache
|
| (nnml "cache"
| (nnml-get-new-mail nil)
| (nnir-search-engine find-grep)
| (nnml-directory "~/News/cache/")
| (nnml-active-file "~/News/cache/active"))
`----
Defined variables (30)
nnir-engines | Alist of supported search engines. |
nnir-hyrex-additional-switches | A list of strings, to be given as additional arguments for nnir-search. |
nnir-hyrex-index-directory | Index directory for HyREX. |
nnir-hyrex-program | Name of the nnir-search executable. |
nnir-hyrex-remove-prefix | The prefix to remove from HyREX file names to get group names. |
nnir-ignored-newsgroups | Newsgroups to skip when searching. |
nnir-imap-default-search-key | The default IMAP search key for an nnir search. |
nnir-imap-search-argument-history | The history for querying search options in nnir. |
nnir-imap-search-arguments | Mapping from user readable keys to IMAP search items for use in nnir. |
nnir-imap-search-other | The IMAP search item for anything other than ‘nnir-imap-search-arguments’. |
nnir-method-default-engines | Alist of default search engines keyed by server method. |
nnir-namazu-additional-switches | A list of strings, to be given as additional arguments to namazu. |
nnir-namazu-index-directory | Index directory for Namazu. |
nnir-namazu-program | Name of Namazu search executable. |
nnir-namazu-remove-prefix | The prefix to remove from Namazu file names to get group names. |
nnir-notmuch-additional-switches | A list of strings, to be given as additional arguments to notmuch. |
nnir-notmuch-filter-group-names-function | Whether and how to use Gnus group names as "path:" search terms. |
nnir-notmuch-program | Name of notmuch search executable. |
nnir-notmuch-remove-prefix | The prefix to remove from notmuch file names to get group names. |
nnir-search-history | Internal: the history for querying search options in nnir. |
nnir-summary-line-format | The format specification of the lines in an nnir summary buffer. |
nnir-swish++-additional-switches | A list of strings, to be given as additional arguments to swish++. |
nnir-swish++-configuration-file | Configuration file for swish++. |
nnir-swish++-program | Name of swish++ search executable. |
nnir-swish++-remove-prefix | The prefix to remove from swish++ file names to get group names. |
nnir-swish-e-additional-switches | A list of strings, to be given as additional arguments to swish-e. |
nnir-swish-e-index-files | List of index files for swish-e. |
nnir-swish-e-program | Name of swish-e search executable. |
nnir-swish-e-remove-prefix | The prefix to remove from swish-e file names to get group names. |
nnir-tmp-buffer | Internal: temporary buffer. |
Defined functions (29)
nnir-add-result | (DIRNAM ARTNO SCORE PREFIX SERVER ARTLIST) |
nnir-artitem-group | (ARTITEM) |
nnir-artitem-number | (ARTITEM) |
nnir-artitem-rsv | (ARTITEM) |
nnir-compose-result | (DIRNAM ARTICLE SCORE PREFIX SERVER) |
nnir-get-active | (SERVER &optional IGNORED) |
nnir-imap-delimited-string | (DELIMITER) |
nnir-imap-end-of-input | () |
nnir-imap-expr-to-imap | (CRITERIA EXPR) |
nnir-imap-make-query | (CRITERIA QSTRING) |
nnir-imap-next-expr | (&optional COUNT) |
nnir-imap-next-symbol | (&optional COUNT) |
nnir-imap-next-term | (&optional COUNT) |
nnir-imap-parse-query | (STRING) |
nnir-imap-peek-symbol | () |
nnir-imap-query-to-imap | (CRITERIA QUERY) |
nnir-make-specs | (NNIR-EXTRA-PARMS &optional SPECS) |
nnir-read-parm | (PARMSPEC) |
nnir-read-parms | (NNIR-SEARCH-ENGINE) |
nnir-read-server-parm | (KEY SERVER &optional NOT-GLOBAL) |
nnir-run-find-grep | (QUERY SERVER &optional GROUPLIST) |
nnir-run-hyrex | (QUERY SERVER &optional GROUP) |
nnir-run-imap | (QUERY SRV &optional GROUPS) |
nnir-run-namazu | (QUERY SERVER &optional GROUP) |
nnir-run-notmuch | (QUERY SERVER &optional GROUPS) |
nnir-run-query | (SPECS) |
nnir-run-swish++ | (QUERY SERVER &optional GROUP) |
nnir-run-swish-e | (QUERY SERVER &optional GROUP) |
nnir-server-to-search-engine | (SERVER) |