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