evolution-data-server r9044 - in branches/camel-db-summary: camel libedataserver



Author: psankar
Date: Wed Jun 25 15:12:06 2008
New Revision: 9044
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9044&view=rev

Log:
Search more conditions like:

BEGINS With
Ends with
Contains



Modified:
   branches/camel-db-summary/camel/camel-db.c
   branches/camel-db-summary/camel/camel-folder-search.c
   branches/camel-db-summary/libedataserver/e-sexp.c
   branches/camel-db-summary/libedataserver/e-sexp.h

Modified: branches/camel-db-summary/camel/camel-db.c
==============================================================================
--- branches/camel-db-summary/camel/camel-db.c	(original)
+++ branches/camel-db-summary/camel/camel-db.c	Wed Jun 25 15:12:06 2008
@@ -731,9 +731,9 @@
 
 char * camel_db_get_column_name (const char *raw_name)
 {
-	if (g_ascii_strcasecmp (raw_name, "Subject"))
+	if (!g_ascii_strcasecmp (raw_name, "Subject"))
 		return g_strdup ("subject");
-	else if (g_ascii_strcasecmp (raw_name, "from"))
+	else if (!g_ascii_strcasecmp (raw_name, "from"))
 		return g_strdup ("mail_from");
 	else {
 		/* Let it crash for all unknown columns for now. 

Modified: branches/camel-db-summary/camel/camel-folder-search.c
==============================================================================
--- branches/camel-db-summary/camel/camel-folder-search.c	(original)
+++ branches/camel-db-summary/camel/camel-folder-search.c	Wed Jun 25 15:12:06 2008
@@ -67,7 +67,7 @@
 static ESExpResult *search_not(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search);
 
 static ESExpResult *search_header_contains(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search);
-static ESExpResult * db_search_header_contains(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search);
+static ESExpResult *db_search_header_contains(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search);
 static ESExpResult *search_header_matches(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search);
 static ESExpResult *search_header_starts_with(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search);
 static ESExpResult *search_header_ends_with(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search);
@@ -305,8 +305,6 @@
 void
 camel_folder_search_set_summary(CamelFolderSearch *search, GPtrArray *summary)
 {
-	int i;
-
 	search->summary = summary;
 }
 
@@ -452,8 +450,7 @@
 	ESExpResult *r;
 	GPtrArray *matches = NULL, *summary_set;
 	int i;
-	GHashTable *results;
-	EMemPool *pool;
+	CamelDB *cdb;
 	struct _CamelFolderSearchPrivate *p = _PRIVATE(search);
 
 	g_assert(search->folder);
@@ -496,48 +493,14 @@
 		goto fail;
 	}
 
+	d(printf ("\nsexp is : [%s]\n", expr));
 	printf ("\nSomething is returned in the top-level caller : [%s]\n", search->query->str);
 
 	matches = g_ptr_array_new();
-
-	CamelStore *store = search->folder->parent_store;
-//	CamelDB *cdb = (CamelDB *) (search->folder->parent_store->cdb);
-	CamelDB *cdb = store->cdb;
-
+	cdb = (CamelDB *) (search->folder->parent_store->cdb);
 	camel_db_select (cdb, search->query->str, (CamelDBSelectCB) read_uid_callback, matches, ex);
-
-	/* now create a folder summary to return?? */
-	if (r->type == ESEXP_RES_ARRAY_PTR) {
-		d(printf("got result ...\n"));
-
-		/* we use a mempool to store the strings, packed in tight as possible, and freed together */
-		/* because the strings are often short (like <8 bytes long), we would be wasting appx 50%
-		   of memory just storing the size tag that malloc assigns us and alignment padding, so this
-		   gets around that (and is faster to allocate and free as a bonus) */
-		pool = e_mempool_new(512, 256, E_MEMPOOL_ALIGN_BYTE);
-		/* reorder result in summary order */
-		results = g_hash_table_new(g_str_hash, g_str_equal);
-		for (i=0;i<r->value.ptrarray->len;i++) {
-			d(printf("adding match: %s\n", (char *)g_ptr_array_index(r->value.ptrarray, i)));
-			g_hash_table_insert(results, g_ptr_array_index(r->value.ptrarray, i), GINT_TO_POINTER (1));
-		}
-
-		for (i=0;i<summary_set->len;i++) {
-			char *uid  = g_ptr_array_index(summary_set, i);
-			if (g_hash_table_lookup(results, uid))
-				g_ptr_array_add(matches, e_mempool_strdup(pool, uid));
-		}
-		g_hash_table_destroy(results);
-
-		/* instead of putting the mempool_hash in the structure, we keep the api clean by
-		   putting a reference to it in a hashtable.  Lets us do some debugging and catch
-		   unfree'd results as well. */
-		g_hash_table_insert(p->mempool_hash, matches, pool);
-	} else {
-		g_warning("Search returned an invalid result type");
-	}
-
 	e_sexp_result_free(search->sexp, r);
+
 fail:
 	/* these might be allocated by match-threads */
 	if (p->threads)
@@ -662,9 +625,7 @@
 static ESExpResult *
 search_match_all(struct _ESExp *f, int argc, struct _ESExpTerm **argv, CamelFolderSearch *search)
 {
-	int i;
 	ESExpResult *r, *r1;
-	GPtrArray *v;
 	gchar *error_msg;
 
 	if (argc>1) {
@@ -856,7 +817,7 @@
 }
 
 static ESExpResult *
-check_header(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search, camel_search_match_t how)
+check_header_deprecated (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search, camel_search_match_t how)
 {
 	ESExpResult *r;
 	int truth = FALSE;
@@ -929,31 +890,50 @@
 }
 
 static ESExpResult *
-search_header_contains(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search)
-{
-	return check_header(f, argc, argv, search, CAMEL_SEARCH_MATCH_CONTAINS);
-}
-
-static ESExpResult *
-db_search_header_contains(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search)
+check_header (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search, camel_search_match_t how)
 {
 	/* FIXME: What to do for headers that are not stored in db */
 
 	ESExpResult *r;
 
-	char *column = camel_db_get_column_name (argv [0]->value.string);
+	if (strlen (argv [1]->value.string) > 1) {
 
-	char *temp = g_strdup_printf ("%%%s%%", argv [1]->value.string);
-	char *value = camel_db_sqlize_string (temp);
-	g_free (temp);
-
-	if (g_str_has_suffix (search->query->str, " "))
-		g_string_append_printf (search->query, "WHERE %s LIKE %s", column, value);
-	else 
-		g_string_append_printf (search->query, " OR %s LIKE %s", column, value);
+		char *value;
+		char *temp;
+		char *column;
+
+		column = camel_db_get_column_name (argv [0]->value.string);
+
+		switch (how) {
+			case CAMEL_SEARCH_MATCH_EXACT:
+				temp = g_strdup_printf ("%s", argv [1]->value.string);
+				break;
+			case CAMEL_SEARCH_MATCH_CONTAINS:
+				temp = g_strdup_printf ("%%%s%%", argv [1]->value.string);
+				break;
+			case CAMEL_SEARCH_MATCH_STARTS:
+				temp = g_strdup_printf ("%s%%", argv [1]->value.string);
+				break;
+			case CAMEL_SEARCH_MATCH_ENDS:
+				temp = g_strdup_printf ("%%%s", argv [1]->value.string);
+				break;
+		}
 
-	g_free (column);
-	camel_db_free_sqlized_string (value);
+		value = camel_db_sqlize_string (temp);
+		g_free (temp);
+
+		if (g_str_has_suffix (search->query->str, " "))
+			g_string_append_printf (search->query, "WHERE %s LIKE %s", column, value);
+		else {
+			if (f->operators)
+				g_string_append_printf (search->query, " %s %s LIKE %s", (char *) (g_slist_nth_data (f->operators, 0)), column, value);
+			else
+				g_string_append_printf (search->query, " OR %s LIKE %s", column, value);
+		}
+
+		g_free (column);
+		camel_db_free_sqlized_string (value);
+	}
 
 	r = e_sexp_result_new(f, ESEXP_RES_BOOL);
 	r->value.bool = FALSE;
@@ -962,6 +942,18 @@
 }
 
 static ESExpResult *
+search_header_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search)
+{
+	return check_header(f, argc, argv, search, CAMEL_SEARCH_MATCH_CONTAINS);
+}
+
+static ESExpResult *
+db_search_header_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search)
+{
+	return check_header (f, argc, argv, search, CAMEL_SEARCH_MATCH_CONTAINS);
+}
+
+static ESExpResult *
 search_header_matches(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search)
 {
 	return check_header(f, argc, argv, search, CAMEL_SEARCH_MATCH_EXACT);
@@ -1065,7 +1057,6 @@
 	struct _glib_sux_donkeys lambdafoo;
 	CamelIndexCursor *wc, *nc;
 	const char *word, *name;
-	CamelMessageInfo *mi;
 	int i;
 
 	/* we can have a maximum of 32 words, as we use it as the AND mask */

Modified: branches/camel-db-summary/libedataserver/e-sexp.c
==============================================================================
--- branches/camel-db-summary/libedataserver/e-sexp.c	(original)
+++ branches/camel-db-summary/libedataserver/e-sexp.c	Wed Jun 25 15:12:06 2008
@@ -251,6 +251,9 @@
 
 	r = e_sexp_result_new(f, ESEXP_RES_UNDEFINED);
 
+	char *oper = "AND";
+	f->operators = g_slist_prepend (f->operators, oper);
+
 	for (i=0;bool && i<argc;i++) {
 		r1 = e_sexp_term_eval(f, argv[i]);
 		if (type == -1)
@@ -291,6 +294,7 @@
 	}
 
 	g_hash_table_destroy(ht);
+	f->operators = g_slist_remove (f->operators, oper);
 
 	return r;
 }
@@ -307,6 +311,9 @@
 
 	r(printf("(or \n"));
 
+	char *oper = "OR";
+	f->operators = g_slist_prepend (f->operators, oper);
+
 	r = e_sexp_result_new(f, ESEXP_RES_UNDEFINED);
 
 	for (i=0;!bool && i<argc;i++) {
@@ -345,6 +352,7 @@
 	}
 	g_hash_table_destroy(ht);
 
+	f->operators = g_slist_remove (f->operators, oper);
 	return r;
 }
 
@@ -887,6 +895,12 @@
 	return terms;
 }
 
+ESExpTerm * e_sexp_parse_value (ESExp *f) 
+{
+	return parse_value (f);
+}
+
+
 static struct _ESExpTerm *
 parse_value(ESExp *f)
 {

Modified: branches/camel-db-summary/libedataserver/e-sexp.h
==============================================================================
--- branches/camel-db-summary/libedataserver/e-sexp.h	(original)
+++ branches/camel-db-summary/libedataserver/e-sexp.h	Wed Jun 25 15:12:06 2008
@@ -117,6 +117,7 @@
 	/* private stuff */
 	jmp_buf failenv;
 	char *error;
+	GSList *operators;
 
 	/* TODO: may also need a pool allocator for term strings, so we dont lose them
 	   in error conditions? */
@@ -173,6 +174,8 @@
 /* return the error string */
 const char     *e_sexp_error		(struct _ESExp *f);
 
+ESExpTerm * e_sexp_parse_value(ESExp *f);
+
 G_END_DECLS
 
 #endif /* _E_SEXP_H */



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