* mu-query-xapian: take a char** for combine; improve _get_query err handling

This commit is contained in:
Dirk-Jan C. Binnema
2009-12-11 22:06:49 +02:00
parent 3a7d6dfd34
commit 390b3db86f
2 changed files with 21 additions and 18 deletions

View File

@ -79,7 +79,6 @@ _uninit_mu_query_xapian (MuQueryXapian *mqx)
g_warning ("%s: caught exception", __FUNCTION__); g_warning ("%s: caught exception", __FUNCTION__);
} }
} }
static Xapian::Query static Xapian::Query
_get_query (MuQueryXapian * mqx, const char* searchexpr, int *err = 0) { _get_query (MuQueryXapian * mqx, const char* searchexpr, int *err = 0) {
@ -93,13 +92,16 @@ _get_query (MuQueryXapian * mqx, const char* searchexpr, int *err = 0) {
Xapian::QueryParser::FLAG_WILDCARD | Xapian::QueryParser::FLAG_WILDCARD |
Xapian::QueryParser::FLAG_PURE_NOT | Xapian::QueryParser::FLAG_PURE_NOT |
Xapian::QueryParser::FLAG_PARTIAL); Xapian::QueryParser::FLAG_PARTIAL);
} catch (const Xapian::Error& ex) {
g_warning ("error in query: %s (\"%s\")",
ex.get_msg().c_str(), searchexpr);
} catch (...) { } catch (...) {
g_warning ("%s: caught exception", __FUNCTION__); g_warning ("%s: caught exception", __FUNCTION__);
if (err)
*err = 1;
return Xapian::Query();
} }
if (err)
*err = 1;
return Xapian::Query();
} }
static void static void
@ -211,36 +213,37 @@ mu_query_xapian_as_string (MuQueryXapian *self, const char* searchexpr)
} }
char* char*
mu_query_xapian_combine (GSList *lst, gboolean connect_or) mu_query_xapian_combine (gchar **params, gboolean connect_or)
{ {
GString *str; GString *str;
int i;
g_return_val_if_fail (lst, NULL); g_return_val_if_fail (params && params[0], NULL);
str = g_string_sized_new (64); /* just a guess */ str = g_string_sized_new (64); /* just a guess */
while (lst) {
for (i = 0; params && params[i]; ++i) {
const char* elm; const char* elm;
const char* cnx = ""; const char* cnx = "";
gboolean do_quote; gboolean do_quote;
elm = (const gchar*)lst->data; elm = (const gchar*)params[i];
if (!elm) /* shouldn't happen */ if (!elm) /* shouldn't happen */
break; break;
if (lst->next) if (params[i + 1])
cnx = connect_or ? " OR " : " AND "; cnx = connect_or ? " OR " : " AND ";
do_quote = (strcasecmp (elm, "OR") == 0 || do_quote = (strcasecmp (elm, "OR") == 0 ||
strcasecmp (elm, "AND") == 0 || strcasecmp (elm, "AND") == 0 ||
strcasecmp (elm, "NOT") == 0); strcasecmp (elm, "NOT") == 0);
g_string_append_printf (str, "%s%s%s%s", g_string_append_printf (str, "%s%s%s%s",
do_quote ? "\"" : "", do_quote ? "\"" : "",
(gchar*)lst->data, elm,
do_quote ? "\"" : "", do_quote ? "\"" : "",
cnx); cnx);
lst = lst->next;
} }
return g_string_free (str, FALSE); return g_string_free (str, FALSE);
} }

View File

@ -73,13 +73,13 @@ MuMsgXapian* mu_query_xapian_run (MuQueryXapian *self,
* please refer to the mu-find manpage, or * please refer to the mu-find manpage, or
* http://xapian.org/docs/queryparser.html * http://xapian.org/docs/queryparser.html
* *
* @param lst a list of search expressions * @param string array of search expressions
* @param connect_or if TRUE, combine the expressions with OR, otherwise use AND * @param connect_or if TRUE, combine the expressions with OR, otherwise use AND
* *
* @return a string with the combined xapian expression or NULL in * @return a string with the combined xapian expression or NULL in
* case of error; free with g_free when it's no longer needed * case of error; free with g_free when it's no longer needed
*/ */
char* mu_query_xapian_combine (GSList *lst, gboolean connect_or); char* mu_query_xapian_combine (gchar **params, gboolean connect_or);
/** /**
* get a string representation of the Xapian search query * get a string representation of the Xapian search query