2011-05-21 19:20:07 +02:00
|
|
|
/* -*-mode: c++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8-*- */
|
2009-11-25 21:55:06 +01:00
|
|
|
/*
|
2011-01-15 12:27:41 +01:00
|
|
|
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2009-11-25 21:55:06 +01:00
|
|
|
**
|
|
|
|
** This program is free software; you can redistribute it and/or modify it
|
|
|
|
** under the terms of the GNU General Public License as published by the
|
|
|
|
** Free Software Foundation; either version 3, or (at your option) any
|
|
|
|
** later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program; if not, write to the Free Software Foundation,
|
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2010-11-11 21:05:55 +01:00
|
|
|
#if HAVE_CONFIG_H
|
2009-11-25 21:55:06 +01:00
|
|
|
#include "config.h"
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
|
2010-01-22 18:18:23 +01:00
|
|
|
#include <cstdio>
|
|
|
|
#include <xapian.h>
|
2010-09-12 15:28:34 +02:00
|
|
|
#include <cstring>
|
2011-03-22 22:37:01 +01:00
|
|
|
#include <stdexcept>
|
2010-01-22 18:18:23 +01:00
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
#include "mu-msg.h"
|
2011-05-21 15:06:52 +02:00
|
|
|
#include "mu-msg-part.h"
|
2010-08-25 20:55:08 +02:00
|
|
|
#include "mu-store.h"
|
2010-01-05 07:32:23 +01:00
|
|
|
#include "mu-util.h"
|
2010-11-22 23:44:18 +01:00
|
|
|
#include "mu-str.h"
|
2010-11-20 15:37:23 +01:00
|
|
|
#include "mu-msg-flags.h"
|
2011-03-01 23:13:24 +01:00
|
|
|
#include "mu-contacts.h"
|
2011-01-12 22:13:03 +01:00
|
|
|
|
2011-01-02 17:05:43 +01:00
|
|
|
/* by default, use transactions of 30000 messages */
|
|
|
|
#define MU_STORE_DEFAULT_TRX_SIZE 30000
|
2009-12-05 15:37:45 +01:00
|
|
|
|
2010-01-22 18:18:23 +01:00
|
|
|
/* http://article.gmane.org/gmane.comp.search.xapian.general/3656 */
|
2010-08-25 20:55:08 +02:00
|
|
|
#define MU_STORE_MAX_TERM_LENGTH 240
|
2010-01-22 18:18:23 +01:00
|
|
|
|
2011-03-22 22:37:01 +01:00
|
|
|
static void add_synonyms (MuStore *store);
|
|
|
|
static gboolean check_version (MuStore *store);
|
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
struct _MuStore {
|
2011-03-22 22:37:01 +01:00
|
|
|
_MuStore (const char *xpath, const char *contacts_cache) :
|
|
|
|
_db (xpath, Xapian::DB_CREATE_OR_OPEN), _in_transaction(0),
|
|
|
|
_processed (0), _trx_size(MU_STORE_DEFAULT_TRX_SIZE), _contacts (0),
|
2011-04-30 10:31:34 +02:00
|
|
|
_version (0) {
|
2011-03-22 22:37:01 +01:00
|
|
|
|
|
|
|
if (!check_version (this))
|
|
|
|
throw std::runtime_error
|
|
|
|
("xapian db version check failed");
|
|
|
|
|
|
|
|
if (contacts_cache) {
|
|
|
|
_contacts = mu_contacts_new (contacts_cache);
|
|
|
|
if (!_contacts) /* don't bail-out for this */
|
|
|
|
throw std::runtime_error
|
|
|
|
("failed to init contacts cache");
|
|
|
|
}
|
|
|
|
|
|
|
|
add_synonyms (this);
|
|
|
|
MU_WRITE_LOG ("%s: opened %s (batch size: %u)",
|
|
|
|
__FUNCTION__, xpath, _trx_size);
|
|
|
|
}
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2011-03-22 22:37:01 +01:00
|
|
|
~_MuStore () {
|
|
|
|
try {
|
2011-04-30 09:09:12 +02:00
|
|
|
g_free (_version);
|
2011-05-01 14:55:25 +02:00
|
|
|
mu_contacts_destroy (_contacts);
|
|
|
|
mu_store_flush (this);
|
2011-03-22 22:37:01 +01:00
|
|
|
|
|
|
|
MU_WRITE_LOG ("closing xapian database with %d documents",
|
|
|
|
(int)_db.get_doccount());
|
2011-05-01 14:55:25 +02:00
|
|
|
|
2011-03-22 22:37:01 +01:00
|
|
|
} MU_XAPIAN_CATCH_BLOCK;
|
|
|
|
}
|
2011-03-01 23:13:24 +01:00
|
|
|
|
2011-03-22 22:37:01 +01:00
|
|
|
Xapian::WritableDatabase _db;
|
2010-11-20 13:43:04 +01:00
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
/* transaction handling */
|
|
|
|
bool _in_transaction;
|
|
|
|
int _processed;
|
2010-01-05 08:08:39 +01:00
|
|
|
size_t _trx_size;
|
2011-03-22 22:37:01 +01:00
|
|
|
guint _batchsize; /* batch size of a xapian transaction */
|
2011-04-30 10:31:34 +02:00
|
|
|
|
2011-03-22 22:37:01 +01:00
|
|
|
/* contacts object to cache all the contact information */
|
|
|
|
MuContacts *_contacts;
|
|
|
|
|
|
|
|
char *_version;
|
2009-11-25 21:55:06 +01:00
|
|
|
};
|
|
|
|
|
2010-11-20 13:43:04 +01:00
|
|
|
|
2011-05-01 14:55:25 +02:00
|
|
|
/* we cache these prefix strings, so we don't have to allocate the all
|
|
|
|
* the time; this should save 10-20 string allocs per message */
|
|
|
|
G_GNUC_CONST static const std::string&
|
|
|
|
prefix (MuMsgFieldId mfid)
|
|
|
|
{
|
|
|
|
static std::string fields[MU_MSG_FIELD_ID_NUM];
|
|
|
|
static bool initialized = false;
|
|
|
|
|
|
|
|
if (G_UNLIKELY(!initialized)) {
|
|
|
|
for (int i = 0; i != MU_MSG_FIELD_ID_NUM; ++i)
|
|
|
|
fields[i] = std::string (1, mu_msg_field_xapian_prefix
|
|
|
|
((MuMsgFieldId)i));
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fields[mfid];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-20 13:43:04 +01:00
|
|
|
static void
|
2010-11-21 12:41:01 +01:00
|
|
|
add_synonym_for_flag (MuMsgFlags flag, Xapian::WritableDatabase *db)
|
2010-11-20 13:43:04 +01:00
|
|
|
{
|
2011-05-01 14:55:25 +02:00
|
|
|
const std::string pfx(prefix(MU_MSG_FIELD_ID_FLAGS));
|
2010-11-21 14:42:53 +01:00
|
|
|
|
|
|
|
db->clear_synonyms (pfx + mu_msg_flag_name (flag));
|
2011-05-01 14:55:25 +02:00
|
|
|
db->add_synonym (pfx + mu_msg_flag_name (flag), pfx +
|
|
|
|
(std::string(1, mu_msg_flag_char (flag))));
|
2010-11-20 15:37:23 +01:00
|
|
|
}
|
2010-11-20 13:43:04 +01:00
|
|
|
|
2010-11-21 14:42:53 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
add_synonym_for_prio (MuMsgPrio prio, Xapian::WritableDatabase *db)
|
|
|
|
{
|
2011-05-01 14:55:25 +02:00
|
|
|
const std::string pfx (prefix(MU_MSG_FIELD_ID_PRIO));
|
2010-11-21 14:42:53 +01:00
|
|
|
|
|
|
|
std::string s1 (pfx + mu_msg_prio_name (prio));
|
|
|
|
std::string s2 (pfx + (std::string(1, mu_msg_prio_char (prio))));
|
|
|
|
|
|
|
|
db->clear_synonyms (s1);
|
|
|
|
db->clear_synonyms (s2);
|
|
|
|
|
|
|
|
db->add_synonym (s1, s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-20 15:37:23 +01:00
|
|
|
static void
|
|
|
|
add_synonyms (MuStore *store)
|
|
|
|
{
|
2010-11-21 12:41:01 +01:00
|
|
|
mu_msg_flags_foreach ((MuMsgFlagsForeachFunc)add_synonym_for_flag,
|
2011-03-22 22:37:01 +01:00
|
|
|
&store->_db);
|
2010-11-21 14:42:53 +01:00
|
|
|
mu_msg_prio_foreach ((MuMsgPrioForeachFunc)add_synonym_for_prio,
|
2011-03-22 22:37:01 +01:00
|
|
|
&store->_db);
|
2010-11-20 13:43:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
check_version (MuStore *store)
|
|
|
|
{
|
|
|
|
/* FIXME clear up versioning semantics */
|
|
|
|
const gchar *version;
|
2011-01-12 22:13:03 +01:00
|
|
|
|
2010-11-20 13:43:04 +01:00
|
|
|
version = mu_store_version (store);
|
|
|
|
|
|
|
|
/* no version yet? it must be a new db then; we'll set the version */
|
|
|
|
if (!version) {
|
2011-01-12 22:13:03 +01:00
|
|
|
if (!mu_store_set_metadata (store, MU_STORE_VERSION_KEY,
|
|
|
|
MU_XAPIAN_DB_VERSION)) {
|
2010-11-20 13:43:04 +01:00
|
|
|
g_warning ("failed to set database version");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE; /* ok, done. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have a version, but is it the right one? */
|
|
|
|
if (std::strcmp (version, MU_XAPIAN_DB_VERSION) != 0) {
|
|
|
|
g_warning ("expected db version %s, but got %s",
|
2011-01-12 22:13:03 +01:00
|
|
|
MU_XAPIAN_DB_VERSION,
|
|
|
|
version ? version : "<none>" );
|
2010-11-20 13:43:04 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-08-25 20:55:08 +02:00
|
|
|
MuStore*
|
2011-03-01 23:13:24 +01:00
|
|
|
mu_store_new (const char* xpath, const char *contacts_cache,
|
|
|
|
GError **err)
|
2009-11-25 21:55:06 +01:00
|
|
|
{
|
2010-01-06 00:20:30 +01:00
|
|
|
g_return_val_if_fail (xpath, NULL);
|
2011-01-12 22:13:03 +01:00
|
|
|
|
2011-03-22 22:37:01 +01:00
|
|
|
try {
|
|
|
|
return new _MuStore (xpath, contacts_cache);
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2010-11-24 19:04:20 +01:00
|
|
|
} MU_XAPIAN_CATCH_BLOCK_G_ERROR(err,MU_ERROR_XAPIAN);
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2010-01-05 07:32:23 +01:00
|
|
|
return NULL;
|
2009-11-25 21:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-20 13:43:04 +01:00
|
|
|
void
|
|
|
|
mu_store_destroy (MuStore *store)
|
|
|
|
{
|
2011-03-22 22:37:01 +01:00
|
|
|
try { delete store; } MU_XAPIAN_CATCH_BLOCK;
|
2010-11-20 13:43:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-15 12:27:41 +01:00
|
|
|
void
|
|
|
|
mu_store_set_batch_size (MuStore *store, guint batchsize)
|
|
|
|
{
|
|
|
|
g_return_if_fail (store);
|
2011-03-22 22:37:01 +01:00
|
|
|
|
|
|
|
store->_trx_size = batchsize ? batchsize : MU_STORE_DEFAULT_TRX_SIZE;
|
2011-01-15 12:27:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-23 20:57:57 +01:00
|
|
|
|
2010-09-26 14:52:22 +02:00
|
|
|
unsigned
|
|
|
|
mu_store_count (MuStore *store)
|
|
|
|
{
|
2010-09-26 16:29:54 +02:00
|
|
|
g_return_val_if_fail (store, 0);
|
2010-09-26 14:52:22 +02:00
|
|
|
|
|
|
|
try {
|
2011-03-22 22:37:01 +01:00
|
|
|
return store->_db.get_doccount();
|
2010-09-26 14:52:22 +02:00
|
|
|
|
|
|
|
} MU_XAPIAN_CATCH_BLOCK;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-20 13:43:04 +01:00
|
|
|
const char*
|
2010-08-25 20:55:08 +02:00
|
|
|
mu_store_version (MuStore *store)
|
2010-01-23 19:50:06 +01:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (store, NULL);
|
2010-11-20 13:43:04 +01:00
|
|
|
|
2011-01-12 22:13:03 +01:00
|
|
|
g_free (store->_version);
|
|
|
|
return store->_version =
|
|
|
|
mu_store_get_metadata (store, MU_STORE_VERSION_KEY);
|
2010-01-23 19:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2011-01-12 22:13:03 +01:00
|
|
|
mu_store_set_metadata (MuStore *store, const char *key, const char *val)
|
2010-01-23 19:50:06 +01:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (store, FALSE);
|
2011-01-12 22:13:03 +01:00
|
|
|
g_return_val_if_fail (key, FALSE);
|
|
|
|
g_return_val_if_fail (val, FALSE);
|
|
|
|
|
2010-01-23 19:50:06 +01:00
|
|
|
try {
|
2011-03-22 22:37:01 +01:00
|
|
|
store->_db.set_metadata (key, val);
|
2010-01-23 19:50:06 +01:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
} MU_XAPIAN_CATCH_BLOCK;
|
|
|
|
|
2011-01-12 22:13:03 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char*
|
|
|
|
mu_store_get_metadata (MuStore *store, const char *key)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (store, NULL);
|
|
|
|
g_return_val_if_fail (key, NULL);
|
|
|
|
|
|
|
|
try {
|
2011-03-22 22:37:01 +01:00
|
|
|
const std::string val (store->_db.get_metadata (key));
|
2011-01-12 22:13:03 +01:00
|
|
|
return val.empty() ? NULL : g_strdup (val.c_str());
|
|
|
|
|
|
|
|
} MU_XAPIAN_CATCH_BLOCK;
|
|
|
|
|
|
|
|
return NULL;
|
2010-01-23 19:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-12 22:13:03 +01:00
|
|
|
|
2010-01-05 08:08:39 +01:00
|
|
|
static void
|
2010-08-25 20:55:08 +02:00
|
|
|
begin_trx_if (MuStore *store, gboolean cond)
|
2010-01-05 08:08:39 +01:00
|
|
|
{
|
|
|
|
if (cond) {
|
2010-01-06 00:20:30 +01:00
|
|
|
g_debug ("beginning Xapian transaction");
|
2011-03-22 22:37:01 +01:00
|
|
|
store->_db.begin_transaction();
|
2010-01-05 08:08:39 +01:00
|
|
|
store->_in_transaction = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-08-25 20:55:08 +02:00
|
|
|
commit_trx_if (MuStore *store, gboolean cond)
|
2010-01-05 08:08:39 +01:00
|
|
|
{
|
|
|
|
if (cond) {
|
2010-01-06 00:20:30 +01:00
|
|
|
g_debug ("comitting Xapian transaction");
|
2010-01-05 08:08:39 +01:00
|
|
|
store->_in_transaction = false;
|
2011-03-22 22:37:01 +01:00
|
|
|
store->_db.commit_transaction();
|
2010-01-05 08:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-08-25 20:55:08 +02:00
|
|
|
rollback_trx_if (MuStore *store, gboolean cond)
|
2010-01-05 08:08:39 +01:00
|
|
|
{
|
|
|
|
if (cond) {
|
2010-01-06 00:20:30 +01:00
|
|
|
g_debug ("rolling back Xapian transaction");
|
2010-01-05 08:08:39 +01:00
|
|
|
store->_in_transaction = false;
|
2011-03-22 22:37:01 +01:00
|
|
|
store->_db.cancel_transaction();
|
2010-01-05 08:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-06 00:20:30 +01:00
|
|
|
void
|
2010-08-25 20:55:08 +02:00
|
|
|
mu_store_flush (MuStore *store)
|
2010-01-06 00:20:30 +01:00
|
|
|
{
|
|
|
|
g_return_if_fail (store);
|
|
|
|
|
|
|
|
try {
|
2010-01-23 12:41:42 +01:00
|
|
|
commit_trx_if (store, store->_in_transaction);
|
2011-03-22 22:37:01 +01:00
|
|
|
store->_db.flush (); /* => commit, post X 1.1.x */
|
2010-01-06 00:20:30 +01:00
|
|
|
|
|
|
|
} MU_XAPIAN_CATCH_BLOCK;
|
2009-11-25 21:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 17:12:01 +01:00
|
|
|
static void
|
|
|
|
add_terms_values_date (Xapian::Document& doc, MuMsg *msg,
|
|
|
|
MuMsgFieldId mfid)
|
|
|
|
{
|
2010-11-22 23:33:15 +01:00
|
|
|
char datebuf[13]; /* YYYYMMDDHHMMSS */
|
2010-11-21 17:12:01 +01:00
|
|
|
static const std::string pfx (1, mu_msg_field_xapian_prefix(mfid));
|
|
|
|
gint64 num = mu_msg_get_field_numeric (msg, mfid);
|
|
|
|
|
2010-11-22 23:33:15 +01:00
|
|
|
if (G_UNLIKELY(strftime(datebuf, sizeof(datebuf), "%Y%m%d%H%M",
|
|
|
|
localtime((const time_t*)&num)) == 0))
|
2010-11-21 17:12:01 +01:00
|
|
|
g_return_if_reached();
|
2010-11-22 23:33:15 +01:00
|
|
|
|
2010-11-21 17:12:01 +01:00
|
|
|
const std::string numstr (Xapian::sortable_serialise((double)num));
|
|
|
|
doc.add_value ((Xapian::valueno)mfid, numstr);
|
2010-11-22 23:33:15 +01:00
|
|
|
doc.add_value ((Xapian::valueno)MU_MSG_PSEUDO_FIELD_ID_DATESTR,
|
|
|
|
datebuf);
|
2010-11-21 17:12:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
static void
|
2011-03-31 22:08:26 +02:00
|
|
|
add_terms_values_number (Xapian::Document& doc, MuMsg *msg, MuMsgFieldId mfid)
|
2009-11-25 21:55:06 +01:00
|
|
|
{
|
2010-11-20 13:43:04 +01:00
|
|
|
gint64 num = mu_msg_get_field_numeric (msg, mfid);
|
2011-03-31 22:08:26 +02:00
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
const std::string numstr (Xapian::sortable_serialise((double)num));
|
2010-11-20 13:43:04 +01:00
|
|
|
doc.add_value ((Xapian::valueno)mfid, numstr);
|
|
|
|
|
|
|
|
if (mfid == MU_MSG_FIELD_ID_FLAGS) {
|
2011-03-31 22:08:26 +02:00
|
|
|
for (const char *cur = mu_msg_flags_str_s ((MuMsgFlags)num);
|
|
|
|
cur && *cur; ++cur)
|
2011-05-01 14:55:25 +02:00
|
|
|
doc.add_term (prefix(mfid) + (char)tolower (*cur));
|
2010-11-21 14:42:53 +01:00
|
|
|
|
|
|
|
} else if (mfid == MU_MSG_FIELD_ID_PRIO) {
|
2011-05-01 14:55:25 +02:00
|
|
|
doc.add_term (prefix(mfid) + std::string(1,
|
2010-11-21 14:42:53 +01:00
|
|
|
mu_msg_prio_char((MuMsgPrio)num)));
|
2011-06-15 22:52:32 +02:00
|
|
|
}
|
2009-11-25 21:55:06 +01:00
|
|
|
}
|
|
|
|
|
2011-06-15 22:52:32 +02:00
|
|
|
|
|
|
|
/* for string and string-list */
|
2009-11-25 21:55:06 +01:00
|
|
|
static void
|
2011-06-15 22:52:32 +02:00
|
|
|
add_terms_values_str (Xapian::Document& doc, char *val,
|
|
|
|
MuMsgFieldId mfid)
|
2009-11-25 21:55:06 +01:00
|
|
|
{
|
2010-11-29 20:29:43 +01:00
|
|
|
/* the value is what we'll display; the unchanged original */
|
|
|
|
if (mu_msg_field_xapian_value(mfid))
|
|
|
|
doc.add_value ((Xapian::valueno)mfid, val);
|
2011-06-15 22:52:32 +02:00
|
|
|
|
2010-11-29 20:29:43 +01:00
|
|
|
/* now, let's create some search terms... */
|
|
|
|
if (mu_msg_field_normalize (mfid))
|
|
|
|
mu_str_normalize_in_place (val, TRUE);
|
|
|
|
if (mu_msg_field_xapian_escape (mfid))
|
|
|
|
mu_str_ascii_xapian_escape_in_place (val);
|
2011-06-15 22:52:32 +02:00
|
|
|
|
2010-11-20 13:43:04 +01:00
|
|
|
if (mu_msg_field_xapian_index (mfid)) {
|
2009-11-25 21:55:06 +01:00
|
|
|
Xapian::TermGenerator termgen;
|
|
|
|
termgen.set_document (doc);
|
2011-05-01 14:55:25 +02:00
|
|
|
termgen.index_text_without_positions (val, 1, prefix(mfid));
|
2010-11-01 23:06:17 +01:00
|
|
|
}
|
2010-11-29 20:29:43 +01:00
|
|
|
|
|
|
|
if (mu_msg_field_xapian_term(mfid))
|
2011-05-01 14:55:25 +02:00
|
|
|
doc.add_term (prefix(mfid) +
|
|
|
|
std::string(val, 0, MU_STORE_MAX_TERM_LENGTH));
|
2011-06-15 22:52:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_terms_values_string_list (Xapian::Document& doc, MuMsg *msg,
|
|
|
|
MuMsgFieldId mfid)
|
|
|
|
{
|
|
|
|
const GSList *lst;
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
lst = mu_msg_get_field_string_list (msg, mfid);
|
|
|
|
if (!lst)
|
|
|
|
return; /* nothing to do */
|
|
|
|
|
|
|
|
str = mu_str_from_list (lst, ',');
|
|
|
|
if (!str)
|
|
|
|
return; /* nothing to do */
|
|
|
|
|
|
|
|
add_terms_values_str (doc, str, mfid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_terms_values_string (Xapian::Document& doc, MuMsg *msg,
|
|
|
|
MuMsgFieldId mfid)
|
|
|
|
{
|
|
|
|
const char *orig;
|
|
|
|
char *val;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (!(orig = mu_msg_get_field_string (msg, mfid)))
|
|
|
|
return; /* nothing to do */
|
|
|
|
|
|
|
|
/* try stack-allocation, it's much faster*/
|
|
|
|
len = strlen (orig);
|
|
|
|
val = (char*)(G_LIKELY(len < 1024)?g_alloca(len+1):g_malloc(len+1));
|
|
|
|
strcpy (val, orig);
|
|
|
|
|
|
|
|
add_terms_values_str (doc, val, mfid);
|
2011-05-01 14:55:25 +02:00
|
|
|
|
|
|
|
if (!(G_LIKELY(len < 1024)))
|
|
|
|
g_free (val);
|
2009-11-25 21:55:06 +01:00
|
|
|
}
|
|
|
|
|
2011-05-21 15:06:52 +02:00
|
|
|
struct PartData {
|
|
|
|
PartData (Xapian::Document& doc, MuMsgFieldId mfid):
|
|
|
|
_doc (doc), _mfid(mfid) {}
|
|
|
|
Xapian::Document _doc;
|
|
|
|
MuMsgFieldId _mfid;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
each_part (MuMsg *msg, MuMsgPart *part, PartData *pdata)
|
|
|
|
{
|
|
|
|
if (mu_msg_part_looks_like_attachment (part, TRUE) &&
|
|
|
|
(part->file_name)) {
|
|
|
|
|
|
|
|
char val[MU_STORE_MAX_TERM_LENGTH + 1];
|
|
|
|
strncpy (val, part->file_name, sizeof(val));
|
|
|
|
|
|
|
|
/* now, let's create a terms... */
|
|
|
|
mu_str_normalize_in_place (val, TRUE);
|
|
|
|
mu_str_ascii_xapian_escape_in_place (val);
|
|
|
|
|
|
|
|
pdata->_doc.add_term (prefix(pdata->_mfid) +
|
|
|
|
std::string(val, 0, MU_STORE_MAX_TERM_LENGTH));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_terms_values_attach (Xapian::Document& doc, MuMsg *msg,
|
|
|
|
MuMsgFieldId mfid)
|
|
|
|
{
|
|
|
|
PartData pdata (doc, mfid);
|
|
|
|
mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part, &pdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
static void
|
2010-08-24 23:57:16 +02:00
|
|
|
add_terms_values_body (Xapian::Document& doc, MuMsg *msg,
|
2010-11-20 13:43:04 +01:00
|
|
|
MuMsgFieldId mfid)
|
2009-12-09 19:21:28 +01:00
|
|
|
{
|
|
|
|
const char *str;
|
2010-11-11 21:05:55 +01:00
|
|
|
char *norm;
|
2009-12-09 19:21:28 +01:00
|
|
|
|
2010-08-24 23:57:16 +02:00
|
|
|
if (mu_msg_get_flags(msg) & MU_MSG_FLAG_ENCRYPTED)
|
2010-11-20 15:37:23 +01:00
|
|
|
return; /* ignore encrypted bodies */
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2010-08-24 23:57:16 +02:00
|
|
|
str = mu_msg_get_body_text (msg);
|
2010-02-11 19:20:34 +01:00
|
|
|
if (!str) /* FIXME: html->txt fallback needed */
|
2010-08-24 23:57:16 +02:00
|
|
|
str = mu_msg_get_body_html (msg);
|
2009-11-28 13:47:11 +01:00
|
|
|
|
2010-01-04 21:49:24 +01:00
|
|
|
if (!str)
|
2009-11-25 21:55:06 +01:00
|
|
|
return; /* no body... */
|
2010-11-11 21:05:55 +01:00
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
Xapian::TermGenerator termgen;
|
|
|
|
termgen.set_document(doc);
|
2010-11-11 21:05:55 +01:00
|
|
|
|
2010-11-22 23:44:18 +01:00
|
|
|
norm = mu_str_normalize (str, TRUE);
|
2010-11-20 13:43:04 +01:00
|
|
|
termgen.index_text_without_positions
|
2011-05-01 14:55:25 +02:00
|
|
|
(norm, 1, prefix(mfid));
|
|
|
|
|
2010-11-11 21:05:55 +01:00
|
|
|
g_free (norm);
|
2009-11-25 21:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct _MsgDoc {
|
2010-09-12 15:28:34 +02:00
|
|
|
Xapian::Document *_doc;
|
|
|
|
MuMsg *_msg;
|
2011-03-01 23:13:24 +01:00
|
|
|
MuStore *_store;
|
2009-11-25 21:55:06 +01:00
|
|
|
};
|
2010-09-12 15:28:34 +02:00
|
|
|
typedef struct _MsgDoc MsgDoc;
|
2009-11-25 21:55:06 +01:00
|
|
|
|
|
|
|
static void
|
2010-11-20 13:43:04 +01:00
|
|
|
add_terms_values (MuMsgFieldId mfid, MsgDoc* msgdoc)
|
2009-11-25 21:55:06 +01:00
|
|
|
{
|
2010-09-12 15:28:34 +02:00
|
|
|
/* note: contact-stuff (To/Cc/From) will handled in
|
|
|
|
* add_contact_info, not here */
|
2010-11-20 13:43:04 +01:00
|
|
|
if (!mu_msg_field_xapian_index(mfid) &&
|
|
|
|
!mu_msg_field_xapian_term(mfid) &&
|
|
|
|
!mu_msg_field_xapian_value(mfid))
|
2009-11-25 21:55:06 +01:00
|
|
|
return;
|
|
|
|
|
2010-11-21 17:12:01 +01:00
|
|
|
switch (mfid) {
|
|
|
|
case MU_MSG_FIELD_ID_DATE:
|
|
|
|
add_terms_values_date (*msgdoc->_doc, msgdoc->_msg, mfid);
|
|
|
|
break;
|
|
|
|
case MU_MSG_FIELD_ID_BODY_TEXT:
|
|
|
|
add_terms_values_body (*msgdoc->_doc, msgdoc->_msg, mfid);
|
|
|
|
break;
|
2011-05-21 15:06:52 +02:00
|
|
|
case MU_MSG_FIELD_ID_ATTACH:
|
|
|
|
add_terms_values_attach (*msgdoc->_doc, msgdoc->_msg, mfid);
|
|
|
|
break;
|
2010-11-21 17:12:01 +01:00
|
|
|
default:
|
|
|
|
if (mu_msg_field_is_numeric (mfid))
|
|
|
|
add_terms_values_number (*msgdoc->_doc, msgdoc->_msg,
|
|
|
|
mfid);
|
2011-06-15 22:52:32 +02:00
|
|
|
else if (mu_msg_field_is_string (mfid))
|
2010-11-21 17:12:01 +01:00
|
|
|
add_terms_values_string (*msgdoc->_doc,
|
|
|
|
msgdoc->_msg,
|
|
|
|
mfid);
|
2011-06-15 22:52:32 +02:00
|
|
|
else if (mu_msg_field_is_string_list(mfid))
|
|
|
|
add_terms_values_string_list (*msgdoc->_doc,
|
|
|
|
msgdoc->_msg,
|
|
|
|
mfid);
|
2009-11-25 21:55:06 +01:00
|
|
|
else
|
2010-11-21 17:12:01 +01:00
|
|
|
g_return_if_reached ();
|
2009-11-25 21:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-12 15:28:34 +02:00
|
|
|
|
2011-05-01 14:55:25 +02:00
|
|
|
static const std::string&
|
2011-03-02 22:03:24 +01:00
|
|
|
xapian_pfx (MuMsgContact *contact)
|
2010-09-12 15:28:34 +02:00
|
|
|
{
|
2011-05-01 14:55:25 +02:00
|
|
|
static const std::string empty;
|
2011-03-02 22:03:24 +01:00
|
|
|
|
2010-11-20 13:43:04 +01:00
|
|
|
/* use ptr to string to prevent copy... */
|
2010-09-12 15:28:34 +02:00
|
|
|
switch (contact->type) {
|
2011-03-02 22:03:24 +01:00
|
|
|
case MU_MSG_CONTACT_TYPE_TO:
|
2011-05-01 14:55:25 +02:00
|
|
|
return prefix(MU_MSG_FIELD_ID_TO);
|
2011-03-02 22:03:24 +01:00
|
|
|
case MU_MSG_CONTACT_TYPE_FROM:
|
2011-05-01 14:55:25 +02:00
|
|
|
return prefix(MU_MSG_FIELD_ID_FROM);
|
2011-03-02 22:03:24 +01:00
|
|
|
case MU_MSG_CONTACT_TYPE_CC:
|
2011-05-01 14:55:25 +02:00
|
|
|
return prefix(MU_MSG_FIELD_ID_CC);
|
2011-05-01 17:31:00 +02:00
|
|
|
case MU_MSG_CONTACT_TYPE_BCC:
|
|
|
|
return prefix(MU_MSG_FIELD_ID_BCC);
|
|
|
|
default:
|
2011-05-01 14:55:25 +02:00
|
|
|
g_warning ("unsupported contact type %u",
|
|
|
|
(unsigned)contact->type);
|
|
|
|
return empty;
|
2010-09-12 15:28:34 +02:00
|
|
|
}
|
2011-03-02 22:03:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
each_contact_info (MuMsgContact *contact, MsgDoc *msgdoc)
|
|
|
|
{
|
2011-05-01 14:55:25 +02:00
|
|
|
const std::string pfx (xapian_pfx(contact));
|
|
|
|
if (pfx.empty())
|
2011-03-02 22:03:24 +01:00
|
|
|
return; /* unsupported contact type */
|
2010-09-12 15:28:34 +02:00
|
|
|
|
2011-03-22 22:37:01 +01:00
|
|
|
if (!mu_str_is_empty(contact->name)) {
|
2010-09-12 15:28:34 +02:00
|
|
|
Xapian::TermGenerator termgen;
|
2011-03-01 23:13:24 +01:00
|
|
|
termgen.set_document (*msgdoc->_doc);
|
2010-11-22 23:44:18 +01:00
|
|
|
char *norm = mu_str_normalize (contact->name, TRUE);
|
2011-05-01 14:55:25 +02:00
|
|
|
termgen.index_text_without_positions (norm, 1, pfx);
|
2010-11-11 21:05:55 +01:00
|
|
|
g_free (norm);
|
2010-09-12 15:28:34 +02:00
|
|
|
}
|
|
|
|
|
2010-11-11 21:05:55 +01:00
|
|
|
/* don't normalize e-mail address, but do lowercase it */
|
2011-05-01 14:55:25 +02:00
|
|
|
if (!mu_str_is_empty(contact->address)) {
|
2011-03-01 23:13:24 +01:00
|
|
|
char *escaped = mu_str_ascii_xapian_escape (contact->address);
|
|
|
|
msgdoc->_doc->add_term
|
2011-05-24 20:41:52 +02:00
|
|
|
(std::string (pfx + escaped, 0,
|
|
|
|
MU_STORE_MAX_TERM_LENGTH));
|
2010-12-07 22:19:13 +01:00
|
|
|
g_free (escaped);
|
2011-03-03 20:22:11 +01:00
|
|
|
|
2011-03-01 23:13:24 +01:00
|
|
|
/* store it also in our contacts cache */
|
|
|
|
if (msgdoc->_store->_contacts)
|
|
|
|
mu_contacts_add (msgdoc->_store->_contacts,
|
2011-05-24 20:41:52 +02:00
|
|
|
contact->address, contact->name,
|
2011-03-01 23:13:24 +01:00
|
|
|
mu_msg_get_date(msgdoc->_msg));
|
2010-11-11 21:05:55 +01:00
|
|
|
}
|
2010-09-12 15:28:34 +02:00
|
|
|
}
|
|
|
|
|
2011-04-30 10:31:34 +02:00
|
|
|
/* get a unique id for this message; note, this function returns a
|
|
|
|
* static buffer -- not reentrant */
|
|
|
|
static const char*
|
2010-01-15 21:15:09 +01:00
|
|
|
get_message_uid (const char* path)
|
2009-11-25 21:55:06 +01:00
|
|
|
{
|
2011-04-30 10:31:34 +02:00
|
|
|
char pfx = 0;
|
|
|
|
static char buf[PATH_MAX + 10];
|
|
|
|
|
|
|
|
if (G_UNLIKELY(!pfx)) {
|
|
|
|
pfx = mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_PATH);
|
|
|
|
buf[0]=pfx;
|
|
|
|
}
|
2010-01-04 21:49:24 +01:00
|
|
|
|
2011-04-30 12:52:17 +02:00
|
|
|
std::strcpy (buf + 1, path);
|
|
|
|
|
2011-04-30 10:31:34 +02:00
|
|
|
return buf;
|
2010-01-04 21:49:24 +01:00
|
|
|
}
|
|
|
|
|
2011-04-30 10:31:34 +02:00
|
|
|
/* get a unique id for this message; note, this function returns a
|
|
|
|
* static buffer -- not reentrant */
|
|
|
|
static const char*
|
2010-08-24 23:57:16 +02:00
|
|
|
get_message_uid (MuMsg *msg)
|
2010-01-05 08:08:39 +01:00
|
|
|
{
|
2011-04-30 10:31:34 +02:00
|
|
|
return get_message_uid (mu_msg_get_path(msg));
|
2010-01-05 08:08:39 +01:00
|
|
|
}
|
2010-01-04 21:49:24 +01:00
|
|
|
|
|
|
|
MuResult
|
2011-04-30 10:31:34 +02:00
|
|
|
mu_store_store (MuStore *store, MuMsg *msg, gboolean replace)
|
2010-01-04 21:49:24 +01:00
|
|
|
{
|
2009-11-25 21:55:06 +01:00
|
|
|
g_return_val_if_fail (store, MU_ERROR);
|
|
|
|
g_return_val_if_fail (msg, MU_ERROR);
|
|
|
|
|
|
|
|
try {
|
|
|
|
Xapian::Document newdoc;
|
|
|
|
Xapian::docid id;
|
2011-03-01 23:13:24 +01:00
|
|
|
MsgDoc msgdoc = { &newdoc, msg, store };
|
2010-01-15 21:15:09 +01:00
|
|
|
const std::string uid(get_message_uid(msg));
|
2011-03-01 23:13:24 +01:00
|
|
|
|
2010-01-23 12:41:42 +01:00
|
|
|
begin_trx_if (store, !store->_in_transaction);
|
2010-02-08 20:23:41 +01:00
|
|
|
/* we must add a unique term, so we can replace
|
2010-09-12 15:28:34 +02:00
|
|
|
* matching documents */
|
2010-01-04 21:49:24 +01:00
|
|
|
newdoc.add_term (uid);
|
2010-11-20 13:43:04 +01:00
|
|
|
mu_msg_field_foreach
|
|
|
|
((MuMsgFieldForEachFunc)add_terms_values, &msgdoc);
|
2010-09-12 15:28:34 +02:00
|
|
|
/* also store the contact-info as separate terms */
|
2010-11-22 23:33:15 +01:00
|
|
|
mu_msg_contact_foreach
|
|
|
|
(msg,
|
|
|
|
(MuMsgContactForeachFunc)each_contact_info,
|
|
|
|
&msgdoc);
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2011-04-30 10:31:34 +02:00
|
|
|
/* add_document is slightly
|
|
|
|
faster, we can use it when
|
|
|
|
* we know the document does not exist yet, eg., in
|
|
|
|
* case of a rebuild */
|
|
|
|
if (replace) /* we replace all existing documents for this file */
|
|
|
|
id = store->_db.replace_document (uid, newdoc);
|
|
|
|
else
|
|
|
|
id = store->_db.add_document (newdoc);
|
|
|
|
|
2011-05-20 20:32:16 +02:00
|
|
|
/* DEBUG */
|
|
|
|
//g_print ("\n[%s]\n", newdoc.serialise().c_str());
|
|
|
|
|
2010-01-05 08:08:39 +01:00
|
|
|
++store->_processed;
|
2010-01-23 12:41:42 +01:00
|
|
|
commit_trx_if (store,
|
2010-01-23 13:12:45 +01:00
|
|
|
store->_processed % store->_trx_size == 0);
|
2009-11-25 21:55:06 +01:00
|
|
|
|
|
|
|
return MU_OK;
|
|
|
|
|
2010-01-06 00:20:30 +01:00
|
|
|
} MU_XAPIAN_CATCH_BLOCK;
|
2010-01-05 08:08:39 +01:00
|
|
|
|
2010-01-23 12:41:42 +01:00
|
|
|
rollback_trx_if (store, store->_in_transaction);
|
2009-11-25 21:55:06 +01:00
|
|
|
|
|
|
|
return MU_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-15 12:27:41 +01:00
|
|
|
gboolean
|
|
|
|
mu_store_remove (MuStore *store, const char *msgpath)
|
2009-11-25 21:55:06 +01:00
|
|
|
{
|
2011-01-15 12:27:41 +01:00
|
|
|
g_return_val_if_fail (store, FALSE);
|
|
|
|
g_return_val_if_fail (msgpath, FALSE);
|
2009-11-25 21:55:06 +01:00
|
|
|
|
|
|
|
try {
|
2010-01-15 21:15:09 +01:00
|
|
|
const std::string uid (get_message_uid (msgpath));
|
2010-01-05 08:08:39 +01:00
|
|
|
|
2010-01-23 12:41:42 +01:00
|
|
|
begin_trx_if (store, !store->_in_transaction);
|
2010-01-05 08:08:39 +01:00
|
|
|
|
2011-03-22 22:37:01 +01:00
|
|
|
store->_db.delete_document (uid);
|
2010-01-05 08:08:39 +01:00
|
|
|
++store->_processed;
|
2010-01-11 19:46:14 +01:00
|
|
|
|
|
|
|
/* do we need to commit now? */
|
|
|
|
bool commit_now = store->_processed % store->_trx_size == 0;
|
2010-01-23 12:41:42 +01:00
|
|
|
commit_trx_if (store, commit_now);
|
2010-01-05 08:08:39 +01:00
|
|
|
|
2011-01-15 12:27:41 +01:00
|
|
|
return TRUE;
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2011-01-15 12:27:41 +01:00
|
|
|
} MU_XAPIAN_CATCH_BLOCK_RETURN (FALSE);
|
2009-11-25 21:55:06 +01:00
|
|
|
}
|
|
|
|
|
2010-01-11 19:46:14 +01:00
|
|
|
gboolean
|
2010-08-25 20:55:08 +02:00
|
|
|
mu_store_contains_message (MuStore *store, const char* path)
|
2010-01-11 19:46:14 +01:00
|
|
|
{
|
2010-09-26 16:29:54 +02:00
|
|
|
g_return_val_if_fail (store, FALSE);
|
|
|
|
g_return_val_if_fail (path, FALSE);
|
2010-01-11 19:46:14 +01:00
|
|
|
|
|
|
|
try {
|
2010-01-15 21:15:09 +01:00
|
|
|
const std::string uid (get_message_uid(path));
|
2011-03-22 22:37:01 +01:00
|
|
|
return store->_db.term_exists (uid) ? TRUE: FALSE;
|
2010-01-11 19:46:14 +01:00
|
|
|
|
|
|
|
} MU_XAPIAN_CATCH_BLOCK_RETURN (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
time_t
|
2010-08-25 20:55:08 +02:00
|
|
|
mu_store_get_timestamp (MuStore *store, const char* msgpath)
|
2009-11-25 21:55:06 +01:00
|
|
|
{
|
2011-01-12 22:13:03 +01:00
|
|
|
char *stampstr;
|
2011-02-04 19:47:56 +01:00
|
|
|
time_t rv;
|
2011-01-12 22:13:03 +01:00
|
|
|
|
2009-11-25 21:55:06 +01:00
|
|
|
g_return_val_if_fail (store, 0);
|
|
|
|
g_return_val_if_fail (msgpath, 0);
|
|
|
|
|
2011-01-12 22:13:03 +01:00
|
|
|
stampstr = mu_store_get_metadata (store, msgpath);
|
|
|
|
if (!stampstr)
|
|
|
|
return (time_t)0;
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2011-02-04 19:47:56 +01:00
|
|
|
rv = (time_t) g_ascii_strtoull (stampstr, NULL, 10);
|
|
|
|
g_free (stampstr);
|
2011-04-30 12:52:17 +02:00
|
|
|
|
2011-02-04 19:47:56 +01:00
|
|
|
return rv;
|
|
|
|
}
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2011-01-12 22:13:03 +01:00
|
|
|
gboolean
|
2010-08-25 20:55:08 +02:00
|
|
|
mu_store_set_timestamp (MuStore *store, const char* msgpath,
|
|
|
|
time_t stamp)
|
2009-11-25 21:55:06 +01:00
|
|
|
{
|
2011-01-12 22:13:03 +01:00
|
|
|
char buf[21];
|
|
|
|
|
|
|
|
g_return_val_if_fail (store, FALSE);
|
|
|
|
g_return_val_if_fail (msgpath, FALSE);
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2011-01-12 22:13:03 +01:00
|
|
|
sprintf (buf, "%" G_GUINT64_FORMAT, (guint64)stamp);
|
|
|
|
return mu_store_set_metadata (store, msgpath, buf);
|
2009-11-25 21:55:06 +01:00
|
|
|
}
|
2010-01-03 22:53:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
MuResult
|
2010-08-25 20:55:08 +02:00
|
|
|
mu_store_foreach (MuStore *self,
|
|
|
|
MuStoreForeachFunc func, void *user_data)
|
2010-01-03 22:53:04 +01:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (self, MU_ERROR);
|
|
|
|
g_return_val_if_fail (func, MU_ERROR);
|
|
|
|
|
|
|
|
try {
|
2011-03-22 22:37:01 +01:00
|
|
|
Xapian::Enquire enq (self->_db);
|
|
|
|
|
2010-01-03 22:53:04 +01:00
|
|
|
enq.set_query (Xapian::Query::MatchAll);
|
|
|
|
enq.set_cutoff (0,0);
|
|
|
|
|
2011-03-22 22:37:01 +01:00
|
|
|
Xapian::MSet matches (enq.get_mset (0, self->_db.get_doccount()));
|
2010-01-03 22:53:04 +01:00
|
|
|
if (matches.empty())
|
|
|
|
return MU_OK; /* database is empty */
|
|
|
|
|
|
|
|
for (Xapian::MSet::iterator iter = matches.begin();
|
|
|
|
iter != matches.end(); ++iter) {
|
|
|
|
Xapian::Document doc (iter.get_document());
|
2011-03-22 22:37:01 +01:00
|
|
|
const std::string path(doc.get_value(MU_MSG_FIELD_ID_PATH));
|
2010-01-03 22:53:04 +01:00
|
|
|
MuResult res = func (path.c_str(), user_data);
|
|
|
|
if (res != MU_OK)
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-01-06 00:20:30 +01:00
|
|
|
} MU_XAPIAN_CATCH_BLOCK_RETURN (MU_ERROR);
|
2010-01-03 22:53:04 +01:00
|
|
|
|
|
|
|
return MU_OK;
|
|
|
|
}
|