From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: [PATCH 1/5] lib: make folder: prefix literal
Date: Fri, 10 Jan 2014 00:18:32 +0200 [thread overview]
Message-ID: <d735583dd1bb48a87530fe3d52a57abd4d17acb8.1389304779.git.jani@nikula.org> (raw)
In-Reply-To: <cover.1389304779.git.jani@nikula.org>
In-Reply-To: <cover.1389304779.git.jani@nikula.org>
In xapian terms, convert folder: prefix from probabilistic to boolean
prefix. This change constitutes a database change: bump the database
version and add database upgrade support.
---
lib/database.cc | 39 ++++++++++++-
lib/message.cc | 154 +++++++++++++++++++++++++-------------------------
lib/notmuch-private.h | 3 +
3 files changed, 117 insertions(+), 79 deletions(-)
diff --git a/lib/database.cc b/lib/database.cc
index f395061..145fd66 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -42,7 +42,7 @@ typedef struct {
const char *prefix;
} prefix_t;
-#define NOTMUCH_DATABASE_VERSION 1
+#define NOTMUCH_DATABASE_VERSION 2
#define STRINGIFY(s) _SUB_STRINGIFY(s)
#define _SUB_STRINGIFY(s) #s
@@ -208,7 +208,8 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {
{ "thread", "G" },
{ "tag", "K" },
{ "is", "K" },
- { "id", "Q" }
+ { "id", "Q" },
+ { "folder", "P" },
};
static prefix_t PROBABILISTIC_PREFIX[]= {
@@ -216,7 +217,6 @@ static prefix_t PROBABILISTIC_PREFIX[]= {
{ "to", "XTO" },
{ "attachment", "XATTACHMENT" },
{ "subject", "XSUBJECT"},
- { "folder", "XFOLDER"}
};
const char *
@@ -1167,6 +1167,39 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
}
}
+ /*
+ * Prior to version 2, the "folder:" prefix was probabilistic and
+ * stemmed. Change it to the current boolean prefix.
+ */
+ if (version < 2) {
+ notmuch_query_t *query = notmuch_query_create (notmuch, "");
+ notmuch_messages_t *messages;
+ notmuch_message_t *message;
+
+ count = 0;
+ total = notmuch_query_count_messages (query);
+
+ for (messages = notmuch_query_search_messages (query);
+ notmuch_messages_valid (messages);
+ notmuch_messages_move_to_next (messages)) {
+ if (do_progress_notify) {
+ progress_notify (closure, (double) count / total);
+ do_progress_notify = 0;
+ }
+
+ message = notmuch_messages_get (messages);
+
+ _notmuch_message_upgrade_folder (message);
+ _notmuch_message_sync (message);
+
+ notmuch_message_destroy (message);
+
+ count++;
+ }
+
+ notmuch_query_destroy (query);
+ }
+
db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION));
db->flush ();
diff --git a/lib/message.cc b/lib/message.cc
index 1b46379..500aa26 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -505,89 +505,27 @@ _notmuch_message_add_filename (notmuch_message_t *message,
_notmuch_message_add_term (message, "file-direntry", direntry);
/* New terms allow user to search with folder: specification. */
- _notmuch_message_gen_terms (message, "folder", directory);
+ _notmuch_message_add_term (message, "folder", directory);
talloc_free (local);
return NOTMUCH_STATUS_SUCCESS;
}
-/* Remove a particular 'filename' from 'message'.
- *
- * This change will not be reflected in the database until the next
- * call to _notmuch_message_sync.
- *
- * If this message still has other filenames, returns
- * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID.
- *
- * Note: This function does not remove a document from the database,
- * even if the specified filename is the only filename for this
- * message. For that functionality, see
- * _notmuch_database_remove_message. */
-notmuch_status_t
-_notmuch_message_remove_filename (notmuch_message_t *message,
- const char *filename)
+static void
+_notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)
{
- const char *direntry_prefix = _find_prefix ("file-direntry");
- int direntry_prefix_len = strlen (direntry_prefix);
- const char *folder_prefix = _find_prefix ("folder");
- int folder_prefix_len = strlen (folder_prefix);
- void *local = talloc_new (message);
- char *zfolder_prefix = talloc_asprintf(local, "Z%s", folder_prefix);
- int zfolder_prefix_len = strlen (zfolder_prefix);
- char *direntry;
- notmuch_private_status_t private_status;
- notmuch_status_t status;
- Xapian::TermIterator i, last;
-
- status = _notmuch_database_filename_to_direntry (
- local, message->notmuch, filename, NOTMUCH_FIND_LOOKUP, &direntry);
- if (status || !direntry)
- return status;
+ Xapian::TermIterator i;
+ size_t prefix_len = strlen (prefix);
- /* Unlink this file from its parent directory. */
- private_status = _notmuch_message_remove_term (message,
- "file-direntry", direntry);
- status = COERCE_STATUS (private_status,
- "Unexpected error from _notmuch_message_remove_term");
- if (status)
- return status;
-
- /* Re-synchronize "folder:" terms for this message. This requires:
- * 1. removing all "folder:" terms
- * 2. removing all "folder:" stemmed terms
- * 3. adding back terms for all remaining filenames of the message. */
-
- /* 1. removing all "folder:" terms */
while (1) {
i = message->doc.termlist_begin ();
- i.skip_to (folder_prefix);
+ i.skip_to (prefix);
/* Terminate loop when no terms remain with desired prefix. */
if (i == message->doc.termlist_end () ||
- strncmp ((*i).c_str (), folder_prefix, folder_prefix_len))
- {
+ strncmp ((*i).c_str (), prefix, prefix_len))
break;
- }
-
- try {
- message->doc.remove_term ((*i));
- } catch (const Xapian::InvalidArgumentError) {
- /* Ignore failure to remove non-existent term. */
- }
- }
-
- /* 2. removing all "folder:" stemmed terms */
- while (1) {
- i = message->doc.termlist_begin ();
- i.skip_to (zfolder_prefix);
-
- /* Terminate loop when no terms remain with desired prefix. */
- if (i == message->doc.termlist_end () ||
- strncmp ((*i).c_str (), zfolder_prefix, zfolder_prefix_len))
- {
- break;
- }
try {
message->doc.remove_term ((*i));
@@ -595,12 +533,18 @@ _notmuch_message_remove_filename (notmuch_message_t *message,
/* Ignore failure to remove non-existent term. */
}
}
+}
- /* 3. adding back terms for all remaining filenames of the message. */
- i = message->doc.termlist_begin ();
- i.skip_to (direntry_prefix);
+/* Add "folder:" terms for all filenames of the message. */
+static notmuch_status_t
+_notmuch_message_add_folder_terms (void *ctx, notmuch_message_t *message)
+{
+ const char *direntry_prefix = _find_prefix ("file-direntry");
+ int direntry_prefix_len = strlen (direntry_prefix);
+ Xapian::TermIterator i = message->doc.termlist_begin ();
+ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
- for (; i != message->doc.termlist_end (); i++) {
+ for (i.skip_to (direntry_prefix); i != message->doc.termlist_end (); i++) {
unsigned int directory_id;
const char *direntry, *directory;
char *colon;
@@ -620,18 +564,76 @@ _notmuch_message_remove_filename (notmuch_message_t *message,
if (colon == NULL || *colon != ':')
INTERNAL_ERROR ("malformed direntry");
- directory = _notmuch_database_get_directory_path (local,
+ directory = _notmuch_database_get_directory_path (ctx,
message->notmuch,
directory_id);
- if (strlen (directory))
- _notmuch_message_gen_terms (message, "folder", directory);
+ _notmuch_message_add_term (message, "folder", directory);
}
+ return status;
+}
+
+/* Remove a particular 'filename' from 'message'.
+ *
+ * This change will not be reflected in the database until the next
+ * call to _notmuch_message_sync.
+ *
+ * If this message still has other filenames, returns
+ * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID.
+ *
+ * Note: This function does not remove a document from the database,
+ * even if the specified filename is the only filename for this
+ * message. For that functionality, see
+ * _notmuch_database_remove_message. */
+notmuch_status_t
+_notmuch_message_remove_filename (notmuch_message_t *message,
+ const char *filename)
+{
+ void *local = talloc_new (message);
+ char *direntry;
+ notmuch_private_status_t private_status;
+ notmuch_status_t status;
+
+ status = _notmuch_database_filename_to_direntry (
+ local, message->notmuch, filename, NOTMUCH_FIND_LOOKUP, &direntry);
+ if (status || !direntry)
+ return status;
+
+ /* Unlink this file from its parent directory. */
+ private_status = _notmuch_message_remove_term (message,
+ "file-direntry", direntry);
+ status = COERCE_STATUS (private_status,
+ "Unexpected error from _notmuch_message_remove_term");
+ if (status)
+ return status;
+
+ /* Remove all "folder:" terms from the message. */
+ _notmuch_message_remove_terms (message, _find_prefix ("folder"));
+
+ /* Add back "folder:" terms for all remaining filenames of the message. */
+ status = _notmuch_message_add_folder_terms (local, message);
+
talloc_free (local);
return status;
}
+/* Upgrade the "folder:" prefix from V1 to V2. */
+#define FOLDER_PREFIX_V1 "XFOLDER"
+#define ZFOLDER_PREFIX_V1 "Z" FOLDER_PREFIX_V1
+void
+_notmuch_message_upgrade_folder (notmuch_message_t *message)
+{
+ /* Remove all old "folder:" terms. */
+ _notmuch_message_remove_terms (message, FOLDER_PREFIX_V1);
+
+ /* Remove all old "folder:" stemmed terms. */
+ _notmuch_message_remove_terms (message, ZFOLDER_PREFIX_V1);
+
+ /* Add new boolean "folder:" terms. */
+ _notmuch_message_add_folder_terms (message, message);
+}
+
char *
_notmuch_message_talloc_copy_data (notmuch_message_t *message)
{
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index af185c7..59eb2bc 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -263,6 +263,9 @@ _notmuch_message_gen_terms (notmuch_message_t *message,
void
_notmuch_message_upgrade_filename_storage (notmuch_message_t *message);
+void
+_notmuch_message_upgrade_folder (notmuch_message_t *message);
+
notmuch_status_t
_notmuch_message_add_filename (notmuch_message_t *message,
const char *filename);
--
1.8.5.2
next prev parent reply other threads:[~2014-01-10 7:10 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-09 22:18 [PATCH 0/5] lib: make folder: prefix literal Jani Nikula
2014-01-09 22:18 ` Jani Nikula [this message]
2014-01-24 21:18 ` [PATCH 1/5] " Austin Clements
2014-01-09 22:18 ` [PATCH 2/5] test: fix insert folder: searches Jani Nikula
2014-01-24 21:20 ` Austin Clements
2014-01-25 19:32 ` Rob Browning
2014-01-09 22:18 ` [PATCH 3/5] test: fix test for literal folder: search Jani Nikula
2014-01-09 22:18 ` [PATCH 4/5] test: add test database in format version 1 Jani Nikula
2014-01-09 22:18 ` [PATCH 5/5] test: add database upgrade test from " Jani Nikula
2014-01-24 21:17 ` [PATCH 0/5] lib: make folder: prefix literal Austin Clements
2014-01-24 23:21 ` David Bremner
2014-01-25 9:33 ` Jani Nikula
2014-01-25 10:47 ` Tomi Ollila
2014-01-25 11:06 ` Jani Nikula
2014-01-25 11:52 ` Tomi Ollila
2014-01-25 15:38 ` Jani Nikula
2014-01-25 16:58 ` David Bremner
2014-01-25 18:22 ` Jani Nikula
[not found] ` <874n4rvcvo.fsf@yoom.home.cworth.org>
2014-01-29 19:05 ` Jani Nikula
[not found] ` <87k3dir3ci.fsf@yoom.home.cworth.org>
2014-01-29 20:46 ` Austin Clements
[not found] ` <87bnyuqw60.fsf@yoom.home.cworth.org>
2014-01-30 6:34 ` Jani Nikula
2014-01-30 21:15 ` Mark Walters
2014-01-30 22:02 ` Austin Clements
2014-01-31 19:19 ` Rob Browning
2014-02-04 20:14 ` Austin Clements
2014-02-04 20:17 ` Rob Browning
2014-01-31 19:24 ` Rob Browning
2014-02-01 14:54 ` Jani Nikula
2014-02-04 20:02 ` Austin Clements
2014-02-05 13:12 ` Tomi Ollila
2014-02-05 21:12 ` Tomi Ollila
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d735583dd1bb48a87530fe3d52a57abd4d17acb8.1389304779.git.jani@nikula.org \
--to=jani@nikula.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).