fts-filter-stemmer-snowball.c revision 02c335c23bf5fa225a467c19f2c063fb0dc7b8c3
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zeleny/* Copyright (c) 2014-2016 Dovecot authors, see the included COPYING file */
20d0bc6d587f346238062df4da5edfde815e59b1Jan Zelenystatic void fts_filter_stemmer_snowball_destroy(struct fts_filter *filter)
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozekfts_filter_stemmer_snowball_create(const struct fts_language *lang,
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina const char *const *settings,
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina const char **error_r)
cf1a8af5556b1d8eab68802918c881ae1a0b89ebPavel Březina *error_r = t_strdup_printf("Unknown setting: %s", settings[0]);
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce pp = pool_alloconly_create(MEMPOOL_GROWING"fts_filter_stemmer_snowball",
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce sizeof(struct fts_filter));
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce sp = p_new(pp, struct fts_filter_stemmer_snowball, 1);
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce sp->lang = p_malloc(sp->pool, sizeof(struct fts_language));
1f800ebb0f190854b8296146174f3d696a426333Simo Sorcefts_filter_stemmer_snowball_create_stemmer(struct fts_filter_stemmer_snowball *sp,
1f800ebb0f190854b8296146174f3d696a426333Simo Sorce const char **error_r)
1f800ebb0f190854b8296146174f3d696a426333Simo Sorce sp->stemmer = sb_stemmer_new(sp->lang->name, "UTF_8");
1f800ebb0f190854b8296146174f3d696a426333Simo Sorce "Creating a Snowball stemmer for language '%s' failed.",
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce fts_filter_stemmer_snowball_destroy(&sp->filter);
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozekfts_filter_stemmer_snowball_filter(struct fts_filter *filter,
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek if (fts_filter_stemmer_snowball_create_stemmer(sp, error_r) < 0)
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek base = sb_stemmer_stem(sp->stemmer, (const unsigned char *)*token, strlen(*token));
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek /* the only reason why this could fail is because of
33c865412732554ef255e93c4e7a58b0bce963c6Jakub Hrozek out of memory. */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce *token = t_strndup(base, sb_stemmer_length(sp->stemmer));
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorcefts_filter_stemmer_snowball_create(const struct fts_language *lang ATTR_UNUSED,
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce const char **error_r)
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorcefts_filter_stemmer_snowball_destroy(struct fts_filter *stemmer ATTR_UNUSED)
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březinafts_filter_stemmer_snowball_filter(struct fts_filter *filter ATTR_UNUSED,
e1f68731525116ce686ffcdc07ad3a14e4fb1cd7Pavel Březinastatic const struct fts_filter fts_filter_stemmer_snowball_real = {