1 #ifndef FTS_API_PRIVATE_H 2 #define FTS_API_PRIVATE_H 3 4 #include "unichar.h" 5 #include "fts-api.h" 6 7 struct mail_user; 8 struct mailbox_list; 9 10 #define MAILBOX_GUID_HEX_LENGTH (GUID_128_SIZE*2) 11 12 struct fts_backend_vfuncs { 13 struct fts_backend *(*alloc)(void); 14 int (*init)(struct fts_backend *backend, const char **error_r); 15 void (*deinit)(struct fts_backend *backend); 16 17 int (*get_last_uid)(struct fts_backend *backend, struct mailbox *box, 18 uint32_t *last_uid_r); 19 20 struct fts_backend_update_context * 21 (*update_init)(struct fts_backend *backend); 22 int (*update_deinit)(struct fts_backend_update_context *ctx); 23 24 void (*update_set_mailbox)(struct fts_backend_update_context *ctx, 25 struct mailbox *box); 26 void (*update_expunge)(struct fts_backend_update_context *ctx, 27 uint32_t uid); 28 29 /* Start a build for specified key */ 30 bool (*update_set_build_key)(struct fts_backend_update_context *ctx, 31 const struct fts_backend_build_key *key); 32 /* Finish a build for specified key - guaranteed to be called */ 33 void (*update_unset_build_key)(struct fts_backend_update_context *ctx); 34 /* Add data for current build key */ 35 int (*update_build_more)(struct fts_backend_update_context *ctx, 36 const unsigned char *data, size_t size); 37 38 int (*refresh)(struct fts_backend *backend); 39 int (*rescan)(struct fts_backend *backend); 40 int (*optimize)(struct fts_backend *backend); 41 42 bool (*can_lookup)(struct fts_backend *backend, 43 const struct mail_search_arg *args); 44 int (*lookup)(struct fts_backend *backend, struct mailbox *box, 45 struct mail_search_arg *args, enum fts_lookup_flags flags, 46 struct fts_result *result); 47 int (*lookup_multi)(struct fts_backend *backend, 48 struct mailbox *const boxes[], 49 struct mail_search_arg *args, 50 enum fts_lookup_flags flags, 51 struct fts_multi_result *result); 52 void (*lookup_done)(struct fts_backend *backend); 53 }; 54 55 enum fts_backend_flags { 56 /* Backend supports indexing binary MIME parts */ 57 FTS_BACKEND_FLAG_BINARY_MIME_PARTS = 0x01, 58 /* Send built text to backend normalized rather than 59 preserving original case */ 60 FTS_BACKEND_FLAG_NORMALIZE_INPUT = 0x02, 61 /* Send only fully indexable words rather than randomly sized blocks */ 62 FTS_BACKEND_FLAG_BUILD_FULL_WORDS = 0x04, 63 /* Fuzzy search works */ 64 FTS_BACKEND_FLAG_FUZZY_SEARCH = 0x08, 65 /* Tokenize all the input. update_build_more() will be called a single 66 directly indexable token at a time. Searching will modify the search 67 args so that lookup() sees only tokens that can be directly 68 searched. */ 69 FTS_BACKEND_FLAG_TOKENIZED_INPUT = 0x10 70 }; 71 72 struct fts_backend { 73 const char *name; 74 enum fts_backend_flags flags; 75 76 struct fts_backend_vfuncs v; 77 struct mail_namespace *ns; 78 79 bool updating:1; 80 }; 81 82 struct fts_backend_update_context { 83 struct fts_backend *backend; 84 normalizer_func_t *normalizer; 85 86 struct mailbox *cur_box, *backend_box; 87 88 bool build_key_open:1; 89 bool failed:1; 90 }; 91 92 struct fts_index_header { 93 uint32_t last_indexed_uid; 94 95 /* Checksum of settings. If the settings change, the index should 96 be rebuilt. */ 97 uint32_t settings_checksum; 98 uint32_t unused; 99 }; 100 101 void fts_backend_register(const struct fts_backend *backend); 102 void fts_backend_unregister(const char *name); 103 104 bool fts_backend_default_can_lookup(struct fts_backend *backend, 105 const struct mail_search_arg *args); 106 107 void fts_filter_uids(ARRAY_TYPE(seq_range) *definite_dest, 108 const ARRAY_TYPE(seq_range) *definite_filter, 109 ARRAY_TYPE(seq_range) *maybe_dest, 110 const ARRAY_TYPE(seq_range) *maybe_filter); 111 112 /* Returns TRUE if ok, FALSE if no fts header */ 113 bool fts_index_get_header(struct mailbox *box, struct fts_index_header *hdr_r); 114 int fts_index_set_header(struct mailbox *box, 115 const struct fts_index_header *hdr); 116 int ATTR_NOWARN_UNUSED_RESULT 117 fts_index_set_last_uid(struct mailbox *box, uint32_t last_uid); 118 int fts_backend_reset_last_uids(struct fts_backend *backend); 119 int fts_index_have_compatible_settings(struct mailbox_list *list, 120 uint32_t checksum); 121 122 /* Returns TRUE if FTS backend should index the header for optimizing 123 separate lookups */ 124 bool fts_header_want_indexed(const char *hdr_name); 125 /* Returns TRUE if header's values should be considered to have a language. */ 126 bool fts_header_has_language(const char *hdr_name); 127 128 int fts_mailbox_get_guid(struct mailbox *box, const char **guid_r); 129 130 #endif 131