* fix unit tests (i.e.. fix re-indexing messages bug)
This commit is contained in:
@ -37,7 +37,6 @@
|
||||
#endif /*PATH_MAX */
|
||||
|
||||
#include <gmime/gmime.h>
|
||||
|
||||
#include "mu-util.h"
|
||||
#include "mu-str.h"
|
||||
#include "mu-maildir.h"
|
||||
|
||||
@ -49,20 +49,19 @@ _MuStore::get_uid_term (const char* path)
|
||||
|
||||
unsigned djbhash, bkdrhash, bkdrseed;
|
||||
unsigned u;
|
||||
static char hex[10];
|
||||
static char hex[18];
|
||||
|
||||
djbhash = 5381;
|
||||
bkdrhash = 0;
|
||||
bkdrseed = 1313;
|
||||
|
||||
|
||||
for(u = 0; path[u]; ++u) {
|
||||
djbhash = ((djbhash << 5) + djbhash) + path[u];
|
||||
bkdrhash = bkdrhash * bkdrseed + path[u];
|
||||
}
|
||||
|
||||
snprintf (hex, sizeof(hex),
|
||||
MU_STORE_UID_PREFIX "%04x%04x",
|
||||
MU_STORE_UID_PREFIX "%08x%08x",
|
||||
djbhash, bkdrhash);
|
||||
|
||||
return hex;
|
||||
@ -162,8 +161,12 @@ mu_store_contains_message (MuStore *store, const char* path, GError **err)
|
||||
g_return_val_if_fail (path, FALSE);
|
||||
|
||||
try {
|
||||
const std::string uid (store->get_uid_term (path));
|
||||
return store->db_read_only()->term_exists (uid) ? TRUE: FALSE;
|
||||
const std::string term (store->get_uid_term(path));
|
||||
|
||||
MU_WRITE_LOG ("term exists? '%s': %s", term.c_str(),
|
||||
store->db_read_only()->term_exists (term) ? "yes" : "no");
|
||||
|
||||
return store->db_read_only()->term_exists (term) ? TRUE: FALSE;
|
||||
|
||||
} MU_XAPIAN_CATCH_BLOCK_G_ERROR_RETURN(err, MU_ERROR_XAPIAN, FALSE);
|
||||
|
||||
@ -177,7 +180,8 @@ mu_store_get_docid_for_path (MuStore *store, const char* path, GError **err)
|
||||
g_return_val_if_fail (path, FALSE);
|
||||
|
||||
try {
|
||||
Xapian::Query query (store->get_uid_term (path)); // uid is a term
|
||||
const std::string term (store->get_uid_term(path));
|
||||
Xapian::Query query (term);
|
||||
Xapian::Enquire enq (*store->db_read_only());
|
||||
|
||||
enq.set_query (query);
|
||||
|
||||
@ -88,7 +88,7 @@ prefix (MuMsgFieldId mfid)
|
||||
static void
|
||||
add_synonym_for_flag (MuFlags flag, Xapian::WritableDatabase *db)
|
||||
{
|
||||
const std::string pfx(prefix(MU_MSG_FIELD_ID_FLAGS));
|
||||
static const std::string pfx(prefix(MU_MSG_FIELD_ID_FLAGS));
|
||||
|
||||
db->clear_synonyms (pfx + mu_flag_name (flag));
|
||||
db->add_synonym (pfx + mu_flag_name (flag), pfx +
|
||||
@ -99,7 +99,7 @@ add_synonym_for_flag (MuFlags flag, Xapian::WritableDatabase *db)
|
||||
static void
|
||||
add_synonym_for_prio (MuMsgPrio prio, Xapian::WritableDatabase *db)
|
||||
{
|
||||
const std::string pfx (prefix(MU_MSG_FIELD_ID_PRIO));
|
||||
static const std::string pfx (prefix(MU_MSG_FIELD_ID_PRIO));
|
||||
|
||||
std::string s1 (pfx + mu_msg_prio_name (prio));
|
||||
std::string s2 (pfx + (std::string(1, mu_msg_prio_char (prio))));
|
||||
@ -567,6 +567,7 @@ new_doc_from_message (MuStore *store, MuMsg *msg)
|
||||
/* also store the contact-info as separate terms */
|
||||
mu_msg_contact_foreach (msg, (MuMsgContactForeachFunc)each_contact_info,
|
||||
&docinfo);
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
@ -580,17 +581,18 @@ mu_store_add_msg (MuStore *store, MuMsg *msg, GError **err)
|
||||
try {
|
||||
Xapian::docid id;
|
||||
Xapian::Document doc (new_doc_from_message(store, msg));
|
||||
const std::string uid (store->get_uid_term(mu_msg_get_path(msg)));
|
||||
const std::string term (store->get_uid_term
|
||||
(mu_msg_get_path(msg)));
|
||||
|
||||
if (!store->in_transaction())
|
||||
store->begin_transaction();
|
||||
|
||||
/* note, this will replace any other messages for this path */
|
||||
doc.add_term (uid);
|
||||
id = store->db_writable()->replace_document (uid, doc);
|
||||
doc.add_term (term);
|
||||
|
||||
MU_WRITE_LOG ("add %s (%s)",
|
||||
mu_msg_get_path (msg), uid.c_str());
|
||||
MU_WRITE_LOG ("adding: %s", term.c_str());
|
||||
|
||||
/* note, this will replace any other messages for this path */
|
||||
id = store->db_writable()->replace_document (term, doc);
|
||||
|
||||
if (store->inc_processed() % store->batch_size() == 0)
|
||||
store->commit_transaction();
|
||||
@ -619,12 +621,12 @@ mu_store_update_msg (MuStore *store, unsigned docid, MuMsg *msg, GError **err)
|
||||
if (!store->in_transaction())
|
||||
store->begin_transaction();
|
||||
|
||||
store->db_writable()->replace_document (docid, doc);
|
||||
|
||||
MU_WRITE_LOG ("update %s (%s) %u",
|
||||
mu_msg_get_path (msg),
|
||||
store->get_uid_term(mu_msg_get_path(msg)),
|
||||
docid);
|
||||
const std::string term
|
||||
(store->get_uid_term(mu_msg_get_path(msg)));
|
||||
doc.add_term (term);
|
||||
|
||||
store->db_writable()->replace_document (docid, doc);
|
||||
|
||||
if (store->inc_processed() % store->batch_size() == 0)
|
||||
store->commit_transaction();
|
||||
@ -679,7 +681,10 @@ mu_store_remove_path (MuStore *store, const char *msgpath)
|
||||
g_return_val_if_fail (msgpath, FALSE);
|
||||
|
||||
try {
|
||||
store->db_writable()->delete_document (store->get_uid_term (msgpath));
|
||||
const std::string term
|
||||
(store->get_uid_term(msgpath));
|
||||
|
||||
store->db_writable()->delete_document (term);
|
||||
store->inc_processed();
|
||||
|
||||
return TRUE;
|
||||
|
||||
@ -463,7 +463,7 @@ mu_str_ascii_xapian_escape_in_place (char *query)
|
||||
* a space'... ugh yuck ugly...
|
||||
*/
|
||||
if (!is_xapian_prefix (query, cur))
|
||||
*cur = '_';
|
||||
*cur = ' ';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -542,7 +542,7 @@ test_mu_query_tags_02 (void)
|
||||
{ "x:paradise", 1},
|
||||
{ "tag:@NextActions", 1},
|
||||
{ "x:queensrÿche", 1},
|
||||
{ "tag:lost OR tag:operation:mindcrime", 2},
|
||||
{ "tag:lost OR tag:operation*", 2},
|
||||
};
|
||||
|
||||
xpath = fill_database (MU_TESTMAILDIR2);
|
||||
@ -605,4 +605,3 @@ main (int argc, char *argv[])
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@ -167,7 +167,7 @@ test_mu_str_ascii_xapian_escape (void)
|
||||
{ "Foo.Bar", "foo_bar" },
|
||||
{ "Foo. Bar", "foo. bar" },
|
||||
{ "subject:test@foo", "subject:test_foo" },
|
||||
{ "xxx:test@bar", "xxx_test_bar" },
|
||||
{ "xxx:test@bar", "xxx test_bar" },
|
||||
};
|
||||
|
||||
for (i = 0; i != G_N_ELEMENTS(words); ++i) {
|
||||
|
||||
Reference in New Issue
Block a user