* fix searching for strings with spaces (e.g. maildir:"sent items")
This commit is contained in:
@ -294,6 +294,35 @@ resolve_bookmark (MuConfig *opts, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
gchar*
|
||||||
|
str_quoted_from_strv (const gchar **params)
|
||||||
|
{
|
||||||
|
GString *str;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
g_return_val_if_fail (params, NULL);
|
||||||
|
|
||||||
|
if (!params[0])
|
||||||
|
return g_strdup ("");
|
||||||
|
|
||||||
|
str = g_string_sized_new (64); /* just a guess */
|
||||||
|
|
||||||
|
for (i = 0; params[i]; ++i) {
|
||||||
|
|
||||||
|
if (i > 0)
|
||||||
|
g_string_append_c (str, ' ');
|
||||||
|
|
||||||
|
g_string_append_c (str, '"');
|
||||||
|
g_string_append (str, params[i]);
|
||||||
|
g_string_append_c (str, '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_string_free (str, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static gchar*
|
static gchar*
|
||||||
get_query (MuConfig *opts, GError **err)
|
get_query (MuConfig *opts, GError **err)
|
||||||
{
|
{
|
||||||
@ -313,7 +342,7 @@ get_query (MuConfig *opts, GError **err)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
query = mu_util_str_from_strv ((const gchar**)&opts->params[1]);
|
query = str_quoted_from_strv ((const gchar**)&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);
|
||||||
|
|||||||
@ -203,7 +203,8 @@ get_query (MuQuery *mqx, const char* searchexpr, GError **err)
|
|||||||
Xapian::QueryParser::FLAG_PURE_NOT |
|
Xapian::QueryParser::FLAG_PURE_NOT |
|
||||||
Xapian::QueryParser::FLAG_WILDCARD |
|
Xapian::QueryParser::FLAG_WILDCARD |
|
||||||
Xapian::QueryParser::FLAG_AUTO_SYNONYMS |
|
Xapian::QueryParser::FLAG_AUTO_SYNONYMS |
|
||||||
Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE);
|
Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE
|
||||||
|
);
|
||||||
g_free (preprocessed);
|
g_free (preprocessed);
|
||||||
return query;
|
return query;
|
||||||
|
|
||||||
@ -275,22 +276,32 @@ mu_query_destroy (MuQuery *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* preprocess a query to make them a bit more permissive */
|
/* preprocess a query to make them a bit more promiscuous */
|
||||||
char*
|
char*
|
||||||
mu_query_preprocess (const char *query)
|
mu_query_preprocess (const char *query)
|
||||||
{
|
{
|
||||||
gchar *my_query;
|
GSList *parts, *cur;
|
||||||
|
gchar *myquery;
|
||||||
|
|
||||||
g_return_val_if_fail (query, NULL);
|
g_return_val_if_fail (query, NULL);
|
||||||
my_query = g_strdup (query);
|
|
||||||
|
|
||||||
/* remove accents and turn to lower-case */
|
/* convert the query to a list of query terms, and escape them
|
||||||
mu_str_normalize_in_place (my_query, TRUE);
|
* separately */
|
||||||
/* escape '@', single '_' and ':' if it's not following a
|
parts = mu_str_esc_to_list (query);
|
||||||
* xapian-pfx with '_' */
|
|
||||||
mu_str_ascii_xapian_escape_in_place (my_query);
|
|
||||||
|
|
||||||
return my_query;
|
for (cur = parts; cur; cur = g_slist_next(cur)) {
|
||||||
|
/* remove accents and turn to lower-case */
|
||||||
|
cur->data = mu_str_normalize_in_place ((gchar*)cur->data, TRUE);
|
||||||
|
/* escape '@', single '_' and ':' if it's not following a
|
||||||
|
* xapian-pfx with '_' */
|
||||||
|
cur->data = mu_str_ascii_xapian_escape_in_place
|
||||||
|
((gchar*)cur->data, TRUE /*escape spaces too*/);
|
||||||
|
}
|
||||||
|
|
||||||
|
myquery = mu_str_from_list (parts, ' ');
|
||||||
|
mu_str_free_list (parts);
|
||||||
|
|
||||||
|
return myquery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
12
src/mu-str.c
12
src/mu-str.c
@ -432,7 +432,7 @@ mu_str_subject_normalize (const gchar* str)
|
|||||||
* specially; function below is an ugly hack to make it DWIM in most
|
* specially; function below is an ugly hack to make it DWIM in most
|
||||||
* cases...*/
|
* cases...*/
|
||||||
char*
|
char*
|
||||||
mu_str_ascii_xapian_escape_in_place (char *query)
|
mu_str_ascii_xapian_escape_in_place (char *query, gboolean esc_space)
|
||||||
{
|
{
|
||||||
gchar *cur;
|
gchar *cur;
|
||||||
const char escchar = '_';
|
const char escchar = '_';
|
||||||
@ -444,10 +444,14 @@ mu_str_ascii_xapian_escape_in_place (char *query)
|
|||||||
*cur = tolower(*cur);
|
*cur = tolower(*cur);
|
||||||
|
|
||||||
switch (*cur) {
|
switch (*cur) {
|
||||||
|
case ' ':
|
||||||
|
if (!esc_space)
|
||||||
|
break;
|
||||||
case '@':
|
case '@':
|
||||||
case '-':
|
case '-':
|
||||||
case '/':
|
case '/':
|
||||||
case '.': {
|
case '.':
|
||||||
|
{
|
||||||
/* don't replace a final special char */
|
/* don't replace a final special char */
|
||||||
if (cur[1]== ' ' || cur[1]=='\t' || cur[1]== '.')
|
if (cur[1]== ' ' || cur[1]=='\t' || cur[1]== '.')
|
||||||
++cur;
|
++cur;
|
||||||
@ -472,11 +476,11 @@ mu_str_ascii_xapian_escape_in_place (char *query)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
mu_str_ascii_xapian_escape (const char *query)
|
mu_str_ascii_xapian_escape (const char *query, gboolean esc_space)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (query, NULL);
|
g_return_val_if_fail (query, NULL);
|
||||||
|
|
||||||
return mu_str_ascii_xapian_escape_in_place (g_strdup(query));
|
return mu_str_ascii_xapian_escape_in_place (g_strdup(query), esc_space);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -141,10 +141,11 @@ char* mu_str_normalize_in_place (char *str, gboolean downcase);
|
|||||||
* works for ascii strings, like e-mail addresses and message-id.
|
* works for ascii strings, like e-mail addresses and message-id.
|
||||||
*
|
*
|
||||||
* @param query a query string
|
* @param query a query string
|
||||||
|
* @param esc_space escape space characters as well
|
||||||
*
|
*
|
||||||
* @return the escaped string or NULL in case of error
|
* @return the escaped string or NULL in case of error
|
||||||
*/
|
*/
|
||||||
char* mu_str_ascii_xapian_escape_in_place (char *query);
|
char* mu_str_ascii_xapian_escape_in_place (char *query, gboolean esc_space);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* escape the string for use with xapian matching. in practice, if the
|
* escape the string for use with xapian matching. in practice, if the
|
||||||
@ -155,10 +156,11 @@ char* mu_str_ascii_xapian_escape_in_place (char *query);
|
|||||||
* works for ascii strings, like e-mail addresses and message-id.
|
* works for ascii strings, like e-mail addresses and message-id.
|
||||||
*
|
*
|
||||||
* @param query a query string
|
* @param query a query string
|
||||||
|
* @param esc_space escape space characters as well
|
||||||
*
|
*
|
||||||
* @return the escaped string (free with g_free) or NULL in case of error
|
* @return the escaped string (free with g_free) or NULL in case of error
|
||||||
*/
|
*/
|
||||||
char* mu_str_ascii_xapian_escape (const char *query)
|
char* mu_str_ascii_xapian_escape (const char *query, gboolean esc_space)
|
||||||
G_GNUC_WARN_UNUSED_RESULT;
|
G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -284,7 +284,7 @@ mu_util_str_from_strv (const gchar **params)
|
|||||||
|
|
||||||
for (i = 0; params[i]; ++i) {
|
for (i = 0; params[i]; ++i) {
|
||||||
|
|
||||||
if (i>0)
|
if (i > 0)
|
||||||
g_string_append_c (str, ' ');
|
g_string_append_c (str, ' ');
|
||||||
|
|
||||||
g_string_append (str, params[i]);
|
g_string_append (str, params[i]);
|
||||||
@ -293,6 +293,11 @@ mu_util_str_from_strv (const gchar **params)
|
|||||||
return g_string_free (str, FALSE);
|
return g_string_free (str, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
mu_util_create_writeable_fd (const char* path, mode_t mode,
|
mu_util_create_writeable_fd (const char* path, mode_t mode,
|
||||||
gboolean overwrite)
|
gboolean overwrite)
|
||||||
@ -482,5 +487,3 @@ mu_util_printerr_encoded (const char *frm, ...)
|
|||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user