1
/* Copyright (c) 2014-2015 Dovecot authors, see the included COPYING file */
5
#include "fts-language.h"
6
#include "fts-filter.h"
7
#include "fts-filter-private.h"
9
static ARRAY(const struct fts_filter *) fts_filter_classes;
11
void fts_filters_init(void)
13
i_array_init(&fts_filter_classes, FTS_FILTER_CLASSES_NR);
15
fts_filter_register(fts_filter_stopwords);
16
fts_filter_register(fts_filter_stemmer_snowball);
17
fts_filter_register(fts_filter_normalizer_icu);
18
fts_filter_register(fts_filter_lowercase);
21
void fts_filters_deinit(void)
23
array_free(&fts_filter_classes);
26
void fts_filter_register(const struct fts_filter *filter_class)
28
i_assert(fts_filter_find(filter_class->class_name) == NULL);
30
array_append(&fts_filter_classes, &filter_class, 1);
33
const struct fts_filter *fts_filter_find(const char *name)
35
const struct fts_filter *const *fp = NULL;
37
array_foreach(&fts_filter_classes, fp) {
38
if (strcmp((*fp)->class_name, name) == 0)
44
int fts_filter_create(const struct fts_filter *filter_class,
45
struct fts_filter *parent,
46
const struct fts_language *lang,
47
const char *const *settings,
48
struct fts_filter **filter_r,
51
struct fts_filter *fp;
52
const char *empty_settings = NULL;
54
i_assert(settings == NULL || str_array_length(settings) % 2 == 0);
57
settings = &empty_settings;
59
if (filter_class->v->create(lang, settings, &fp, error_r) < 0) {
66
fts_filter_ref(parent);
71
void fts_filter_ref(struct fts_filter *fp)
73
i_assert(fp->refcount > 0);
78
void fts_filter_unref(struct fts_filter **_fpp)
80
struct fts_filter *fp = *_fpp;
82
i_assert(fp->refcount > 0);
85
if (--fp->refcount > 0)
88
if (fp->parent != NULL)
89
fts_filter_unref(&fp->parent);
93
int fts_filter_filter(struct fts_filter *filter, const char **token,
98
i_assert((*token)[0] != '\0');
100
/* Recurse to parent. */
101
if (filter->parent != NULL)
102
ret = fts_filter_filter(filter->parent, token, error_r);
104
/* Parent returned token or no parent. */
105
if (ret > 0 || filter->parent == NULL)
106
ret = filter->v->filter(filter, token, error_r);
111
i_assert(*token != NULL);
112
i_assert((*token)[0] != '\0');