X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fdatabase.cc;h=cfb19ccb22c3752f270cd75e08b1b3d8ce97d93f;hp=24b7ec4390096a6ba3b1f36a705d89c59f6c6b51;hb=095d3d7134f5668b96cf1d70997d3f110b03c898;hpb=b23902a61158ecdbca2d9d96c6eaf509d6e3d205 diff --git a/lib/database.cc b/lib/database.cc index 24b7ec43..cfb19ccb 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -291,12 +291,10 @@ prefix_t prefix_table[] = { */ { "folder", "XFOLDER:", NOTMUCH_FIELD_EXTERNAL | NOTMUCH_FIELD_PROCESSOR }, -#if HAVE_XAPIAN_FIELD_PROCESSOR { "date", NULL, NOTMUCH_FIELD_EXTERNAL | NOTMUCH_FIELD_PROCESSOR }, { "query", NULL, NOTMUCH_FIELD_EXTERNAL | NOTMUCH_FIELD_PROCESSOR }, -#endif { "from", "XFROM", NOTMUCH_FIELD_EXTERNAL | NOTMUCH_FIELD_PROBABILISTIC | NOTMUCH_FIELD_PROCESSOR }, @@ -380,7 +378,6 @@ _setup_user_query_fields (notmuch_database_t *notmuch) return NOTMUCH_STATUS_SUCCESS; } -#if HAVE_XAPIAN_FIELD_PROCESSOR static void _setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch) { @@ -388,8 +385,8 @@ _setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch) Xapian::FieldProcessor *fp; if (STRNCMP_LITERAL (prefix->name, "date") == 0) - fp = (new DateFieldProcessor ())->release (); - else if (STRNCMP_LITERAL (prefix->name, "query") == 0) + fp = (new DateFieldProcessor(NOTMUCH_VALUE_TIMESTAMP))->release (); + else if (STRNCMP_LITERAL(prefix->name, "query") == 0) fp = (new QueryFieldProcessor (*notmuch->query_parser, notmuch))->release (); else if (STRNCMP_LITERAL (prefix->name, "thread") == 0) fp = (new ThreadFieldProcessor (*notmuch->query_parser, notmuch))->release (); @@ -405,13 +402,6 @@ _setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch) _setup_query_field_default (prefix, notmuch); } } -#else -static inline void -_setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch) -{ - _setup_query_field_default (prefix, notmuch); -} -#endif const char * _find_prefix (const char *name) @@ -1046,17 +1036,16 @@ notmuch_database_open_verbose (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->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP); - notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:"); - + notmuch->value_range_processor = new Xapian::NumberRangeProcessor (NOTMUCH_VALUE_TIMESTAMP); + notmuch->date_range_processor = new ParseTimeRangeProcessor (NOTMUCH_VALUE_TIMESTAMP, "date:"); + notmuch->last_mod_range_processor = new Xapian::NumberRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:"); 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->date_range_processor); - notmuch->query_parser->add_valuerangeprocessor (notmuch->last_mod_range_processor); + notmuch->query_parser->add_rangeprocessor (notmuch->value_range_processor); + notmuch->query_parser->add_rangeprocessor (notmuch->date_range_processor); + notmuch->query_parser->add_rangeprocessor (notmuch->last_mod_range_processor); for (i = 0; i < ARRAY_SIZE (prefix_table); i++) { const prefix_t *prefix = &prefix_table[i]; @@ -1087,6 +1076,10 @@ notmuch_database_open_verbose (const char *path, *database = notmuch; else talloc_free (notmuch); + + if (notmuch) + notmuch->open = true; + return status; } @@ -1098,7 +1091,7 @@ notmuch_database_close (notmuch_database_t *notmuch) /* Many Xapian objects (and thus notmuch objects) hold references to * the database, so merely deleting the database may not suffice to * close it. Thus, we explicitly close it here. */ - if (notmuch->xapian_db != NULL) { + if (notmuch->open) { try { /* If there's an outstanding transaction, it's unclear if * closing the Xapian database commits everything up to @@ -1121,20 +1114,7 @@ notmuch_database_close (notmuch_database_t *notmuch) } } } - - delete notmuch->term_gen; - notmuch->term_gen = NULL; - delete notmuch->query_parser; - notmuch->query_parser = NULL; - delete notmuch->xapian_db; - notmuch->xapian_db = NULL; - delete notmuch->value_range_processor; - notmuch->value_range_processor = NULL; - delete notmuch->date_range_processor; - notmuch->date_range_processor = NULL; - delete notmuch->last_mod_range_processor; - notmuch->last_mod_range_processor = NULL; - + notmuch->open = false; return status; } @@ -1291,11 +1271,7 @@ notmuch_database_compact (const char *path, try { NotmuchCompactor compactor (status_cb, closure); - - compactor.set_renumber (false); - compactor.add_source (xapian_path); - compactor.set_destdir (compact_xapian_path); - compactor.compact (); + notmuch->xapian_db->compact (compact_xapian_path, Xapian::DBCOMPACT_NO_RENUMBER, 0, compactor); } catch (const Xapian::Error &error) { _notmuch_database_log (notmuch, "Error while compacting: %s\n", error.get_msg ().c_str ()); ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION; @@ -1351,6 +1327,20 @@ notmuch_database_destroy (notmuch_database_t *notmuch) notmuch_status_t status; status = notmuch_database_close (notmuch); + + delete notmuch->term_gen; + notmuch->term_gen = NULL; + delete notmuch->query_parser; + notmuch->query_parser = NULL; + delete notmuch->xapian_db; + notmuch->xapian_db = NULL; + delete notmuch->value_range_processor; + notmuch->value_range_processor = NULL; + delete notmuch->date_range_processor; + notmuch->date_range_processor = NULL; + delete notmuch->last_mod_range_processor; + notmuch->last_mod_range_processor = NULL; + talloc_free (notmuch); return status; @@ -1415,8 +1405,8 @@ handle_sigalrm (unused (int signal)) */ notmuch_status_t notmuch_database_upgrade (notmuch_database_t *notmuch, - void (*progress_notify)(void *closure, - double progress), + void (*progress_notify) (void *closure, + double progress), void *closure) { void *local = talloc_new (NULL);