From: Phil Carmody Date: Wed, 16 May 2018 13:32:35 +0000 (+0300) Subject: lib-fts: tokenizer-generic - recognise request for explicit prefix searching X-Git-Tag: 2.3.9~1280 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=336ddc224efa86d9b2f51243a134f25857d53521;p=thirdparty%2Fdovecot%2Fcore.git lib-fts: tokenizer-generic - recognise request for explicit prefix searching Just store a flag in the tokenizer when the setting is seen, nothing more. Signed-off-by: Phil Carmody --- diff --git a/src/lib-fts/fts-tokenizer-generic-private.h b/src/lib-fts/fts-tokenizer-generic-private.h index e9b8f597af..2669023bc5 100644 --- a/src/lib-fts/fts-tokenizer-generic-private.h +++ b/src/lib-fts/fts-tokenizer-generic-private.h @@ -40,6 +40,7 @@ enum boundary_algorithm { struct generic_fts_tokenizer { struct fts_tokenizer tokenizer; unsigned int max_length; + bool prefixsplat; /* for search strings, accept a trailing '*' for explicit prefix */ bool wb5a; /* TR29 rule for prefix separation in e.g. French or Italian. */ bool seen_wb5a; diff --git a/src/lib-fts/fts-tokenizer-generic.c b/src/lib-fts/fts-tokenizer-generic.c index 1bcc8db4eb..797e431616 100644 --- a/src/lib-fts/fts-tokenizer-generic.c +++ b/src/lib-fts/fts-tokenizer-generic.c @@ -36,6 +36,8 @@ fts_tokenizer_generic_create(const char *const *settings, unsigned int max_length = FTS_DEFAULT_TOKEN_MAX_LENGTH; enum boundary_algorithm algo = BOUNDARY_ALGORITHM_SIMPLE; bool wb5a = FALSE; + bool search = FALSE; + bool explicitprefix = FALSE; unsigned int i; for (i = 0; settings[i] != NULL; i += 2) { @@ -61,17 +63,24 @@ fts_tokenizer_generic_create(const char *const *settings, } else if (strcmp(key, "search") == 0) { /* tokenizing a search string - makes no difference to us */ + search = TRUE; } else if (strcasecmp(key, "wb5a") == 0) { if (strcasecmp(value, "no") == 0) wb5a = FALSE; else wb5a = TRUE; + } else if (strcasecmp(key, "explicitprefix") == 0) { + explicitprefix = TRUE; } else { *error_r = t_strdup_printf("Unknown setting: %s", key); return -1; } } + /* Tokenise normally unless tokenising an explicit prefix query */ + if (!search) + explicitprefix = FALSE; + if (wb5a && algo != BOUNDARY_ALGORITHM_TR29) { *error_r = "Can not use WB5a for algorithms other than TR29."; return -1; @@ -85,6 +94,7 @@ fts_tokenizer_generic_create(const char *const *settings, tok->max_length = max_length; tok->algorithm = algo; tok->wb5a = wb5a; + tok->prefixsplat = explicitprefix; tok->token = buffer_create_dynamic(default_pool, 64); *tokenizer_r = &tok->tokenizer;