dovecot-1.1: When searching words with only non-indexed characte...

dovecot at dovecot.org dovecot at dovecot.org
Sat Mar 8 03:26:50 EET 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/92c2ab255c65
changeset: 7375:92c2ab255c65
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Mar 08 03:26:47 2008 +0200
description:
When searching words with only non-indexed characters, return all messages
as "maybe".

diffstat:

1 file changed, 29 insertions(+), 24 deletions(-)
src/plugins/fts-squat/squat-trie.c |   53 +++++++++++++++++++-----------------

diffs (92 lines):

diff -r 0bb3fc72a74f -r 92c2ab255c65 src/plugins/fts-squat/squat-trie.c
--- a/src/plugins/fts-squat/squat-trie.c	Sat Mar 08 02:09:40 2008 +0200
+++ b/src/plugins/fts-squat/squat-trie.c	Sat Mar 08 03:26:47 2008 +0200
@@ -1916,24 +1916,11 @@ squat_trie_lookup_real(struct squat_trie
 	unsigned char *data;
 	uint8_t *char_lengths;
 	unsigned int i, start, bytes, str_bytelen, str_charlen;
+	bool searched = FALSE;
 	int ret = 0;
 
 	array_clear(definite_uids);
 	array_clear(maybe_uids);
-
-	str_bytelen = strlen(str);
-	if (str_bytelen == 0) {
-		/* list all root UIDs */
-		i_array_init(&ctx.tmp_uids, 128);
-		ret = squat_uidlist_get_seqrange(trie->uidlist,
-						 trie->root.uid_list_idx,
-						 &ctx.tmp_uids);
-		squat_trie_filter_type(type, &ctx.tmp_uids,
-				       definite_uids);
-		squat_trie_add_unknown(trie, maybe_uids);
-		array_free(&ctx.tmp_uids);
-		return ret;
-	}
 
 	memset(&ctx, 0, sizeof(ctx));
 	ctx.trie = trie;
@@ -1944,7 +1931,8 @@ squat_trie_lookup_real(struct squat_trie
 	i_array_init(&ctx.tmp_uids2, 128);
 	ctx.first = TRUE;
 
-	char_lengths = t_malloc0(str_bytelen);
+	str_bytelen = strlen(str);
+	char_lengths = str_bytelen == 0 ? NULL : t_malloc0(str_bytelen);
 	for (i = 0, str_charlen = 0; i < str_bytelen; str_charlen++) {
 		bytes = uni_utf8_char_bytes(str[i]);
 		char_lengths[i] = bytes;
@@ -1963,19 +1951,12 @@ squat_trie_lookup_real(struct squat_trie
 			ret = squat_trie_lookup_partial(&ctx, data + start,
 							char_lengths,
 							i - start);
+			searched = TRUE;
 		}
 		start = i + char_lengths[i];
 	}
 
-	if (start != 0) {
-		/* string has nonindexed characters. finish the search. */
-		array_clear(definite_uids);
-		if (i != start && ret >= 0) {
-			ret = squat_trie_lookup_partial(&ctx, data + start,
-							char_lengths,
-							i - start);
-		}
-	} else {
+	if (start == 0) {
 		if (str_charlen <= trie->hdr.partial_len ||
 		    trie->hdr.full_len > trie->hdr.partial_len) {
 			ret = squat_trie_lookup_data(trie, data, str_bytelen,
@@ -1997,6 +1978,30 @@ squat_trie_lookup_real(struct squat_trie
 							char_lengths,
 							i - start);
 		}
+	} else if (str_bytelen > 0) {
+		/* string has nonindexed characters. finish the search. */
+		array_clear(definite_uids);
+		if (i != start && ret >= 0) {
+			ret = squat_trie_lookup_partial(&ctx, data + start,
+							char_lengths,
+							i - start);
+		} else if (!searched) {
+			/* string has only nonindexed chars,
+			   list all root UIDs as maybes */
+			ret = squat_uidlist_get_seqrange(trie->uidlist,
+							trie->root.uid_list_idx,
+							&ctx.tmp_uids);
+			squat_trie_filter_type(type, &ctx.tmp_uids,
+					       maybe_uids);
+		}
+	} else {
+		/* zero string length - list all root UIDs as definite
+		   answers */
+		ret = squat_uidlist_get_seqrange(trie->uidlist,
+						 trie->root.uid_list_idx,
+						 &ctx.tmp_uids);
+		squat_trie_filter_type(type, &ctx.tmp_uids,
+				       definite_uids);
 	}
 	squat_trie_add_unknown(trie, maybe_uids);
 	array_free(&ctx.tmp_uids);


More information about the dovecot-cvs mailing list