changeset 7429:477b619b926b HEAD

Added FTS_SQUAT environment with partial=n and full=m settings.
author Timo Sirainen <tss@iki.fi>
date Thu, 20 Mar 2008 15:34:44 +0200
parents d6f1eb00e4d3
children 2b89ceb0f6af
files src/plugins/fts-squat/fts-backend-squat.c src/plugins/fts-squat/squat-trie-private.h src/plugins/fts-squat/squat-trie.c src/plugins/fts-squat/squat-trie.h
diffstat 4 files changed, 53 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/fts-squat/fts-backend-squat.c	Thu Mar 20 15:09:30 2008 +0200
+++ b/src/plugins/fts-squat/fts-backend-squat.c	Thu Mar 20 15:34:44 2008 +0200
@@ -7,6 +7,8 @@
 #include "squat-trie.h"
 #include "fts-squat-plugin.h"
 
+#include <stdlib.h>
+
 #define SQUAT_FILE_PREFIX "dovecot.index.search"
 
 struct squat_fts_backend {
@@ -19,12 +21,39 @@
 	struct squat_trie_build_context *build_ctx;
 };
 
+static void
+fts_backend_squat_set(struct squat_fts_backend *backend, const char *str)
+{
+	const char *const *tmp;
+	int len;
+
+	for (tmp = t_strsplit_spaces(str, " "); *tmp != NULL; tmp++) {
+		if (strncmp(*tmp, "partial=", 8) == 0) {
+			len = atoi(*tmp + 8);
+			if (len <= 0) {
+				i_fatal("fts_squat: Invalid partial len: %s",
+					*tmp + 8);
+			}
+			squat_trie_set_partial_len(backend->trie, len);
+		} else if (strncmp(*tmp, "full=", 5) == 0) {
+			len = atoi(*tmp + 5);
+			if (len <= 0) {
+				i_fatal("fts_squat: Invalid full len: %s",
+					*tmp + 5);
+			}
+			squat_trie_set_full_len(backend->trie, len);
+		} else {
+			i_fatal("fts_squat: Invalid setting: %s", *tmp);
+		}
+	}
+}
+
 static struct fts_backend *fts_backend_squat_init(struct mailbox *box)
 {
 	struct squat_fts_backend *backend;
 	struct mail_storage *storage;
 	struct mailbox_status status;
-	const char *path;
+	const char *path, *env;
 	enum squat_index_flags flags = 0;
 
 	storage = mailbox_get_storage(box);
@@ -50,6 +79,10 @@
 		squat_trie_init(t_strconcat(path, "/"SQUAT_FILE_PREFIX, NULL),
 				status.uidvalidity, storage->lock_method,
 				flags);
+
+	env = getenv("FTS_SQUAT");
+	if (env != NULL)
+		fts_backend_squat_set(backend, env);
 	return &backend->backend;
 }
 
--- a/src/plugins/fts-squat/squat-trie-private.h	Thu Mar 20 15:09:30 2008 +0200
+++ b/src/plugins/fts-squat/squat-trie-private.h	Thu Mar 20 15:34:44 2008 +0200
@@ -133,6 +133,8 @@
 	size_t mmap_size;
 
 	unsigned char default_normalize_map[256];
+	unsigned int default_partial_len;
+	unsigned int default_full_len;
 
 	unsigned int corrupted:1;
 };
--- a/src/plugins/fts-squat/squat-trie.c	Thu Mar 20 15:09:30 2008 +0200
+++ b/src/plugins/fts-squat/squat-trie.c	Thu Mar 20 15:34:44 2008 +0200
@@ -145,6 +145,8 @@
 	trie->dotlock_set.nfs_flush = (flags & SQUAT_INDEX_FLAG_NFS_FLUSH) != 0;
 	trie->dotlock_set.timeout = SQUAT_TRIE_LOCK_TIMEOUT;
 	trie->dotlock_set.stale_timeout = SQUAT_TRIE_DOTLOCK_STALE_TIMEOUT;
+	trie->default_partial_len = DEFAULT_PARTIAL_LEN;
+	trie->default_full_len = DEFAULT_FULL_LEN;
 	return trie;
 }
 
@@ -190,14 +192,24 @@
 	i_free(trie);
 }
 
+void squat_trie_set_partial_len(struct squat_trie *trie, unsigned int len)
+{
+	trie->default_partial_len = len;
+}
+
+void squat_trie_set_full_len(struct squat_trie *trie, unsigned int len)
+{
+	trie->default_full_len = len;
+}
+
 static void squat_trie_header_init(struct squat_trie *trie)
 {
 	memset(&trie->hdr, 0, sizeof(trie->hdr));
 	trie->hdr.version = SQUAT_TRIE_VERSION;
 	trie->hdr.indexid = time(NULL);
 	trie->hdr.uidvalidity = trie->uidvalidity;
-	trie->hdr.partial_len = DEFAULT_PARTIAL_LEN;
-	trie->hdr.full_len = DEFAULT_FULL_LEN;
+	trie->hdr.partial_len = trie->default_partial_len;
+	trie->hdr.full_len = trie->default_full_len;
 
 	i_assert(sizeof(trie->hdr.normalize_map) ==
 		 sizeof(trie->default_normalize_map));
--- a/src/plugins/fts-squat/squat-trie.h	Thu Mar 20 15:09:30 2008 +0200
+++ b/src/plugins/fts-squat/squat-trie.h	Thu Mar 20 15:34:44 2008 +0200
@@ -23,6 +23,9 @@
 		enum squat_index_flags flags);
 void squat_trie_deinit(struct squat_trie **trie);
 
+void squat_trie_set_partial_len(struct squat_trie *trie, unsigned int len);
+void squat_trie_set_full_len(struct squat_trie *trie, unsigned int len);
+
 void squat_trie_refresh(struct squat_trie *trie);
 
 int squat_trie_build_init(struct squat_trie *trie, uint32_t *last_uid_r,