/* Copyright (c) 2006-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "hash.h"
#include "hex-binary.h"
#include "strescape.h"
#include "message-part.h"
#include "mail-namespace.h"
#include "mail-storage-private.h"
#include "fts-expunge-log.h"
#include "lucene-wrapper.h"
#include "fts-indexer.h"
#include "fts-lucene-plugin.h"
#include <wchar.h>
struct lucene_fts_backend {
char *dir_path;
unsigned int selected_box_generation;
};
struct lucene_fts_backend_update_context {
char *first_box_vname;
char *hdr_name;
unsigned int added_msgs;
bool lucene_opened;
bool last_indexed_uid_set;
bool mime_parts;
};
{
if (backend->dir_created)
return 0;
return -1;
return 0;
}
static int
{
&metadata) < 0) {
i_error("lucene: Couldn't get mailbox %s GUID: %s",
return -1;
}
return 0;
}
static int
{
unsigned int i;
return 0;
return -1;
for (i = 0; i < N_ELEMENTS(wguid_hex); i++)
sizeof(backend->selected_box_guid));
return 0;
}
{
}
static int
{
(struct lucene_fts_backend *)_backend;
const char *path;
/* invalid settings */
*error_r = "Invalid fts_lucene settings";
return -1;
}
/* fts already checked that index exists */
/* change our flags so we get proper input */
}
return 0;
}
{
(struct lucene_fts_backend *)_backend;
}
static int
{
(struct lucene_fts_backend *)_backend;
int ret;
if (ret < 0)
return -1;
if (ret == 0) {
/* need to rebuild the index */
*last_uid_r = 0;
} else {
}
return 0;
}
/* either nothing has been indexed, or the index was corrupted.
do it the slow way. */
return -1;
return -1;
return 0;
}
static struct fts_backend_update_context *
{
(struct lucene_fts_backend *)_backend;
}
static bool
{
unsigned int expunges;
return TRUE;
return FALSE;
return FALSE;
return expunges > 0 &&
}
static int
{
(struct lucene_fts_backend_update_context *)_ctx;
if (ctx->lucene_opened) {
ret = -1;
}
ret = -1;
/* lucene-indexes directory doesn't even exist,
so dovecot.index's last_index_uid is wrong.
rescan to update them. */
ret = 0;
}
}
}
if (fts_backend_lucene_need_optimize(ctx)) {
if (ctx->lucene_opened)
int fd;
/* the optimize affects all mailboxes within namespace,
so just use any mailbox name in it */
i_close_fd(&fd);
}
}
return ret;
}
static void
{
(struct lucene_fts_backend_update_context *)_ctx;
}
}
static void
{
(struct lucene_fts_backend_update_context *)_ctx;
if (!ctx->last_indexed_uid_set) {
ctx->last_indexed_uid = 0;
else
}
if (ctx->last_indexed_uid == 0 ||
/* don't waste time adding expunge to log for a message that
isn't even indexed. this check is racy, because indexer may
just be in the middle of indexing this message. we'll
attempt to avoid that by skipping the expunging only if
indexing hasn't been done for a while (100 msgs). */
return;
}
ctx->expunge_ctx =
}
}
static bool
const struct fts_backend_build_key *key)
{
(struct lucene_fts_backend_update_context *)_ctx;
if (!ctx->lucene_opened) {
if (fts_backend_lucene_mkdir(backend) < 0)
}
break;
break;
i_unreached();
}
ctx->added_msgs++;
}
if (ctx->mime_parts)
return TRUE;
}
static void
{
(struct lucene_fts_backend_update_context *)_ctx;
}
static int
{
(struct lucene_fts_backend_update_context *)_ctx;
int ret;
return -1;
T_BEGIN {
} T_END;
return ret;
}
static int
{
(struct lucene_fts_backend *)_backend;
return 0;
}
{
(struct lucene_fts_backend *)_backend;
return -1;
}
{
(struct lucene_fts_backend *)_backend;
int ret;
if (ret == 0) {
/* log was corrupted, need to rescan */
}
if (ret >= 0)
return ret;
}
static int
struct mail_search_arg *args,
enum fts_lookup_flags flags,
struct fts_result *result)
{
(struct lucene_fts_backend *)_backend;
int ret;
return -1;
T_BEGIN {
} T_END;
return ret;
}
/* a char* hash function from ASU -- from glib */
{
unsigned int g, h = 0;
while (*s != '\0') {
h = (h << 4) + *s;
if ((g = h & 0xf0000000UL) != 0) {
h = h ^ (g >> 24);
h = h ^ g;
}
s++;
}
return h;
}
static int
struct fts_multi_result *result)
{
const char *guid;
unsigned int i, j;
/* first create the box_results - we'll be using pointers to them
later on and appending to the array changes the pointers */
}
return -1;
for (j = 0; j < MAILBOX_GUID_HEX_LENGTH; j++)
}
return 0;
}
static int
struct mail_search_arg *args,
enum fts_lookup_flags flags,
struct fts_multi_result *result)
{
(struct lucene_fts_backend *)_backend;
int ret;
T_BEGIN {
if (ret == 0) {
result);
}
} T_END;
return ret;
}
{
/* the next refresh is going to close the index anyway, so we might as
well do it now */
(void)fts_backend_lucene_refresh(_backend);
}
.name = "lucene",
{
}
};