mirror of https://github.com/djcb/mu.git
* mu-query: some cleanups
This commit is contained in:
parent
656004ee9e
commit
186e44ca66
|
@ -191,12 +191,22 @@ struct _MuQuery {
|
||||||
Xapian::ValueRangeProcessor* _size_range_processor;
|
Xapian::ValueRangeProcessor* _size_range_processor;
|
||||||
};
|
};
|
||||||
|
|
||||||
gboolean
|
static void
|
||||||
|
uninit_mu_query (MuQuery *mqx)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
delete mqx->_db;
|
||||||
|
delete mqx->_qparser;
|
||||||
|
|
||||||
|
delete mqx->_date_range_processor;
|
||||||
|
delete mqx->_size_range_processor;
|
||||||
|
|
||||||
|
} MU_XAPIAN_CATCH_BLOCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
init_mu_query (MuQuery *mqx, const char* dbpath)
|
init_mu_query (MuQuery *mqx, const char* dbpath)
|
||||||
{
|
{
|
||||||
mqx->_db = 0;
|
|
||||||
mqx->_qparser = 0;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mqx->_db = new Xapian::Database(dbpath);
|
mqx->_db = new Xapian::Database(dbpath);
|
||||||
mqx->_qparser = new Xapian::QueryParser;
|
mqx->_qparser = new Xapian::QueryParser;
|
||||||
|
@ -222,30 +232,12 @@ init_mu_query (MuQuery *mqx, const char* dbpath)
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK;
|
} MU_XAPIAN_CATCH_BLOCK;
|
||||||
|
|
||||||
try {
|
// things went wrong, cleanup resources
|
||||||
delete mqx->_db;
|
uninit_mu_query (mqx);
|
||||||
delete mqx->_qparser;
|
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK;
|
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
uninit_mu_query (MuQuery *mqx)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
delete mqx->_db;
|
|
||||||
delete mqx->_qparser;
|
|
||||||
|
|
||||||
delete mqx->_date_range_processor;
|
|
||||||
delete mqx->_size_range_processor;
|
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
set_query (MuQuery *mqx, Xapian::Query& q, const char* searchexpr,
|
set_query (MuQuery *mqx, Xapian::Query& q, const char* searchexpr,
|
||||||
GError **err) {
|
GError **err) {
|
||||||
|
@ -323,7 +315,7 @@ mu_query_new (const char* xpath, GError **err)
|
||||||
if (mu_util_xapian_is_empty (xpath))
|
if (mu_util_xapian_is_empty (xpath))
|
||||||
g_warning ("database %s is empty; nothing to do", xpath);
|
g_warning ("database %s is empty; nothing to do", xpath);
|
||||||
|
|
||||||
mqx = g_new (MuQuery, 1);
|
mqx = g_new0 (MuQuery, 1);
|
||||||
|
|
||||||
if (!init_mu_query (mqx, xpath)) {
|
if (!init_mu_query (mqx, xpath)) {
|
||||||
g_set_error (err, 0, MU_ERROR_INTERNAL,
|
g_set_error (err, 0, MU_ERROR_INTERNAL,
|
||||||
|
|
|
@ -210,6 +210,7 @@ test_mu_query_05 (void)
|
||||||
MuMsgIter *iter;
|
MuMsgIter *iter;
|
||||||
MuMsg *msg;
|
MuMsg *msg;
|
||||||
gchar *xpath;
|
gchar *xpath;
|
||||||
|
GError *err;
|
||||||
|
|
||||||
xpath = fill_database ();
|
xpath = fill_database ();
|
||||||
g_assert (xpath != NULL);
|
g_assert (xpath != NULL);
|
||||||
|
@ -217,8 +218,14 @@ test_mu_query_05 (void)
|
||||||
query = mu_query_new (xpath, NULL);
|
query = mu_query_new (xpath, NULL);
|
||||||
iter = mu_query_run (query, "fünkÿ", MU_MSG_FIELD_ID_NONE,
|
iter = mu_query_run (query, "fünkÿ", MU_MSG_FIELD_ID_NONE,
|
||||||
FALSE, 1, NULL);
|
FALSE, 1, NULL);
|
||||||
msg = mu_msg_iter_get_msg (iter, NULL);
|
err = NULL;
|
||||||
|
msg = mu_msg_iter_get_msg (iter, &err);
|
||||||
|
if (!msg) {
|
||||||
|
g_warning ("error getting message: %s", err->message);
|
||||||
|
g_error_free (err);
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
|
||||||
g_assert_cmpstr (mu_msg_get_subject(msg),==,
|
g_assert_cmpstr (mu_msg_get_subject(msg),==,
|
||||||
"Greetings from Lothlórien");
|
"Greetings from Lothlórien");
|
||||||
g_assert_cmpstr (mu_msg_get_summary(msg,5),==,
|
g_assert_cmpstr (mu_msg_get_summary(msg,5),==,
|
||||||
|
|
Loading…
Reference in New Issue