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'".
This commit is contained in:
Carl Worth 2009-11-23 16:58:35 +01:00
parent a378dff8a1
commit 793cbf8049
5 changed files with 46 additions and 5 deletions

15
TODO
View file

@ -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).

View 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

View 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);
}

View file

@ -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

View file

@ -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,