[PATCH 3/5] lib: Make MTIME values searchable

Subject: [PATCH 3/5] lib: Make MTIME values searchable

Date: Tue, 13 Dec 2011 18:11:43 +0100

To: notmuch@notmuchmail.org

Cc:

From: Thomas Jost


Tag modification times are now searchable as ranges (just like regular message
dates) with the "mtime:" prefix.
---
 lib/database-private.h |    1 +
 lib/database.cc        |    3 +++
 notmuch.1              |   14 ++++++++++++--
 notmuch.c              |   13 ++++++++++---
 4 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/lib/database-private.h b/lib/database-private.h
index 88532d5..e71c8e4 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -52,6 +52,7 @@ struct _notmuch_database {
     Xapian::QueryParser *query_parser;
     Xapian::TermGenerator *term_gen;
     Xapian::ValueRangeProcessor *value_range_processor;
+    Xapian::ValueRangeProcessor *mtime_value_range_processor;
 };
 
 /* Return the list of terms from the given iterator matching a prefix.
diff --git a/lib/database.cc b/lib/database.cc
index 6dc6f73..cc970c1 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -677,12 +677,14 @@ notmuch_database_open (const char *path,
 	notmuch->term_gen = new Xapian::TermGenerator;
 	notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));
 	notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);
+	notmuch->mtime_value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_MTIME, "mtime:");
 
 	notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);
 	notmuch->query_parser->set_database (*notmuch->xapian_db);
 	notmuch->query_parser->set_stemmer (Xapian::Stem ("english"));
 	notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);
 	notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);
+	notmuch->query_parser->add_valuerangeprocessor (notmuch->mtime_value_range_processor);
 
 	for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {
 	    prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];
@@ -726,6 +728,7 @@ notmuch_database_close (notmuch_database_t *notmuch)
     delete notmuch->query_parser;
     delete notmuch->xapian_db;
     delete notmuch->value_range_processor;
+    delete notmuch->mtime_value_range_processor;
     talloc_free (notmuch);
 }
 
diff --git a/notmuch.1 b/notmuch.1
index 3dbd67e..2235096 100644
--- a/notmuch.1
+++ b/notmuch.1
@@ -644,6 +644,8 @@ terms to match against specific portions of an email, (where
 
 	folder:<directory-path>
 
+	mtime:<timestamp-range>
+
 The
 .B from:
 prefix is used to match the name or address of the sender of an email
@@ -707,8 +709,8 @@ operators, but will have to be protected from interpretation by the
 shell, (such as by putting quotation marks around any parenthesized
 expression).
 
-Finally, results can be restricted to only messages within a
-particular time range, (based on the Date: header) with a syntax of:
+Results can be restricted to only messages within a particular time range,
+(based on the Date: header) with a syntax of:
 
 	<initial-timestamp>..<final-timestamp>
 
@@ -721,6 +723,14 @@ specify a date range to return messages from 2009\-10\-01 until the
 current time:
 
 	$(date +%s \-d 2009\-10\-01)..$(date +%s)
+
+Finally, the
+.B mtime:
+prefix can be used to search for messages which were modified (e.g. tags were
+added or removed) within a particular time range, with the same syntax as
+before:
+
+	mtime:<initial-timestamp>..<final-timestamp>
 .SH HOOKS
 Hooks are scripts (or arbitrary executables or symlinks to such) that notmuch
 invokes before and after certain actions. These scripts reside in
diff --git a/notmuch.c b/notmuch.c
index c0ce026..443cf59 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -71,6 +71,7 @@ static const char search_terms_help[] =
     "\t\tid:<message-id>\n"
     "\t\tthread:<thread-id>\n"
     "\t\tfolder:<directory-path>\n"
+    "\t\tmtime:<timestamp-range>\n"
     "\n"
     "\tThe from: prefix is used to match the name or address of\n"
     "\tthe sender of an email message.\n"
@@ -112,8 +113,8 @@ static const char search_terms_help[] =
     "\tinterpretation by the shell, (such as by putting quotation\n"
     "\tmarks around any parenthesized expression).\n"
     "\n"
-    "\tFinally, results can be restricted to only messages within a\n"
-    "\tparticular time range, (based on the Date: header) with:\n"
+    "\tResults can be restricted to only messages within a particular\n"
+    "\ttime range, (based on the Date: header) with:\n"
     "\n"
     "\t\t<intial-timestamp>..<final-timestamp>\n"
     "\n"
@@ -125,7 +126,13 @@ static const char search_terms_help[] =
     "\tfollowing syntax would specify a date range to return messages\n"
     "\tfrom 2009-10-01 until the current time:\n"
     "\n"
-    "\t\t$(date +%%s -d 2009-10-01)..$(date +%%s)\n\n";
+    "\t\t$(date +%%s -d 2009-10-01)..$(date +%%s)\n\n"
+    "\n"
+    "\tFinally, the mtime: prefix can be used to search for messages\n"
+    "\twhich were modified (e.g. tags were added or removed) within a\n"
+    "\tparticular time range, with the same syntax as before:\n"
+    "\n"
+    "\t\tmtime:<initial-timestamp>..<final-timestamp>\n";
 
 static const char hooks_help[] =
     "\tHooks are scripts (or arbitrary executables or symlinks to such) that\n"
-- 
1.7.8


Thread: