[PATCH v2 02/11] lib: database: store message filesize & add range processor

Ioan-Adrian Ratiu adi at adirat.com
Thu May 18 15:26:59 PDT 2017


The filesize and range processor are very useful to do search queries
like "filesize:1000..10000". All sizes are in bytes for now because
that's what I'm interested in.

I think the database needs to be re-created for this to work so that
all newly indexed messages have the new xapian filesize value, I did
not have the time to test a "hybrid" database where just some of the
messages have the value.

Signed-off-by: Ioan-Adrian Ratiu <adi at adirat.com>
---
 lib/database-private.h | 1 +
 lib/database.cc        | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/lib/database-private.h b/lib/database-private.h
index 727b1d61..d4d5ab6b 100644
--- a/lib/database-private.h
+++ b/lib/database-private.h
@@ -215,6 +215,7 @@ struct _notmuch_database {
     Xapian::ValueRangeProcessor *value_range_processor;
     Xapian::ValueRangeProcessor *date_range_processor;
     Xapian::ValueRangeProcessor *last_mod_range_processor;
+    Xapian::ValueRangeProcessor *filesize_range_processor;
 };
 
 /* Prior to database version 3, features were implied by the database
diff --git a/lib/database.cc b/lib/database.cc
index 5b13f541..84e616cf 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -295,6 +295,7 @@ prefix_t prefix_table[] = {
     { "subject",		"XSUBJECT",	NOTMUCH_FIELD_EXTERNAL |
 						NOTMUCH_FIELD_PROBABILISTIC |
 						NOTMUCH_FIELD_PROCESSOR},
+    { "filesize",		"XFILESIZE",	NOTMUCH_FIELD_EXTERNAL },
 };
 
 static void
@@ -1082,6 +1083,7 @@ notmuch_database_open_verbose (const char *path,
 	notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);
 	notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);
 	notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:");
+	notmuch->filesize_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_FILESIZE, "filesize:");
 
 	notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);
 	notmuch->query_parser->set_database (*notmuch->xapian_db);
@@ -1090,6 +1092,7 @@ notmuch_database_open_verbose (const char *path,
 	notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);
 	notmuch->query_parser->add_valuerangeprocessor (notmuch->date_range_processor);
 	notmuch->query_parser->add_valuerangeprocessor (notmuch->last_mod_range_processor);
+	notmuch->query_parser->add_valuerangeprocessor (notmuch->filesize_range_processor);
 
 	for (i = 0; i < ARRAY_SIZE (prefix_table); i++) {
 	    const prefix_t *prefix = &prefix_table[i];
@@ -1166,6 +1169,8 @@ notmuch_database_close (notmuch_database_t *notmuch)
     notmuch->date_range_processor = NULL;
     delete notmuch->last_mod_range_processor;
     notmuch->last_mod_range_processor = NULL;
+    delete notmuch->filesize_range_processor;
+    notmuch->filesize_range_processor = NULL;
 
     return status;
 }
@@ -2563,6 +2568,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
 	}
 
 	_notmuch_message_add_filename (message, filename);
+	_notmuch_message_add_filesize (message, message_file);
 
 	/* Is this a newly created message object or a ghost
 	 * message?  We have to be slightly careful: if this is a
-- 
2.13.0



More information about the notmuch mailing list