dovecot-1.2: fts-solr: Fixes with virtual mailboxes.

dovecot at dovecot.org dovecot at dovecot.org
Tue Apr 14 23:51:42 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/43b68bd6023a
changeset: 8945:43b68bd6023a
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Apr 14 16:51:36 2009 -0400
description:
fts-solr: Fixes with virtual mailboxes.

diffstat:

1 file changed, 21 insertions(+), 16 deletions(-)
src/plugins/fts-solr/fts-backend-solr.c |   37 +++++++++++++++++--------------

diffs (85 lines):

diff -r 1143c696126a -r 43b68bd6023a src/plugins/fts-solr/fts-backend-solr.c
--- a/src/plugins/fts-solr/fts-backend-solr.c	Mon Apr 13 19:20:42 2009 -0400
+++ b/src/plugins/fts-solr/fts-backend-solr.c	Tue Apr 14 16:51:36 2009 -0400
@@ -185,17 +185,23 @@ static void fts_backend_solr_deinit(stru
 
 static void
 solr_add_ns_query(string_t *str, struct fts_backend *_backend,
-		  struct mail_namespace *ns)
+		  struct mail_namespace *ns, bool neg)
 {
 	struct solr_fts_backend *backend = (struct solr_fts_backend *)_backend;
 
 	while (ns->alias_for != NULL)
 		ns = ns->alias_for;
 
-	if (ns == backend->default_ns || *ns->prefix == '\0')
-		str_append(str, " -ns:[* TO *]");
-	else {
-		str_append(str, " %2Bns:");
+	if (ns == backend->default_ns || *ns->prefix == '\0') {
+		if (!neg)
+			str_append(str, " -ns:[* TO *]");
+		else
+			str_append(str, " +ns:[* TO *]");
+	} else {
+		if (!neg)
+			str_append(str, " +ns:");
+		else
+			str_append(str, " -ns:");
 		solr_quote(str, ns->prefix);
 	}
 }
@@ -207,7 +213,7 @@ solr_add_ns_query_http(string_t *str, st
 	string_t *tmp;
 
 	tmp = t_str_new(64);
-	solr_add_ns_query(tmp, backend, ns);
+	solr_add_ns_query(tmp, backend, ns, FALSE);
 	solr_connection_http_escape(solr_conn, str, str_c(tmp));
 }
 
@@ -331,6 +337,11 @@ solr_add_pattern(string_t *str, const st
 	if (!mail_namespace_update_name(pattern->ns, &name))
 		name = mail_namespace_fix_sep(pattern->ns, name);
 
+	if (strcmp(name, "*") == 0) {
+		str_append(str, "[* TO *]");
+		return;
+	}
+
 	/* first check if there are any wildcards in the pattern */
 	for (p = name; *p != '\0'; p++) {
 		if (*p == '%' || *p == '*')
@@ -392,7 +403,7 @@ fts_backend_solr_filter_mailboxes(struct
 			str_append_c(fq, '(');
 			str_append(fq, "+box:");
 			solr_add_pattern(fq, &includes[i]);
-			solr_add_ns_query(fq, _backend, includes[i].ns);
+			solr_add_ns_query(fq, _backend, includes[i].ns, FALSE);
 			str_append_c(fq, ')');
 		}
 		str_append_c(fq, ')');
@@ -401,19 +412,13 @@ fts_backend_solr_filter_mailboxes(struct
 	for (i = 0; i < exc_count; i++) {
 		if (str_len(fq) > 0)
 			str_append_c(fq, ' ');
-		str_append_c(fq, '(');
-		str_append(fq, "-box:");
+		str_append(fq, "NOT (");
+		str_append(fq, "box:");
 		solr_add_pattern(fq, &excludes[i]);
 
 		for (ns = excludes[i].ns; ns->alias_for != NULL; )
 			ns = ns->alias_for;
-		if (ns == backend->default_ns) {
-			str_append(fq, " OR NOT");
-			solr_add_ns_query(fq, _backend, ns);
-		} else if (*ns->prefix != '\0') {
-			str_append(fq, " OR -ns:");
-			solr_quote(fq, ns->prefix);
-		}
+		solr_add_ns_query(fq, _backend, ns, FALSE);
 		str_append_c(fq, ')');
 	}
 	if (str_len(fq) > 0) {


More information about the dovecot-cvs mailing list