bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2014-2018 Dovecot authors, see the included COPYING file */
1ef271d30011acf79e8e2a42b7b9baae8a2264d3Timo Sirainenstatic ARRAY(const struct fts_filter *) fts_filter_classes;
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen i_array_init(&fts_filter_classes, FTS_FILTER_CLASSES_NR);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen fts_filter_register(fts_filter_stemmer_snowball);
63713f16bad8b55e74c479adb6b47965b519c29bTimo Sirainen fts_filter_register(fts_filter_normalizer_icu);
471167b9701fcc99b66f7a8bcae07bc4ac0dbbd4Timo Sirainen fts_filter_register(fts_filter_english_possessive);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenvoid fts_filter_register(const struct fts_filter *filter_class)
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen i_assert(fts_filter_find(filter_class->class_name) == NULL);
1ef271d30011acf79e8e2a42b7b9baae8a2264d3Timo Sirainen array_append(&fts_filter_classes, &filter_class, 1);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenconst struct fts_filter *fts_filter_find(const char *name)
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenint fts_filter_create(const struct fts_filter *filter_class,
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen const char *const *settings,
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen const char **error_r)
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen i_assert(settings == NULL || str_array_length(settings) % 2 == 0);
be7085921228e1c1333dbf7aa2daca41115c3f23Timo Sirainen if (filter_class->v.create(lang, settings, &fp, error_r) < 0) {
bc180e646844ad8ad8d0228016389434433fd405Timo Sirainen /* default implementation */
bc180e646844ad8ad8d0228016389434433fd405Timo Sirainen *error_r = t_strdup_printf("Unknown setting: %s", settings[0]);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenvoid fts_filter_unref(struct fts_filter **_fpp)
bc180e646844ad8ad8d0228016389434433fd405Timo Sirainen /* default destroy implementation */
2bb1ef0b669901fb91ff961e7fb074439ef769abTimo Sirainenint fts_filter_filter(struct fts_filter *filter, const char **token,
2bb1ef0b669901fb91ff961e7fb074439ef769abTimo Sirainen const char **error_r)
1d0f568e26ce5cbf18cd7bb335c6eea20a7e3770Teemu Huovila /* Recurse to parent. */
1d0f568e26ce5cbf18cd7bb335c6eea20a7e3770Teemu Huovila ret = fts_filter_filter(filter->parent, token, error_r);
1d0f568e26ce5cbf18cd7bb335c6eea20a7e3770Teemu Huovila /* Parent returned token or no parent. */