[evolution-exchange] Bug #260407 - 'endswith' address book search doesn't work



commit 9ddae70075cb38e8d9813f9a8fb9fb290acd7eb9
Author: Milan Crha <mcrha redhat com>
Date:   Mon Oct 19 17:50:59 2009 +0200

    Bug #260407 - 'endswith' address book search doesn't work

 addressbook/e-book-backend-exchange.c |   30 ++++++++++++++++++++++++++++--
 server/lib/e2k-restriction.c          |    8 ++------
 2 files changed, 30 insertions(+), 8 deletions(-)
---
diff --git a/addressbook/e-book-backend-exchange.c b/addressbook/e-book-backend-exchange.c
index b6ab7e9..c442b9c 100644
--- a/addressbook/e-book-backend-exchange.c
+++ b/addressbook/e-book-backend-exchange.c
@@ -2016,7 +2016,7 @@ func_match (struct _ESExp *f, gint argc, struct _ESExpResult **argv, gpointer da
 
 		rn = e2k_restriction_or (rns->len, (E2kRestriction **)rns->pdata, TRUE);
 		g_ptr_array_free (rns, TRUE);
-	} else if (!strcmp (propname, "full_name") && flags == E2K_FL_PREFIX) {
+	} else if (!strcmp (propname, "full_name")) {
 		if (!*str) {
 			rn = e2k_restriction_orv (
 				e2k_restriction_exist (
@@ -2207,6 +2207,7 @@ e_book_backend_exchange_get_contact_list (EBookBackendSync  *backend,
 	E2kHTTPStatus status;
 	gchar *vcard;
 	GList *vcard_list = NULL, *temp, *offline_contacts;
+	EBookBackendSExp *sexp = NULL;
 
 	d(printf("ebbe_get_contact_list(%p, %p, %s)\n", backend, book, query));
 
@@ -2246,15 +2247,38 @@ e_book_backend_exchange_get_contact_list (EBookBackendSync  *backend,
 
 		e2k_restriction_unref (rn);
 
+		if (query)
+			sexp = e_book_backend_sexp_new (query);
+
 		*contacts = NULL;
 		while ((result = e2k_result_iter_next (iter))) {
-			vcard = vcard_from_props (be, result);
+			if (sexp) {
+				EContact *contact;
+
+				vcard = NULL;
+				contact = e_contact_from_props (be, result);
+				if (contact) {
+					/* there is no suffix restriction, thus it's done by contains,
+					   thus check for contact validity against the query is required */
+					if (e_book_backend_sexp_match_contact (sexp, contact))
+						vcard = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
+
+					g_object_unref (contact);
+				}
+			} else {
+				vcard = vcard_from_props (be, result);
+			}
+
 			if (!vcard)
 				continue;
+
 			*contacts = g_list_prepend (*contacts, vcard);
 		}
 		status = e2k_result_iter_free (iter);
 
+		if (sexp)
+			g_object_unref (sexp);
+
 		return http_status_to_pas (status);
 
 	default:
@@ -2347,6 +2371,8 @@ e_book_backend_exchange_start_book_view (EBookBackend  *backend,
 		while ((result = e2k_result_iter_next (iter))) {
 			contact = e_contact_from_props (be, result);
 			if (contact) {
+				/* the function itself checks for validity of the contact against the query,
+				   thus no need to do it here too (because of no suffix restriction) */
 				e_data_book_view_notify_update (book_view,
 								contact);
 				g_object_unref (contact);
diff --git a/server/lib/e2k-restriction.c b/server/lib/e2k-restriction.c
index f8a6c67..41b3ff1 100644
--- a/server/lib/e2k-restriction.c
+++ b/server/lib/e2k-restriction.c
@@ -614,6 +614,8 @@ rn_to_sql (E2kRestriction *rn, GString *sql, E2kRestrictionType inside)
 		g_string_append_printf (sql, "\"%s\" ", pv->prop.name);
 
 		switch (E2K_FL_MATCH_TYPE (rn->res.content.fuzzy_level)) {
+		case E2K_FL_SUFFIX:
+			/* make suffix same as substring; it'll be checked for suffixes only later */
 		case E2K_FL_SUBSTRING:
 			g_string_append (sql, "LIKE '%");
 			append_sql_quoted (sql, pv->value);
@@ -626,12 +628,6 @@ rn_to_sql (E2kRestriction *rn, GString *sql, E2kRestrictionType inside)
 			g_string_append (sql, "%'");
 			break;
 
-		case E2K_FL_SUFFIX:
-			g_string_append (sql, "LIKE '%");
-			append_sql_quoted (sql, pv->value);
-			g_string_append_c (sql, '\'');
-			break;
-
 		case E2K_FL_FULLSTRING:
 		default:
 			g_string_append (sql, "= '");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]