From: Marco Bettini Date: Thu, 17 Nov 2022 15:10:56 +0000 (+0000) Subject: fts-flatcurve: Simplify handling of phrase queries X-Git-Tag: 2.4.0~3382 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7e82e7d61b4e6dbd2049750f9f79939a512371c;p=thirdparty%2Fdovecot%2Fcore.git fts-flatcurve: Simplify handling of phrase queries Dovecot FTS drivers can't properly support phrase searching (as of v2.3.19), so simply ignore these queries in flatcurve. Both IMAP searches and doveadm searches will pass both the phrase and the component terms as part of the query, so no need to split the phrases in the plugin. --- diff --git a/src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc b/src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc index 0145e2e580..0f0e30e912 100644 --- a/src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc +++ b/src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc @@ -2030,8 +2030,6 @@ static void fts_flatcurve_build_query_arg(struct flatcurve_fts_query *query, struct mail_search_arg *arg) { - struct flatcurve_fts_query_xapian *x = query->xapian; - if (arg->no_fts) return; @@ -2072,33 +2070,18 @@ fts_flatcurve_build_query_arg(struct flatcurve_fts_query *query, if (*arg->value.str == '\0') { /* This is an existence search. */ fts_flatcurve_build_query_arg_term(query, arg, ""); - return; - } - - /* Prepare search term. Phrase searching is not supported - * natively (FTS core provides index terms without positional - * context) so we can only do single term searching with - * Xapian. Therefore, if we do see a multi-term search, break - * it apart and do a maybe query. */ - const char *const *parts = t_strsplit_spaces(arg->value.str, " "); - unsigned int count = str_array_length(parts); - if (count > 1) - query->maybe = TRUE; - - for (unsigned int index = 0; index < count; index++, parts++) { - /* For phrase searches, we only add wildcard to the - * last term. */ - const char *term = (index + 1) == count ? - t_strconcat(*parts, "*", NULL) : *parts; - - fts_flatcurve_build_query_arg_term(query, arg, term); - - /* We need to AND search all phrase terms. */ - if (count > 1) { - struct flatcurve_fts_query_arg *qarg = - array_back_modifiable(&x->args); - qarg->is_and = TRUE; - } + } else if (strchr(arg->value.str, ' ') != NULL) { + /* Phrase searching is not supported natively, so we can only do + * single term searching with Xapian (FTS core provides index + * terms without positional context). + + * As of v2.3.19, FTS core will send both the phrase search and + * individual search terms separately as part of the same query. + * Therefore, If we do see a multi-term search, just ignore it */ + } else { + /* Prepare search term. */ + fts_flatcurve_build_query_arg_term(query, arg, + t_strdup_printf("%s*", arg->value.str)); } }