c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef LUCENE_WRAPPER_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define LUCENE_WRAPPER_H
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen#include "fts-api-private.h"
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen#include "guid.h"
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainenstruct mailbox_list;
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainenstruct fts_expunge_log;
c37098f8ce6d512ba41f09564d04ed25720f0a77Timo Sirainenstruct fts_lucene_settings;
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainen
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen#define MAILBOX_GUID_HEX_LENGTH (GUID_128_SIZE*2)
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainenstruct lucene_index_record {
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen guid_128_t mailbox_guid;
57b523eeb99ed5d7f5002907a409cdef54353ce5Timo Sirainen uint32_t uid, part_num;
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainen};
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainen
678d0463849ba777106eb7875f27db07a5d8e3dfTimo SirainenHASH_TABLE_DEFINE_TYPE(wguid_result, wchar_t *, struct fts_result *);
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainenstruct lucene_index *
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainenlucene_index_init(const char *path, struct mailbox_list *list,
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen const struct fts_lucene_settings *set)
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen ATTR_NULL(2, 3);
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainenvoid lucene_index_deinit(struct lucene_index *index);
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen
62bf16bd8bb79e308e64110ae8d0b2a55a4c1490Timo Sirainenvoid lucene_index_select_mailbox(struct lucene_index *index,
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen const wchar_t guid[MAILBOX_GUID_HEX_LENGTH]);
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainenvoid lucene_index_unselect_mailbox(struct lucene_index *index);
37f96554a5734557cd454691d163e602d36384b4Timo Sirainenint lucene_index_get_last_uid(struct lucene_index *index, uint32_t *last_uid_r);
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainenint lucene_index_get_doc_count(struct lucene_index *index, uint32_t *count_r);
6380f2bc729a03b328793e8ad6ba7587620fa184Timo Sirainen
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainenint lucene_index_build_init(struct lucene_index *index);
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainenint lucene_index_build_more(struct lucene_index *index, uint32_t uid,
57b523eeb99ed5d7f5002907a409cdef54353ce5Timo Sirainen uint32_t part_num, const unsigned char *data,
57b523eeb99ed5d7f5002907a409cdef54353ce5Timo Sirainen size_t size, const char *hdr_name);
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainenint lucene_index_build_deinit(struct lucene_index *index);
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainenvoid lucene_index_close(struct lucene_index *index);
03f4c5f3502801f5b318f464cc75313a88558805Timo Sirainenint lucene_index_rescan(struct lucene_index *index);
027c729b3107441f54a2602ccf2c67c6206998d5Timo Sirainenint lucene_index_expunge_from_log(struct lucene_index *index,
027c729b3107441f54a2602ccf2c67c6206998d5Timo Sirainen struct fts_expunge_log *log);
009d6d90b33bc7f64fa8251ac392cc87a835b833Timo Sirainenint lucene_index_optimize(struct lucene_index *index);
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainenint lucene_index_lookup(struct lucene_index *index,
117fb8c00336dc54bab9cfa547249df7a4970611Timo Sirainen struct mail_search_arg *args,
117fb8c00336dc54bab9cfa547249df7a4970611Timo Sirainen enum fts_lookup_flags flags,
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen struct fts_result *result);
be044d4f3d08652d7332cdec5aaf8391474908bbTimo Sirainen
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainenint lucene_index_lookup_multi(struct lucene_index *index,
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen HASH_TABLE_TYPE(wguid_result) guids,
117fb8c00336dc54bab9cfa547249df7a4970611Timo Sirainen struct mail_search_arg *args,
117fb8c00336dc54bab9cfa547249df7a4970611Timo Sirainen enum fts_lookup_flags flags,
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainen struct fts_multi_result *result);
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainenstruct lucene_index_iter *
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainenlucene_index_iter_init(struct lucene_index *index);
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainenconst struct lucene_index_record *
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainenlucene_index_iter_next(struct lucene_index_iter *iter);
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainenint lucene_index_iter_deinit(struct lucene_index_iter **iter);
39ed514f9d401b3cb589595c6a2f532050254d77Timo Sirainen
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen/* internal: */
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainenvoid lucene_utf8_n_to_tchar(const unsigned char *src, size_t srcsize,
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen wchar_t *dest, size_t destsize);
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen
64f30df0bee5218c9a69915e796d9d1376cfbf29Timo Sirainenvoid lucene_shutdown(void);
64f30df0bee5218c9a69915e796d9d1376cfbf29Timo Sirainen
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen#endif