]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fts-flatcurve: Simplify handling of phrase queries
authorMarco Bettini <marco.bettini@open-xchange.com>
Thu, 17 Nov 2022 15:10:56 +0000 (15:10 +0000)
committerMarco Bettini <marco.bettini@open-xchange.com>
Fri, 25 Nov 2022 10:42:12 +0000 (10:42 +0000)
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.

src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc

index 0145e2e580ad5377645f49bc22705d41f9881f17..0f0e30e9126fee20434c1e71b9a87d30465f4b13 100644 (file)
@@ -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));
        }
 }