* mu-query-xapian: take a char** for combine; improve _get_query err handling
This commit is contained in:
@ -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)
|
if (err)
|
||||||
*err = 1;
|
*err = 1;
|
||||||
|
|
||||||
return Xapian::Query();
|
return Xapian::Query();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -211,23 +213,26 @@ 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 ||
|
||||||
@ -236,11 +241,9 @@ mu_query_xapian_combine (GSList *lst, gboolean connect_or)
|
|||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user