2009-11-25 21:55:06 +01:00
|
|
|
/*
|
2010-08-25 20:46:16 +02:00
|
|
|
** Copyright (C) 2008-2010 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 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.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2010-08-25 20:46:16 +02:00
|
|
|
#ifndef __MU_QUERY_H__
|
|
|
|
#define __MU_QUERY_H__
|
2009-11-25 21:55:06 +01:00
|
|
|
|
|
|
|
#include <glib.h>
|
2010-11-24 19:04:20 +01:00
|
|
|
#include <mu-msg-iter.h>
|
2011-01-04 22:19:03 +01:00
|
|
|
#include <mu-util.h> /* for MuResult, MuError */
|
2009-11-25 21:55:06 +01:00
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
2009-12-08 23:01:49 +01:00
|
|
|
|
2010-08-25 20:46:16 +02:00
|
|
|
struct _MuQuery;
|
|
|
|
typedef struct _MuQuery MuQuery;
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2010-08-25 20:46:16 +02:00
|
|
|
/**
|
|
|
|
* create a new MuQuery instance.
|
2009-11-25 21:55:06 +01:00
|
|
|
*
|
2010-11-23 23:47:36 +01:00
|
|
|
* @param path path to the xapian db to search
|
|
|
|
* @param err receives error information (if there is any); if
|
|
|
|
* function returns non-NULL, err will _not_be set. err can be NULL
|
2010-11-24 19:04:20 +01:00
|
|
|
* possble errors (err->code) are MU_ERROR_XAPIAN_DIR and
|
|
|
|
* MU_ERROR_XAPIAN_NOT_UPTODATE
|
2010-11-23 23:47:36 +01:00
|
|
|
*
|
2010-08-25 20:46:16 +02:00
|
|
|
* @return a new MuQuery instance, or NULL in case of error.
|
|
|
|
* when the instance is no longer needed, use mu_query_destroy
|
2009-11-25 21:55:06 +01:00
|
|
|
* to free it
|
|
|
|
*/
|
2010-11-30 07:32:59 +01:00
|
|
|
MuQuery *mu_query_new (const char* path, GError **err)
|
|
|
|
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2010-08-25 20:46:16 +02:00
|
|
|
/**
|
|
|
|
* destroy the MuQuery instance
|
2009-11-25 21:55:06 +01:00
|
|
|
*
|
2010-08-25 20:46:16 +02:00
|
|
|
* @param self a MuQuery instance, or NULL
|
2009-11-25 21:55:06 +01:00
|
|
|
*/
|
2010-08-25 20:46:16 +02:00
|
|
|
void mu_query_destroy (MuQuery *self);
|
2010-01-23 19:50:06 +01:00
|
|
|
|
|
|
|
|
2010-08-25 20:46:16 +02:00
|
|
|
/**
|
2010-01-23 19:50:06 +01:00
|
|
|
* get a version string for the database
|
|
|
|
*
|
2010-08-25 20:46:16 +02:00
|
|
|
* @param store a valid MuQuery
|
2010-01-23 19:50:06 +01:00
|
|
|
*
|
|
|
|
* @return the version string (free with g_free), or NULL in case of error
|
|
|
|
*/
|
2010-11-30 07:32:59 +01:00
|
|
|
char* mu_query_version (MuQuery *store)
|
|
|
|
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2010-08-25 20:46:16 +02:00
|
|
|
/**
|
2009-11-25 21:55:06 +01:00
|
|
|
* run a Xapian query; for the syntax, please refer to the mu-find
|
|
|
|
* manpage, or http://xapian.org/docs/queryparser.html
|
|
|
|
*
|
2010-08-25 20:46:16 +02:00
|
|
|
* @param self a valid MuQuery instance
|
2009-11-25 21:55:06 +01:00
|
|
|
* @param expr the search expression
|
2010-11-20 13:43:04 +01:00
|
|
|
* @param sortfield the field id to sort by or MU_MSG_FIELD_ID_NONE if
|
|
|
|
* sorting is not desired
|
2010-01-23 23:51:17 +01:00
|
|
|
* @param ascending if TRUE sort in ascending (A-Z) order, otherwise,
|
|
|
|
* sort in descending (Z-A) order
|
|
|
|
* @param batchsize the size of batches to receive; this is mainly for
|
2010-01-24 12:15:04 +01:00
|
|
|
* reasons - it's best to get the size one wants to show the user at once.
|
|
|
|
* If you pass '0' as the batchsize, mu will use the maximum size (the count
|
|
|
|
* of documents in the database)
|
2010-11-23 23:47:36 +01:00
|
|
|
* @param err receives error information (if there is any); if
|
|
|
|
* function returns non-NULL, err will _not_be set. err can be NULL
|
2010-11-24 19:04:20 +01:00
|
|
|
* possible error (err->code) is MU_ERROR_QUERY,
|
2009-11-25 21:55:06 +01:00
|
|
|
*
|
2010-08-25 20:29:53 +02:00
|
|
|
* @return a MuMsgIter instance you can iterate over, or NULL in
|
2009-11-25 21:55:06 +01:00
|
|
|
* case of error
|
|
|
|
*/
|
2010-11-30 07:32:59 +01:00
|
|
|
MuMsgIter* mu_query_run (MuQuery *self, const char* expr,
|
|
|
|
MuMsgFieldId sortfieldid, gboolean ascending,
|
|
|
|
size_t batchsize, GError **err)
|
|
|
|
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2010-08-25 20:46:16 +02:00
|
|
|
/**
|
2009-11-25 21:55:06 +01:00
|
|
|
* get a string representation of the Xapian search query
|
|
|
|
*
|
2010-08-25 20:46:16 +02:00
|
|
|
* @param self a MuQuery instance
|
2009-11-25 21:55:06 +01:00
|
|
|
* @param searchexpr a xapian search expression
|
2010-11-23 23:47:36 +01:00
|
|
|
* @param err receives error information (if there is any); if
|
|
|
|
* function returns non-NULL, err will _not_be set. err can be NULL
|
2009-11-25 21:55:06 +01:00
|
|
|
*
|
|
|
|
* @return the string representation of the xapian query, or NULL in case of
|
|
|
|
* error; free the returned value with g_free
|
|
|
|
*/
|
2010-11-30 07:32:59 +01:00
|
|
|
char* mu_query_as_string (MuQuery *self, const char* searchexpr, GError **err)
|
|
|
|
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
|
|
|
|
2010-09-12 15:30:29 +02:00
|
|
|
/**
|
|
|
|
* pre-process the query; this function is useful mainly for debugging mu
|
|
|
|
*
|
|
|
|
* @param query a query string
|
|
|
|
*
|
|
|
|
* @return a pre-processed query, free it with g_free
|
|
|
|
*/
|
2010-11-30 07:32:59 +01:00
|
|
|
char* mu_query_preprocess (const char *query)
|
|
|
|
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
2009-11-25 21:55:06 +01:00
|
|
|
|
|
|
|
G_END_DECLS
|
|
|
|
|
2010-08-25 20:46:16 +02:00
|
|
|
#endif /*__MU_QUERY_H__*/
|