summaryrefslogtreecommitdiffstats
path: root/src/plugins/fts-lucene/doveadm-fts-lucene.c
blob: a761907009fddc332e5d94bf3c99b0b84678d990 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Copyright (c) 2011-2018 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "doveadm-dump.h"
#include "doveadm-fts.h"
#include "lucene-wrapper.h"

#include <stdio.h>
#include <sys/stat.h>

const char *doveadm_fts_lucene_plugin_version = DOVECOT_ABI_VERSION;

void doveadm_fts_lucene_plugin_init(struct module *module);
void doveadm_fts_lucene_plugin_deinit(void);

static void
cmd_dump_fts_lucene(const char *path, const char *const *args ATTR_UNUSED)
{
	struct lucene_index *index;
	struct lucene_index_iter *iter;
	guid_128_t prev_guid;
	const struct lucene_index_record *rec;
	bool first = TRUE;

	i_zero(&prev_guid);
	index = lucene_index_init(path, NULL, NULL);
	iter = lucene_index_iter_init(index);
	while ((rec = lucene_index_iter_next(iter)) != NULL) {
		if (memcmp(prev_guid, rec->mailbox_guid,
			   sizeof(prev_guid)) != 0) {
			if (first)
				first = FALSE;
			else
				printf("\n");
			memcpy(prev_guid, rec->mailbox_guid, sizeof(prev_guid));
			printf("%s: ", guid_128_to_string(prev_guid));
		}
		printf("%u", rec->uid);
		if (rec->part_num != 0)
			printf("[%u]", rec->part_num);
		printf("\n");
	}
	printf("\n");
	if (lucene_index_iter_deinit(&iter) < 0)
		i_error("Lucene index iteration failed");
	lucene_index_deinit(index);
}

static bool test_dump_fts_lucene(const char *path)
{
	struct stat st;

	path = t_strconcat(path, "/segments.gen", NULL);
	return stat(path, &st) == 0;
}

static const struct doveadm_cmd_dump doveadm_cmd_dump_fts_lucene = {
	"fts-lucene",
	test_dump_fts_lucene,
	cmd_dump_fts_lucene
};

void doveadm_fts_lucene_plugin_init(struct module *module ATTR_UNUSED)
{
	doveadm_dump_register(&doveadm_cmd_dump_fts_lucene);
}

void doveadm_fts_lucene_plugin_deinit(void)
{
}