update commands for new query parser

This commit is contained in:
djcb 2017-10-24 22:58:32 +03:00
parent 5e9cafea59
commit aa07c4a27c
6 changed files with 56 additions and 46 deletions

View File

@ -173,7 +173,7 @@ struct MuProc: public Mux::ProcIface {
const Xapian::Database& db_; const Xapian::Database& db_;
}; };
class _MuQuery { struct _MuQuery {
public: public:
_MuQuery (MuStore *store): _store(mu_store_ref(store)) {} _MuQuery (MuStore *store): _store(mu_store_ref(store)) {}
~_MuQuery () { mu_store_unref (_store); } ~_MuQuery () { mu_store_unref (_store); }

View File

@ -59,6 +59,7 @@ mu-help-strings.h: mu-help-strings.txt mu-help-strings.awk
mu_LDADD= \ mu_LDADD= \
${top_builddir}/lib/libmu.la \ ${top_builddir}/lib/libmu.la \
${top_builddir}/lib/parser/libmuxparser.la \
$(GLIB_LIBS) $(GLIB_LIBS)
EXTRA_DIST= \ EXTRA_DIST= \

View File

@ -48,20 +48,26 @@ typedef gboolean (OutputFunc) (MuMsg *msg, MuMsgIter *iter,
MuConfig *opts, GError **err); MuConfig *opts, GError **err);
static gboolean static gboolean
print_xapian_query (MuQuery *xapian, const gchar *query, GError **err) print_internal (MuQuery *query, const gchar *expr, gboolean xapian,
gboolean warn, GError **err)
{ {
char *querystr; char *str;
querystr = mu_query_as_string (xapian, query, err); if (xapian)
if (!querystr) str = mu_query_internal_xapian (query, expr, err);
return FALSE; else
str = mu_query_internal (query, expr, warn, err);
g_print ("%s\n", querystr); if (str) {
g_free (querystr); g_print ("%s\n", str);
g_free (str);
}
return TRUE; return str != NULL;
} }
/* returns MU_MSG_FIELD_ID_NONE if there is an error */ /* returns MU_MSG_FIELD_ID_NONE if there is an error */
static MuMsgFieldId static MuMsgFieldId
sort_field_from_string (const char* fieldstr, GError **err) sort_field_from_string (const char* fieldstr, GError **err)
@ -203,7 +209,7 @@ get_query (MuConfig *opts, GError **err)
return NULL; return NULL;
} }
query = mu_str_quoted_from_strv ((const gchar**)&opts->params[1]); query = g_strjoinv (" ", &opts->params[1]);
if (bookmarkval) { if (bookmarkval) {
gchar *tmp; gchar *tmp;
tmp = g_strdup_printf ("%s %s", bookmarkval, query); tmp = g_strdup_printf ("%s %s", bookmarkval, query);
@ -654,7 +660,7 @@ execute_find (MuStore *store, MuConfig *opts, GError **err)
MuQuery *oracle; MuQuery *oracle;
gboolean rv; gboolean rv;
oracle = get_query_obj(store, err); oracle = get_query_obj (store, err);
if (!oracle) if (!oracle)
return FALSE; return FALSE;
@ -665,7 +671,10 @@ execute_find (MuStore *store, MuConfig *opts, GError **err)
} }
if (opts->format == MU_CONFIG_FORMAT_XQUERY) if (opts->format == MU_CONFIG_FORMAT_XQUERY)
rv = print_xapian_query (oracle, query_str, err); rv = print_internal (oracle, query_str, TRUE, FALSE, err);
else if (opts->format == MU_CONFIG_FORMAT_MQUERY)
rv = print_internal (oracle, query_str, FALSE,
opts->verbose, err);
else else
rv = process_query (oracle, query_str, opts, err); rv = process_query (oracle, query_str, opts, err);
@ -687,6 +696,7 @@ format_params_valid (MuConfig *opts, GError **err)
case MU_CONFIG_FORMAT_LINKS: case MU_CONFIG_FORMAT_LINKS:
case MU_CONFIG_FORMAT_XML: case MU_CONFIG_FORMAT_XML:
case MU_CONFIG_FORMAT_XQUERY: case MU_CONFIG_FORMAT_XQUERY:
case MU_CONFIG_FORMAT_MQUERY:
if (opts->exec) { if (opts->exec) {
mu_util_g_set_error mu_util_g_set_error
(err, MU_ERROR_IN_PARAMETERS, (err, MU_ERROR_IN_PARAMETERS,

View File

@ -275,7 +275,7 @@ get_docid_from_msgid (MuQuery *query, const char *str, GError **err)
unsigned docid; unsigned docid;
MuMsgIter *iter; MuMsgIter *iter;
querystr = g_strdup_printf ("msgid:\"%s\"", str); querystr = g_strdup_printf ("msgid:%s", str);
iter = mu_query_run (query, querystr, iter = mu_query_run (query, querystr,
MU_MSG_FIELD_ID_NONE, MU_MSG_FIELD_ID_NONE,
1, MU_QUERY_FLAG_NONE, err); 1, MU_QUERY_FLAG_NONE, err);
@ -310,7 +310,7 @@ get_docids_from_msgids (MuQuery *query, const char *str, GError **err)
MuMsgIter *iter; MuMsgIter *iter;
GSList *lst; GSList *lst;
querystr = g_strdup_printf ("msgid:\"%s\"", str); querystr = g_strdup_printf ("msgid:%s", str);
iter = mu_query_run (query, querystr, MU_MSG_FIELD_ID_NONE, iter = mu_query_run (query, querystr, MU_MSG_FIELD_ID_NONE,
-1 /*unlimited*/, MU_QUERY_FLAG_NONE, -1 /*unlimited*/, MU_QUERY_FLAG_NONE,
err); err);
@ -360,7 +360,6 @@ determine_docid (MuQuery *query, GHashTable *args, GError **err)
} }
#define DOCID_VALID_OR_ERROR_RETURN(DOCID,E) \ #define DOCID_VALID_OR_ERROR_RETURN(DOCID,E) \
if ((DOCID)==MU_STORE_INVALID_DOCID) { \ if ((DOCID)==MU_STORE_INVALID_DOCID) { \
mu_util_g_set_error((E),MU_ERROR_IN_PARAMETERS, \ mu_util_g_set_error((E),MU_ERROR_IN_PARAMETERS, \

View File

@ -52,7 +52,8 @@ get_output_format (const char *formatstr)
{"plain", MU_CONFIG_FORMAT_PLAIN}, {"plain", MU_CONFIG_FORMAT_PLAIN},
{"sexp", MU_CONFIG_FORMAT_SEXP}, {"sexp", MU_CONFIG_FORMAT_SEXP},
{"xml", MU_CONFIG_FORMAT_XML}, {"xml", MU_CONFIG_FORMAT_XML},
{"xquery", MU_CONFIG_FORMAT_XQUERY} {"xquery", MU_CONFIG_FORMAT_XQUERY},
{"mquery", MU_CONFIG_FORMAT_MQUERY}
}; };
for (i = 0; i != G_N_ELEMENTS(formats); i++) for (i = 0; i != G_N_ELEMENTS(formats); i++)

View File

@ -1,7 +1,7 @@
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/ /* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
/* /*
** Copyright (C) 2008-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> ** Copyright (C) 2008-2017 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** **
** This program is free software; you can redistribute it and/or modify it ** 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 ** under the terms of the GNU General Public License as published by the
@ -55,6 +55,7 @@ enum _MuConfigFormat {
MU_CONFIG_FORMAT_LINKS, /* output as symlinks */ MU_CONFIG_FORMAT_LINKS, /* output as symlinks */
MU_CONFIG_FORMAT_XML, /* output xml */ MU_CONFIG_FORMAT_XML, /* output xml */
MU_CONFIG_FORMAT_XQUERY, /* output the xapian query */ MU_CONFIG_FORMAT_XQUERY, /* output the xapian query */
MU_CONFIG_FORMAT_MQUERY, /* output the mux query */
MU_CONFIG_FORMAT_EXEC /* execute some command */ MU_CONFIG_FORMAT_EXEC /* execute some command */
}; };
@ -166,7 +167,6 @@ struct _MuConfig {
* multiple messages in mu * multiple messages in mu
* view */ * view */
/* options for cfind (and 'find' --> "after") */ /* options for cfind (and 'find' --> "after") */
gboolean personal; /* only show 'personal' addresses */ gboolean personal; /* only show 'personal' addresses */
/* also 'after' --> see above */ /* also 'after' --> see above */
@ -227,7 +227,6 @@ void mu_config_uninit (MuConfig *conf);
*/ */
MuError mu_config_execute (MuConfig *conf); MuError mu_config_execute (MuConfig *conf);
/** /**
* count the number of non-option parameters * count the number of non-option parameters
* *