]> git.notmuchmail.org Git - notmuch/commitdiff
Add rudimentary date-based search.
authorCarl Worth <cworth@cworth.org>
Mon, 23 Nov 2009 15:58:35 +0000 (16:58 +0100)
committerCarl Worth <cworth@cworth.org>
Mon, 23 Nov 2009 16:17:08 +0000 (17:17 +0100)
The rudimentary aspect here is that the date ranges are specified with
UNIX timestamp values (number of seconds since 1970-01-01 UTC). One
thing that can help here is using the date program to determins
timestamps, such as:

$(date +%s -d 2009-10-01)..$(date +%s)

Long-term, we'll probably need to do our own query parsing to be able
to support directly-specified dates and also relative expressions like
"since:'2 months ago'".

TODO
lib/database-private.h
lib/database.cc
notmuch.1
notmuch.c

diff --git a/TODO b/TODO
index 7c984c28c88485af53abc5731f4ad229c60f1438..65d6c75ccea0f72e89d1128e173077d7fa76e081 100644 (file)
--- a/TODO
+++ b/TODO
@@ -4,11 +4,9 @@ Fix the things that are causing the most pain to new users
 
 2. Allow an easy way to get tags from directory names (if the user has them)
 
-3. Allow an easy way to remove excess tags, (date-based search)
+3. Make emacs fast for big search results (see "lazy searching" below)
 
-4. Make emacs fast for big search results (see "lazy searching" below)
-
-5. Fix Xapian defect #250 so tagging is fast.
+4. Fix Xapian defect #250 so tagging is fast.
 
 Emacs interface (notmuch.el)
 ----------------------------
@@ -112,6 +110,15 @@ indexing.
 
 notmuch library
 ---------------
+Provide a sane syntax for date ranges. First, we don't want to require
+both endpoints to be specified. For example it would be nice to be
+able to say things like "since:2009-01-1" or "until:2009-01-1" and
+have the other enpoint be implicit. Second we'de like to support
+relative specifications of time such as "since:'2 months ago'". To do
+any of this we're probably going to need to break down an write our
+own parser for the query string rather than using Xapian's QueryParser
+class.
+
 Add support for files that are moved or deleted (which obviously need
 to be handled differently).
 
index 5f178f3ebc27b77882fc8f25669776fbbef838dd..431966fbd7de14d4a5297cefe0e8ca75d8a6f929 100644 (file)
@@ -32,6 +32,7 @@ struct _notmuch_database {
     Xapian::Database *xapian_db;
     Xapian::QueryParser *query_parser;
     Xapian::TermGenerator *term_gen;
+    Xapian::ValueRangeProcessor *value_range_processor;
 };
 
 #endif
index 2c90019cbee8922bfe9c88541a8aae809c2d6a0f..3fe12dd50ee65af6d709edc511229a5e9f047e8f 100644 (file)
@@ -501,11 +501,13 @@ notmuch_database_open (const char *path,
        notmuch->query_parser = new Xapian::QueryParser;
        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->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);
 
        for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {
            prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];
@@ -548,6 +550,7 @@ notmuch_database_close (notmuch_database_t *notmuch)
     delete notmuch->term_gen;
     delete notmuch->query_parser;
     delete notmuch->xapian_db;
+    delete notmuch->value_range_processor;
     talloc_free (notmuch);
 }
 
index eeb1a948ac8c3da69915887a8adc8578a4c1c995..c5a7711fcf13459b854acd26b82ab633633b47a5 100644 (file)
--- a/notmuch.1
+++ b/notmuch.1
@@ -408,6 +408,21 @@ Parentheses can also be used to control the combination of the Boolean
 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:
+
+       <intial-timestamp>..<final-timestamp>
+
+Each timestamp is a number representing the number of seconds since
+1970-01-01 00:00:00 UTC. This is not the most convenient means of
+expressing date ranges, but until notmuch is fixed to accept a more
+convenient form, one can use the date program to construct
+timestamps. For example, with the bash shell the folowing syntax would
+specify a date range to return messages from 2009-10-01 until the
+current time:
+
+       $(date +%s -d 2009-10-01)..$(date +%s)
 .SH SEE ALSO
 The emacs-based interface to notmuch (available as
 .B notmuch.el
index 72ca62044e90a2a3ccd2a0cee493f81141504fa4..24f872882471baa50482a8730d63504046c05c23 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -89,7 +89,22 @@ static const char search_terms_help[] =
     "\t\tParentheses can also be used to control the combination of\n"
     "\t\tthe Boolean operators, but will have to be protected from\n"
     "\t\tinterpretation by the shell, (such as by putting quotation\n"
-    "\t\tmarks around any parenthesized expression).\n\n";
+    "\t\tmarks around any parenthesized expression).\n"
+    "\n"
+    "\t\tFinally, results can be restricted to only messages within a\n"
+    "\t\tparticular time range, (based on the Date: header) with:\n"
+    "\n"
+    "\t\t\t<intial-timestamp>..<final-timestamp>\n"
+    "\n"
+    "\t\tEach timestamp is a number representing the number of seconds\n"
+    "\t\tsince 1970-01-01 00:00:00 UTC. This is not the most convenient\n"
+    "\t\tmeans of expressing date ranges, but until notmuch is fixed to\n"
+    "\t\taccept a more convenient form, one can use the date program to\n"
+    "\t\tconstruct timestamps. For example, with the bash shell the\n"
+    "\t\tfollowing syntax would specify a date range to return messages\n"
+    "\t\tfrom 2009-10-01 until the current time:\n"
+    "\n"
+    "\t\t\t$(date +%s -d 2009-10-01)..$(date +%s)\n\n";
 
 command_t commands[] = {
     { "setup", notmuch_setup_command,