* rename MuMsgIterXapian => MuMsgIter
This commit is contained in:
@ -72,9 +72,9 @@ libmu_la_SOURCES= \
|
|||||||
mu-msg.c \
|
mu-msg.c \
|
||||||
mu-msg.h \
|
mu-msg.h \
|
||||||
mu-msg-priv.h \
|
mu-msg-priv.h \
|
||||||
mu-msg-iter-xapian-priv.hh \
|
mu-msg-iter-priv.hh \
|
||||||
mu-msg-iter-xapian.cc \
|
mu-msg-iter.cc \
|
||||||
mu-msg-iter-xapian.h \
|
mu-msg-iter.h \
|
||||||
mu-msg-part.c \
|
mu-msg-part.c \
|
||||||
mu-msg-part.h \
|
mu-msg-part.h \
|
||||||
mu-msg-str.c \
|
mu-msg-str.c \
|
||||||
|
|||||||
@ -32,7 +32,7 @@
|
|||||||
#include "mu-maildir.h"
|
#include "mu-maildir.h"
|
||||||
#include "mu-index.h"
|
#include "mu-index.h"
|
||||||
#include "mu-query-xapian.h"
|
#include "mu-query-xapian.h"
|
||||||
#include "mu-msg-iter-xapian.h"
|
#include "mu-msg-iter.h"
|
||||||
#include "mu-msg-str.h"
|
#include "mu-msg-str.h"
|
||||||
|
|
||||||
#include "mu-util.h"
|
#include "mu-util.h"
|
||||||
@ -66,34 +66,34 @@ print_xapian_query (MuQueryXapian *xapian, const gchar *query)
|
|||||||
|
|
||||||
|
|
||||||
static const gchar*
|
static const gchar*
|
||||||
display_field (MuMsgIterXapian *iter, const MuMsgField* field)
|
display_field (MuMsgIter *iter, const MuMsgField* field)
|
||||||
{
|
{
|
||||||
gint64 val;
|
gint64 val;
|
||||||
|
|
||||||
switch (mu_msg_field_type(field)) {
|
switch (mu_msg_field_type(field)) {
|
||||||
case MU_MSG_FIELD_TYPE_STRING:
|
case MU_MSG_FIELD_TYPE_STRING:
|
||||||
return mu_msg_iter_xapian_get_field (iter, field);
|
return mu_msg_iter_get_field (iter, field);
|
||||||
|
|
||||||
case MU_MSG_FIELD_TYPE_INT:
|
case MU_MSG_FIELD_TYPE_INT:
|
||||||
|
|
||||||
if (mu_msg_field_id(field) == MU_MSG_FIELD_ID_PRIO) {
|
if (mu_msg_field_id(field) == MU_MSG_FIELD_ID_PRIO) {
|
||||||
val = mu_msg_iter_xapian_get_field_numeric (iter, field);
|
val = mu_msg_iter_get_field_numeric (iter, field);
|
||||||
return mu_msg_str_prio ((MuMsgPrio)val);
|
return mu_msg_str_prio ((MuMsgPrio)val);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mu_msg_field_id(field) == MU_MSG_FIELD_ID_FLAGS) {
|
if (mu_msg_field_id(field) == MU_MSG_FIELD_ID_FLAGS) {
|
||||||
val = mu_msg_iter_xapian_get_field_numeric (iter, field);
|
val = mu_msg_iter_get_field_numeric (iter, field);
|
||||||
return mu_msg_str_flags_s ((MuMsgPrio)val);
|
return mu_msg_str_flags_s ((MuMsgPrio)val);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mu_msg_iter_xapian_get_field (iter, field); /* as string */
|
return mu_msg_iter_get_field (iter, field); /* as string */
|
||||||
|
|
||||||
case MU_MSG_FIELD_TYPE_TIME_T:
|
case MU_MSG_FIELD_TYPE_TIME_T:
|
||||||
val = mu_msg_iter_xapian_get_field_numeric (iter, field);
|
val = mu_msg_iter_get_field_numeric (iter, field);
|
||||||
return mu_msg_str_date_s ((time_t)val);
|
return mu_msg_str_date_s ((time_t)val);
|
||||||
|
|
||||||
case MU_MSG_FIELD_TYPE_BYTESIZE:
|
case MU_MSG_FIELD_TYPE_BYTESIZE:
|
||||||
val = mu_msg_iter_xapian_get_field_numeric (iter, field);
|
val = mu_msg_iter_get_field_numeric (iter, field);
|
||||||
return mu_msg_str_size_s ((time_t)val);
|
return mu_msg_str_size_s ((time_t)val);
|
||||||
default:
|
default:
|
||||||
g_return_val_if_reached (NULL);
|
g_return_val_if_reached (NULL);
|
||||||
@ -119,12 +119,12 @@ sort_field_from_string (const char* fieldstr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_summary (MuMsgIterXapian *iter, size_t summary_len)
|
print_summary (MuMsgIter *iter, size_t summary_len)
|
||||||
{
|
{
|
||||||
const char *summ;
|
const char *summ;
|
||||||
MuMsg *msg;
|
MuMsg *msg;
|
||||||
|
|
||||||
msg = mu_msg_iter_xapian_get_msg (iter);
|
msg = mu_msg_iter_get_msg (iter);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
g_warning ("%s: failed to create msg object", __FUNCTION__);
|
g_warning ("%s: failed to create msg object", __FUNCTION__);
|
||||||
return;
|
return;
|
||||||
@ -139,12 +139,12 @@ print_summary (MuMsgIterXapian *iter, size_t summary_len)
|
|||||||
|
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
print_rows (MuMsgIterXapian *iter, const char *fields, size_t summary_len)
|
print_rows (MuMsgIter *iter, const char *fields, size_t summary_len)
|
||||||
{
|
{
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
const char* myfields;
|
const char* myfields;
|
||||||
|
|
||||||
if (mu_msg_iter_xapian_is_null (iter))
|
if (mu_msg_iter_is_null (iter))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -170,7 +170,7 @@ print_rows (MuMsgIterXapian *iter, const char *fields, size_t summary_len)
|
|||||||
|
|
||||||
++count;
|
++count;
|
||||||
|
|
||||||
} while (mu_msg_iter_xapian_next (iter));
|
} while (mu_msg_iter_next (iter));
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
@ -192,7 +192,7 @@ create_or_clear_linksdir_maybe (const char *linksdir, gboolean clearlinks)
|
|||||||
|
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
make_links (MuMsgIterXapian *iter, const char* linksdir, gboolean clearlinks)
|
make_links (MuMsgIter *iter, const char* linksdir, gboolean clearlinks)
|
||||||
{
|
{
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
const MuMsgField *pathfield;
|
const MuMsgField *pathfield;
|
||||||
@ -200,7 +200,7 @@ make_links (MuMsgIterXapian *iter, const char* linksdir, gboolean clearlinks)
|
|||||||
if (!create_or_clear_linksdir_maybe (linksdir, clearlinks))
|
if (!create_or_clear_linksdir_maybe (linksdir, clearlinks))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (mu_msg_iter_xapian_is_null (iter))
|
if (mu_msg_iter_is_null (iter))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
pathfield = mu_msg_field_from_id (MU_MSG_FIELD_ID_PATH);
|
pathfield = mu_msg_field_from_id (MU_MSG_FIELD_ID_PATH);
|
||||||
@ -210,10 +210,10 @@ make_links (MuMsgIterXapian *iter, const char* linksdir, gboolean clearlinks)
|
|||||||
const char *path;
|
const char *path;
|
||||||
|
|
||||||
/* there's no data in the iter */
|
/* there's no data in the iter */
|
||||||
if (mu_msg_iter_xapian_is_null (iter))
|
if (mu_msg_iter_is_null (iter))
|
||||||
return count;
|
return count;
|
||||||
|
|
||||||
path = mu_msg_iter_xapian_get_field (iter, pathfield);
|
path = mu_msg_iter_get_field (iter, pathfield);
|
||||||
if (!path)
|
if (!path)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ make_links (MuMsgIterXapian *iter, const char* linksdir, gboolean clearlinks)
|
|||||||
break;
|
break;
|
||||||
++count;
|
++count;
|
||||||
|
|
||||||
} while (mu_msg_iter_xapian_next (iter));
|
} while (mu_msg_iter_next (iter));
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
@ -238,7 +238,7 @@ make_links (MuMsgIterXapian *iter, const char* linksdir, gboolean clearlinks)
|
|||||||
static gboolean
|
static gboolean
|
||||||
run_query (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
run_query (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
||||||
{
|
{
|
||||||
MuMsgIterXapian *iter;
|
MuMsgIter *iter;
|
||||||
const MuMsgField *sortfield;
|
const MuMsgField *sortfield;
|
||||||
size_t matches;
|
size_t matches;
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ run_query (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
|||||||
if (matches == 0)
|
if (matches == 0)
|
||||||
g_printerr ("No matches found\n");
|
g_printerr ("No matches found\n");
|
||||||
|
|
||||||
mu_msg_iter_xapian_destroy (iter);
|
mu_msg_iter_destroy (iter);
|
||||||
|
|
||||||
return matches > 0;
|
return matches > 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
** Copyright (C) 22010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
||||||
**
|
|
||||||
** 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 of the License, 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.
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __MU_MSG_XAPIAN_PRIV_HH__
|
|
||||||
#define __MU_MSG_XAPIAN_PRIV_HH__
|
|
||||||
|
|
||||||
#include <xapian.h>
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* create a new MuMsgIterXapian -- basically, an iterator over the search
|
|
||||||
* results
|
|
||||||
*
|
|
||||||
* @param enq a Xapian::Enquiry providing access to search results
|
|
||||||
* @param batchsize how many results to retrieve at once
|
|
||||||
*
|
|
||||||
* @return a new MuMsgIterXapian, or NULL in case of error
|
|
||||||
*/
|
|
||||||
MuMsgIterXapian *mu_msg_iter_xapian_new
|
|
||||||
(const Xapian::Enquire& enq, size_t batchsize)G_GNUC_WARN_UNUSED_RESULT;
|
|
||||||
|
|
||||||
#endif /*__MU_MSG_XAPIAN_PRIV_HH__*/
|
|
||||||
@ -1,304 +0,0 @@
|
|||||||
/*
|
|
||||||
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
||||||
**
|
|
||||||
** 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 of the License, 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.
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include "xapian.h"
|
|
||||||
|
|
||||||
#include "mu-util.h"
|
|
||||||
#include "mu-msg-iter-xapian.h"
|
|
||||||
|
|
||||||
struct _MuMsgIterXapian {
|
|
||||||
Xapian::Enquire *_enq;
|
|
||||||
Xapian::MSet _matches;
|
|
||||||
Xapian::MSet::const_iterator _cursor;
|
|
||||||
size_t _batchsize;
|
|
||||||
size_t _offset;
|
|
||||||
char* _str[MU_MSG_FIELD_ID_NUM];
|
|
||||||
bool _is_null;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MuMsgIterXapian*
|
|
||||||
mu_msg_iter_xapian_new (const Xapian::Enquire& enq, size_t batchsize)
|
|
||||||
{
|
|
||||||
MuMsgIterXapian *iter;
|
|
||||||
|
|
||||||
try {
|
|
||||||
iter = new MuMsgIterXapian;
|
|
||||||
memset (iter->_str, 0, sizeof(iter->_str));
|
|
||||||
|
|
||||||
iter->_enq = new Xapian::Enquire(enq);
|
|
||||||
iter->_matches = iter->_enq->get_mset (0, batchsize);
|
|
||||||
if (!iter->_matches.empty()) {
|
|
||||||
iter->_cursor = iter->_matches.begin();
|
|
||||||
iter->_is_null = false;
|
|
||||||
} else
|
|
||||||
iter->_is_null = true;
|
|
||||||
|
|
||||||
iter->_batchsize = batchsize;
|
|
||||||
iter->_offset = 0;
|
|
||||||
|
|
||||||
return iter;
|
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK_RETURN(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
mu_msg_iter_xapian_destroy (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
if (iter) {
|
|
||||||
for (int i = 0; i != MU_MSG_FIELD_ID_NUM; ++i)
|
|
||||||
g_free (iter->_str[i]);
|
|
||||||
|
|
||||||
try {
|
|
||||||
delete iter->_enq;
|
|
||||||
delete iter;
|
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MuMsg*
|
|
||||||
mu_msg_iter_xapian_get_msg (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
const char *path;
|
|
||||||
MuMsg *msg;
|
|
||||||
|
|
||||||
g_return_val_if_fail (iter, NULL);
|
|
||||||
|
|
||||||
path = mu_msg_iter_xapian_get_path (iter);
|
|
||||||
if (!path) {
|
|
||||||
g_warning ("%s: no path for message", __FUNCTION__);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg = mu_msg_new (path, NULL);
|
|
||||||
if (!msg) {
|
|
||||||
g_warning ("%s: failed to create msg object", __FUNCTION__);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
message_is_readable (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
Xapian::Document doc (iter->_cursor.get_document());
|
|
||||||
const std::string path(doc.get_value(MU_MSG_FIELD_ID_PATH));
|
|
||||||
|
|
||||||
if (access (path.c_str(), R_OK) != 0) {
|
|
||||||
g_debug ("cannot read %s: %s", path.c_str(),
|
|
||||||
strerror(errno));
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static MuMsgIterXapian*
|
|
||||||
get_next_batch (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
iter->_matches = iter->_enq->get_mset (iter->_offset,
|
|
||||||
iter->_batchsize);
|
|
||||||
if (iter->_matches.empty()) {
|
|
||||||
iter->_cursor = iter->_matches.end();
|
|
||||||
iter->_is_null = true;
|
|
||||||
} else {
|
|
||||||
iter->_cursor = iter->_matches.begin();
|
|
||||||
iter->_is_null = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return iter;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
mu_msg_iter_xapian_next (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (iter, FALSE);
|
|
||||||
|
|
||||||
try {
|
|
||||||
++iter->_offset;
|
|
||||||
if (++iter->_cursor == iter->_matches.end())
|
|
||||||
iter = get_next_batch (iter);
|
|
||||||
if (iter->_cursor == iter->_matches.end())
|
|
||||||
return FALSE; /* no more matches */
|
|
||||||
|
|
||||||
/* the message may not be readable / existing, e.g.,
|
|
||||||
* because of the database not being fully up to
|
|
||||||
* date. in that case, we ignore the message. it
|
|
||||||
* might be nice to auto-delete these messages from
|
|
||||||
* the db, but that would might screw up the
|
|
||||||
* search; also, we only have read-only access to
|
|
||||||
* the db here */
|
|
||||||
if (!message_is_readable (iter))
|
|
||||||
return mu_msg_iter_xapian_next (iter);
|
|
||||||
|
|
||||||
for (int i = 0; i != MU_MSG_FIELD_ID_NUM; ++i) {
|
|
||||||
g_free (iter->_str[i]);
|
|
||||||
iter->_str[i] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK_RETURN(FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
mu_msg_iter_xapian_is_null (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (iter, TRUE);
|
|
||||||
|
|
||||||
return iter->_is_null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const gchar*
|
|
||||||
mu_msg_iter_xapian_get_field (MuMsgIterXapian *iter, const MuMsgField *field)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (iter, NULL);
|
|
||||||
g_return_val_if_fail (!mu_msg_iter_xapian_is_null(iter), NULL);
|
|
||||||
g_return_val_if_fail (field, NULL);
|
|
||||||
|
|
||||||
try {
|
|
||||||
MuMsgFieldId id;
|
|
||||||
|
|
||||||
id = mu_msg_field_id (field);
|
|
||||||
if (!iter->_str[id]) { /* cache the value */
|
|
||||||
Xapian::Document doc (iter->_cursor.get_document());
|
|
||||||
iter->_str[id] = g_strdup (doc.get_value(id).c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
return iter->_str[id];
|
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK_RETURN(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
gint64
|
|
||||||
mu_msg_iter_xapian_get_field_numeric (MuMsgIterXapian *iter,
|
|
||||||
const MuMsgField *field)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (mu_msg_field_is_numeric(field), -1);
|
|
||||||
|
|
||||||
try {
|
|
||||||
return static_cast<gint64>(
|
|
||||||
Xapian::sortable_unserialise(
|
|
||||||
mu_msg_iter_xapian_get_field(iter, field)));
|
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK_RETURN(static_cast<gint64>(-1));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const gchar*
|
|
||||||
get_field (MuMsgIterXapian *iter, MuMsgFieldId id)
|
|
||||||
{
|
|
||||||
return mu_msg_iter_xapian_get_field(iter, mu_msg_field_from_id (id));
|
|
||||||
}
|
|
||||||
|
|
||||||
static long
|
|
||||||
get_field_number (MuMsgIterXapian *iter, MuMsgFieldId id)
|
|
||||||
{
|
|
||||||
const char* str = get_field (iter, id);
|
|
||||||
return str ? atol (str) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* hmmm.... is it impossible to get a 0 docid, or just very improbable? */
|
|
||||||
unsigned int
|
|
||||||
mu_msg_iter_xapian_get_docid (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (iter, 0);
|
|
||||||
|
|
||||||
try {
|
|
||||||
return iter->_cursor.get_document().get_docid();
|
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK_RETURN (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char*
|
|
||||||
mu_msg_iter_xapian_get_path (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
return get_field (iter, MU_MSG_FIELD_ID_PATH);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char*
|
|
||||||
mu_msg_iter_xapian_get_from (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
return get_field (iter, MU_MSG_FIELD_ID_FROM);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char*
|
|
||||||
mu_msg_iter_xapian_get_to (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
return get_field (iter, MU_MSG_FIELD_ID_TO);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char*
|
|
||||||
mu_msg_iter_xapian_get_cc (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
return get_field (iter, MU_MSG_FIELD_ID_CC);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char*
|
|
||||||
mu_msg_iter_xapian_get_subject (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
return get_field (iter, MU_MSG_FIELD_ID_SUBJECT);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t
|
|
||||||
mu_msg_iter_xapian_get_size (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
return (size_t) get_field_number (iter, MU_MSG_FIELD_ID_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
time_t
|
|
||||||
mu_msg_iter_xapian_get_date (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
return (size_t) get_field_number (iter, MU_MSG_FIELD_ID_DATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MuMsgFlags
|
|
||||||
mu_msg_iter_xapian_get_flags (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
return (MuMsgFlags) get_field_number (iter, MU_MSG_FIELD_ID_FLAGS);
|
|
||||||
}
|
|
||||||
|
|
||||||
MuMsgPrio
|
|
||||||
mu_msg_iter_xapian_get_prio (MuMsgIterXapian *iter)
|
|
||||||
{
|
|
||||||
return (MuMsgPrio) get_field_number (iter, MU_MSG_FIELD_ID_PRIO);
|
|
||||||
}
|
|
||||||
@ -1,199 +0,0 @@
|
|||||||
/*
|
|
||||||
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
||||||
**
|
|
||||||
** 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 of the License, 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.
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __MU_MSG_ITER_XAPIAN_H__
|
|
||||||
#define __MU_MSG_ITER_XAPIAN_H__
|
|
||||||
|
|
||||||
#include "mu-msg.h"
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
struct _MuMsgIterXapian;
|
|
||||||
typedef struct _MuMsgIterXapian MuMsgIterXapian;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the next next message (which you got from
|
|
||||||
* e.g. mu_query_xapian_run)
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
*
|
|
||||||
* @return TRUE if it succeeded, FALSE otherwise (e.g., because there
|
|
||||||
* are no more messages in the query result)
|
|
||||||
*/
|
|
||||||
gboolean mu_msg_iter_xapian_next (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* does the iter point to a real message?
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
*
|
|
||||||
* @return TRUE if the iterator points to a message, FALSE other
|
|
||||||
*/
|
|
||||||
gboolean mu_msg_iter_xapian_is_null (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* destroy the sequence of messages; ie. /all/ of them
|
|
||||||
*
|
|
||||||
* @param msg a valid MuMsgIterXapian message or NULL
|
|
||||||
*/
|
|
||||||
void mu_msg_iter_xapian_destroy (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the corresponding MuMsg for this iter; this requires
|
|
||||||
* the corresponding message file to be present at the expected place
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian instance
|
|
||||||
*
|
|
||||||
* @return a MuMsgGMime instance, or NULL in case of error. Use
|
|
||||||
* mu_msg_gmime_destroy when the instance is no longer needed
|
|
||||||
*/
|
|
||||||
MuMsg* mu_msg_iter_xapian_get_msg (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the document id for the current message
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
*
|
|
||||||
* @return the docid or 0 in case of error
|
|
||||||
*/
|
|
||||||
unsigned int mu_msg_iter_xapian_get_docid (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the directory path of the message
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
*
|
|
||||||
* @return the path, or NULL in case of error
|
|
||||||
*/
|
|
||||||
const char* mu_msg_iter_xapian_get_path (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the size of the message
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
*
|
|
||||||
* @return the size, or 0 in case of error
|
|
||||||
*/
|
|
||||||
size_t mu_msg_iter_xapian_get_size (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the timestamp (ctime) of the message file
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
*
|
|
||||||
* @return the size, or 0 in case of error
|
|
||||||
*/
|
|
||||||
time_t mu_msg_iter_xapian_get_timestamp (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the sent time of the message
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
*
|
|
||||||
* @return the time, or 0 in case of error
|
|
||||||
*/
|
|
||||||
time_t mu_msg_iter_xapian_get_date (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the message sender(s) of the message
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
*
|
|
||||||
* @return the time, or 0 in case of error
|
|
||||||
*/
|
|
||||||
const char* mu_msg_iter_xapian_get_from (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the message recipient (To:) of the message
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
*
|
|
||||||
* @return the To-recipient(s), or NULL in case of error
|
|
||||||
*/
|
|
||||||
const char* mu_msg_iter_xapian_get_to (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the message recipient (Cc:) of the message
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
*
|
|
||||||
* @return the Cc-recipient(s), or NULL in case of error
|
|
||||||
*/
|
|
||||||
const char* mu_msg_iter_xapian_get_cc (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the subject of the message
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
*
|
|
||||||
* @return the subject, or NULL in case of error
|
|
||||||
*/
|
|
||||||
const char* mu_msg_iter_xapian_get_subject (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the message flags
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
*
|
|
||||||
* @return the message flags, or MU_MSG_FLAG_UNKNOWN
|
|
||||||
*/
|
|
||||||
MuMsgFlags mu_msg_iter_xapian_get_flags (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the message priority
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
*
|
|
||||||
* @return the message priority, or MU_MSG_PRIO_NONE
|
|
||||||
*/
|
|
||||||
MuMsgPrio mu_msg_iter_xapian_get_prio (MuMsgIterXapian *iter);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get some message field
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
* @param field the string field to retrieve
|
|
||||||
*
|
|
||||||
* @return the field value, or NULL
|
|
||||||
*/
|
|
||||||
const gchar* mu_msg_iter_xapian_get_field (MuMsgIterXapian *iter,
|
|
||||||
const MuMsgField *field);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get some numeric message field
|
|
||||||
*
|
|
||||||
* @param iter a valid MuMsgIterXapian iterator
|
|
||||||
* @param field the numeric field to retrieve
|
|
||||||
*
|
|
||||||
* @return the field value, or -1 in case of error
|
|
||||||
*/
|
|
||||||
gint64 mu_msg_iter_xapian_get_field_numeric (MuMsgIterXapian *iter,
|
|
||||||
const MuMsgField *field);
|
|
||||||
G_END_DECLS
|
|
||||||
|
|
||||||
#endif /*__MU_MSG_ITER_XAPIAN_H__*/
|
|
||||||
@ -25,8 +25,8 @@
|
|||||||
|
|
||||||
#include "mu-query-xapian.h"
|
#include "mu-query-xapian.h"
|
||||||
|
|
||||||
#include "mu-msg-iter-xapian.h"
|
#include "mu-msg-iter.h"
|
||||||
#include "mu-msg-iter-xapian-priv.hh"
|
#include "mu-msg-iter-priv.hh"
|
||||||
|
|
||||||
#include "mu-util.h"
|
#include "mu-util.h"
|
||||||
#include "mu-util-xapian.h"
|
#include "mu-util-xapian.h"
|
||||||
@ -172,7 +172,7 @@ mu_query_xapian_destroy (MuQueryXapian *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MuMsgIterXapian*
|
MuMsgIter*
|
||||||
mu_query_xapian_run (MuQueryXapian *self, const char* searchexpr,
|
mu_query_xapian_run (MuQueryXapian *self, const char* searchexpr,
|
||||||
const MuMsgField* sortfield, gboolean ascending,
|
const MuMsgField* sortfield, gboolean ascending,
|
||||||
size_t batchsize)
|
size_t batchsize)
|
||||||
@ -202,7 +202,7 @@ mu_query_xapian_run (MuQueryXapian *self, const char* searchexpr,
|
|||||||
enq.set_query(q);
|
enq.set_query(q);
|
||||||
enq.set_cutoff(0,0);
|
enq.set_cutoff(0,0);
|
||||||
|
|
||||||
return mu_msg_iter_xapian_new (enq, batchsize);
|
return mu_msg_iter_new (enq, batchsize);
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK_RETURN(NULL);
|
} MU_XAPIAN_CATCH_BLOCK_RETURN(NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
#define __MU_QUERY_XAPIAN_H__
|
#define __MU_QUERY_XAPIAN_H__
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include "mu-msg-iter-xapian.h"
|
#include "mu-msg-iter.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
/*
|
/*
|
||||||
@ -74,15 +74,14 @@ char* mu_query_xapian_version (MuQueryXapian *store) G_GNUC_WARN_UNUSED_RESULT;
|
|||||||
* If you pass '0' as the batchsize, mu will use the maximum size (the count
|
* If you pass '0' as the batchsize, mu will use the maximum size (the count
|
||||||
* of documents in the database)
|
* of documents in the database)
|
||||||
*
|
*
|
||||||
* @return a MuMsgIterXapian instance you can iterate over, or NULL in
|
* @return a MuMsgIter instance you can iterate over, or NULL in
|
||||||
* case of error
|
* case of error
|
||||||
*/
|
*/
|
||||||
MuMsgIterXapian* mu_query_xapian_run (MuQueryXapian *self,
|
MuMsgIter* mu_query_xapian_run (MuQueryXapian *self,
|
||||||
const char* expr,
|
const char* expr,
|
||||||
const MuMsgField* sortfield,
|
const MuMsgField* sortfield,
|
||||||
gboolean ascending,
|
gboolean ascending,
|
||||||
size_t batchsize)
|
size_t batchsize) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
G_GNUC_WARN_UNUSED_RESULT;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,8 +94,7 @@ G_GNUC_WARN_UNUSED_RESULT;
|
|||||||
* error; free the returned value with g_free
|
* error; free the returned value with g_free
|
||||||
*/
|
*/
|
||||||
char* mu_query_xapian_as_string (MuQueryXapian *self,
|
char* mu_query_xapian_as_string (MuQueryXapian *self,
|
||||||
const char* searchexpr)
|
const char* searchexpr) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
G_GNUC_WARN_UNUSED_RESULT;
|
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify
|
** 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
|
** it under the terms of the GNU General Public License as published by
|
||||||
@ -101,6 +101,7 @@ gchar* mu_util_str_from_strv (const gchar **params) G_GNUC_WARN_UNUSED_RESULT;
|
|||||||
* don't repeat these catch blocks everywhere...
|
* don't repeat these catch blocks everywhere...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MU_XAPIAN_CATCH_BLOCK \
|
#define MU_XAPIAN_CATCH_BLOCK \
|
||||||
catch (const Xapian::Error &err) { \
|
catch (const Xapian::Error &err) { \
|
||||||
g_critical ("%s: caught xapian exception '%s'", \
|
g_critical ("%s: caught xapian exception '%s'", \
|
||||||
|
|||||||
@ -55,15 +55,15 @@ fill_database (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static guint
|
static guint
|
||||||
count_matches ( MuMsgIterXapian *iter)
|
count_matches ( MuMsgIter *iter)
|
||||||
{
|
{
|
||||||
guint count;
|
guint count;
|
||||||
|
|
||||||
if (mu_msg_iter_xapian_is_null(iter))
|
if (mu_msg_iter_is_null(iter))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
count = 1;
|
count = 1;
|
||||||
while (mu_msg_iter_xapian_next (iter))
|
while (mu_msg_iter_next (iter))
|
||||||
++count;
|
++count;
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
@ -98,12 +98,12 @@ test_mu_query_01 (void)
|
|||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
MuMsgIterXapian *iter =
|
MuMsgIter *iter =
|
||||||
mu_query_xapian_run (query, queries[i].query, NULL,
|
mu_query_xapian_run (query, queries[i].query, NULL,
|
||||||
FALSE, 1);
|
FALSE, 1);
|
||||||
|
|
||||||
g_assert_cmpuint (queries[i].count, ==, count_matches(iter));
|
g_assert_cmpuint (queries[i].count, ==, count_matches(iter));
|
||||||
mu_msg_iter_xapian_destroy (iter);
|
mu_msg_iter_destroy (iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
mu_query_xapian_destroy (query);
|
mu_query_xapian_destroy (query);
|
||||||
@ -114,7 +114,7 @@ test_mu_query_01 (void)
|
|||||||
static void
|
static void
|
||||||
test_mu_query_02 (void)
|
test_mu_query_02 (void)
|
||||||
{
|
{
|
||||||
MuMsgIterXapian *iter;
|
MuMsgIter *iter;
|
||||||
MuQueryXapian *query;
|
MuQueryXapian *query;
|
||||||
const char* q;
|
const char* q;
|
||||||
gchar *xpath;
|
gchar *xpath;
|
||||||
@ -154,12 +154,12 @@ test_mu_query_03 (void)
|
|||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
MuMsgIterXapian *iter =
|
MuMsgIter *iter =
|
||||||
mu_query_xapian_run (query, queries[i].query, NULL,
|
mu_query_xapian_run (query, queries[i].query, NULL,
|
||||||
FALSE, 1);
|
FALSE, 1);
|
||||||
|
|
||||||
g_assert_cmpuint (queries[i].count, ==, count_matches(iter));
|
g_assert_cmpuint (queries[i].count, ==, count_matches(iter));
|
||||||
mu_msg_iter_xapian_destroy (iter);
|
mu_msg_iter_destroy (iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
mu_query_xapian_destroy (query);
|
mu_query_xapian_destroy (query);
|
||||||
|
|||||||
Reference in New Issue
Block a user