From: Carl Worth Date: Mon, 23 Nov 2009 15:58:35 +0000 (+0100) Subject: Add rudimentary date-based search. X-Git-Tag: 0.1~347 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=793cbf80495b8230e0b4de6ac609e2ca88b7dd4b Add rudimentary date-based search. 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'". --- diff --git a/TODO b/TODO index 7c984c28..65d6c75c 100644 --- 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). diff --git a/lib/database-private.h b/lib/database-private.h index 5f178f3e..431966fb 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -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 diff --git a/lib/database.cc b/lib/database.cc index 2c90019c..3fe12dd5 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -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); } diff --git a/notmuch.1 b/notmuch.1 index eeb1a948..c5a7711f 100644 --- 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: + + .. + +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 diff --git a/notmuch.c b/notmuch.c index 72ca6204..24f87288 100644 --- 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..\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,