diff options
| author | David Bremner <david@tethera.net> | 2019-03-18 21:39:21 -0300 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2019-04-17 08:48:16 -0300 |
| commit | 319dd95ebbd841320e269d34e67a824876f8426a (patch) | |
| tree | 3f57795432d7a2d6573e77cab3e9176a507098d0 /lib/message.cc | |
| parent | 9fbc5cb578c60762ab9c2a24a14d4d07de516790 (diff) | |
lib: add 'body:' field, stop indexing headers twice.
The new `body:` field (in Xapian terms) or prefix (in slightly
sloppier notmuch) terms allows matching terms that occur only in the
body.
Unprefixed query terms should continue to match anywhere (header or
body) in the message.
This follows a suggestion of Olly Betts to use the facility (since
Xapian 1.0.4) to add the same field with multiple prefixes. The double
indexing of previous versions is thus replaced with a query time
expension of unprefixed query terms to the various prefixed
equivalent.
Reindexing will be needed for 'body:' searches to work correctly;
otherwise they will also match messages where the term occur in
headers (demonstrated by the new tests in T530-upgrade.sh)
Diffstat (limited to 'lib/message.cc')
| -rw-r--r-- | lib/message.cc | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/lib/message.cc b/lib/message.cc index 6f2f6345..38a48933 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -1419,8 +1419,9 @@ _notmuch_message_add_term (notmuch_message_t *message, } /* Parse 'text' and add a term to 'message' for each parsed word. Each - * term will be added both prefixed (if prefix_name is not NULL) and - * also non-prefixed). */ + * term will be added with the appropriate prefix if prefix_name is + * non-NULL. + */ notmuch_private_status_t _notmuch_message_gen_terms (notmuch_message_t *message, const char *prefix_name, @@ -1432,22 +1433,17 @@ _notmuch_message_gen_terms (notmuch_message_t *message, return NOTMUCH_PRIVATE_STATUS_NULL_POINTER; term_gen->set_document (message->doc); + term_gen->set_termpos (message->termpos); if (prefix_name) { - const char *prefix = _find_prefix (prefix_name); - - term_gen->set_termpos (message->termpos); - term_gen->index_text (text, 1, prefix); - /* Create a gap between this an the next terms so they don't - * appear to be a phrase. */ - message->termpos = term_gen->get_termpos () + 100; - _notmuch_message_invalidate_metadata (message, prefix_name); + term_gen->index_text (text, 1, _find_prefix (prefix_name)); + } else { + term_gen->index_text (text); } - term_gen->set_termpos (message->termpos); - term_gen->index_text (text); - /* Create a term gap, as above. */ + /* Create a gap between this an the next terms so they don't + * appear to be a phrase. */ message->termpos = term_gen->get_termpos () + 100; return NOTMUCH_PRIVATE_STATUS_SUCCESS; |
