2011-08-30 21:02:08 +02:00
|
|
|
/*
|
2017-10-24 21:57:57 +02:00
|
|
|
** Copyright (C) 2008-2017 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.
|
2011-08-30 21:02:08 +02:00
|
|
|
**
|
2009-11-25 21:55:06 +01:00
|
|
|
** 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.
|
2011-08-30 21:02:08 +02:00
|
|
|
**
|
2009-11-25 21:55:06 +01:00
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program; if not, write to the Free Software Foundation,
|
2011-08-30 21:02:08 +02:00
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
2009-11-25 21:55:06 +01:00
|
|
|
*/
|
|
|
|
|
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>
|
2019-07-28 13:12:06 +02:00
|
|
|
#include <mu-store.hh>
|
2010-11-24 19:04:20 +01:00
|
|
|
#include <mu-msg-iter.h>
|
2019-12-16 20:44:35 +01:00
|
|
|
#include <utils/mu-util.h>
|
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
|
|
|
/**
|
2011-08-30 21:02:08 +02:00
|
|
|
* create a new MuQuery instance.
|
|
|
|
*
|
|
|
|
* @param store a MuStore object
|
2011-08-29 22:38:55 +02:00
|
|
|
* @param err receives error information (if there is any); if
|
|
|
|
* function returns non-NULL, err will _not_be set. err can be NULL
|
2019-11-06 16:13:39 +01:00
|
|
|
* possible errors (err->code) are MU_ERROR_XAPIAN_DIR and
|
2011-08-29 22:38:55 +02:00
|
|
|
* MU_ERROR_XAPIAN_NOT_UPTODATE
|
2011-08-30 21:02:08 +02:00
|
|
|
*
|
2011-08-29 22:38:55 +02:00
|
|
|
* @return a new MuQuery instance, or NULL in case of error.
|
|
|
|
* when the instance is no longer needed, use mu_query_destroy
|
|
|
|
* to free it
|
|
|
|
*/
|
2017-10-24 21:57:57 +02:00
|
|
|
MuQuery* mu_query_new (MuStore *store, GError **err)
|
2011-08-29 22:38:55 +02:00
|
|
|
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
|
|
|
|
2010-08-25 20:46:16 +02:00
|
|
|
/**
|
|
|
|
* destroy the MuQuery instance
|
2011-08-30 21:02:08 +02: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
|
|
|
|
2012-12-16 14:08:34 +01:00
|
|
|
|
2017-10-24 21:57:57 +02:00
|
|
|
typedef enum {
|
|
|
|
MU_QUERY_FLAG_NONE = 0 << 0, /**< no flags */
|
2012-12-25 16:34:24 +01:00
|
|
|
MU_QUERY_FLAG_DESCENDING = 1 << 0, /**< sort z->a */
|
|
|
|
MU_QUERY_FLAG_SKIP_UNREADABLE = 1 << 1, /**< skip unreadable msgs */
|
|
|
|
MU_QUERY_FLAG_SKIP_DUPS = 1 << 2, /**< skip duplicate msgs */
|
2012-12-27 10:09:05 +01:00
|
|
|
MU_QUERY_FLAG_INCLUDE_RELATED = 1 << 3, /**< include related msgs */
|
2017-12-03 21:16:32 +01:00
|
|
|
MU_QUERY_FLAG_THREADS = 1 << 4, /**< calculate threading info */
|
|
|
|
MU_QUERY_FLAG_RAW = 1 << 5 /**< don't parse the query */
|
2017-10-24 21:57:57 +02:00
|
|
|
} MuQueryFlags;
|
2012-12-16 14:08:34 +01:00
|
|
|
|
2010-08-25 20:46:16 +02:00
|
|
|
/**
|
2020-01-21 19:50:19 +01:00
|
|
|
* run a Xapian query; for the syntax, please refer to the mu-query
|
|
|
|
* manpage
|
2011-08-30 21:02:08 +02:00
|
|
|
*
|
2010-08-25 20:46:16 +02:00
|
|
|
* @param self a valid MuQuery instance
|
2011-12-30 12:26:58 +01:00
|
|
|
* @param expr the search expression; use "" to match all messages
|
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
|
2011-12-07 07:15:48 +01:00
|
|
|
* @param maxnum maximum number of search results to return, or <= 0 for
|
|
|
|
* unlimited
|
2012-12-16 14:08:34 +01:00
|
|
|
* @param flags bitwise OR'd flags to influence the query (see MuQueryFlags)
|
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
|
|
|
|
*/
|
2017-10-24 21:57:57 +02:00
|
|
|
MuMsgIter* mu_query_run (MuQuery *self, const char* expr,
|
|
|
|
MuMsgFieldId sortfieldid, int maxnum,
|
2012-12-16 14:08:34 +01:00
|
|
|
MuQueryFlags flags, GError **err)
|
2010-11-30 07:32:59 +01:00
|
|
|
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
2009-11-25 21:55:06 +01:00
|
|
|
|
2011-09-12 19:49:01 +02:00
|
|
|
|
2020-01-21 19:50:19 +01:00
|
|
|
/**
|
|
|
|
* run a Xapian query to count the number of matches; for the syntax, please
|
|
|
|
* refer to the mu-query manpage
|
|
|
|
*
|
|
|
|
* @param self a valid MuQuery instance
|
|
|
|
* @param expr the search expression; use "" to match all messages
|
|
|
|
*
|
|
|
|
* @return the number of matches
|
|
|
|
*/
|
|
|
|
size_t mu_query_count_run (MuQuery *self, const char *searchexpr);
|
|
|
|
|
2010-08-25 20:46:16 +02:00
|
|
|
/**
|
2017-10-24 21:57:57 +02:00
|
|
|
* get Xapian's internal string representation of the query
|
2011-08-30 21:02:08 +02:00
|
|
|
*
|
|
|
|
* @param self a MuQuery instance
|
2009-11-25 21:55:06 +01:00
|
|
|
* @param searchexpr a xapian search expression
|
2017-10-24 21:57:57 +02:00
|
|
|
* @param warn print warnings to stderr
|
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
|
2011-08-30 21:02:08 +02:00
|
|
|
*
|
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
|
|
|
|
*/
|
2017-10-24 21:57:57 +02:00
|
|
|
char* mu_query_internal (MuQuery *self, const char *searchexpr,
|
|
|
|
gboolean warn, GError **err)
|
2010-11-30 07:32:59 +01:00
|
|
|
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
2011-08-30 21:02:08 +02:00
|
|
|
|
2010-09-12 15:30:29 +02:00
|
|
|
/**
|
2017-10-24 21:57:57 +02:00
|
|
|
* get Xapian's internal string representation of the query
|
2011-08-30 21:02:08 +02:00
|
|
|
*
|
2017-10-24 21:57:57 +02:00
|
|
|
* @param self a MuQuery instance
|
|
|
|
* @param searchexpr a xapian search expression
|
|
|
|
* @param err receives error information (if there is any); if
|
|
|
|
* function returns non-NULL, err will _not_be set. err can be NULL
|
2011-08-30 21:02:08 +02:00
|
|
|
*
|
2017-10-24 21:57:57 +02:00
|
|
|
* @return the string representation of the xapian query, or NULL in case of
|
|
|
|
* error; free the returned value with g_free
|
2010-09-12 15:30:29 +02:00
|
|
|
*/
|
2017-10-24 21:57:57 +02:00
|
|
|
char* mu_query_internal_xapian (MuQuery *self, const char* searchexpr,
|
|
|
|
GError **err)
|
|
|
|
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__*/
|