[Kazehakase-cvs] CVS update: kazehakase/module/search

Back to archive index

Hiroyuki Ikezoe ikezo****@users*****
Mon Dec 4 11:19:18 JST 2006


Index: kazehakase/module/search/kz-search-hyper-estraier.c
diff -u kazehakase/module/search/kz-search-hyper-estraier.c:1.5 kazehakase/module/search/kz-search-hyper-estraier.c:1.6
--- kazehakase/module/search/kz-search-hyper-estraier.c:1.5	Sun Dec  3 19:59:07 2006
+++ kazehakase/module/search/kz-search-hyper-estraier.c	Mon Dec  4 11:19:18 2006
@@ -33,6 +33,7 @@
 #define HYPER_ESTRAIERRAIER_URI "http://hyperestraier.sourceforge.net/"
 #define DTD   "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"
 #define HEAD  "<head>\n" \
+	      "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" \
 	      "  <title>Full-text search in history</title>\n" \
 	      "  <link rel=\"stylesheet\" type=\"text/css\" href=\"history-search:?css=search-result.css\">\n" \
 	      "</head>\n"
@@ -49,7 +50,7 @@
 		"  </div>\n" \
 		"</div>\n"
 #define FOOTER  "<div class=\"footer\">\n" \
-	        "Powered by <a href=\"%s\">Hyper HyperEstraierraier</a> version %s\n" \
+	        "Powered by <a href=\"%s\">Hyper Estraier</a> version %s\n" \
 		"</div>\n"
 
 typedef struct _KzSearchHyperEstraierPrivate	KzSearchHyperEstraierPrivate;
@@ -88,7 +89,12 @@
 /* KzSearch Class */
 static gchar	  *get_search_result_html     (KzSearch *search, const gchar *text);
 static KzBookmark *get_search_result_bookmark (KzSearch *search, const gchar *text);
-static gboolean    register_document          (KzSearch *search, const gchar *uri, const gchar *title, GTime mtime);
+static gboolean    register_document          (KzSearch *search,
+					       const gchar *uri,
+					       const gchar *encoding,
+					       const gchar *title,
+					       const gchar *contents,
+					       GTime mtime);
 static gboolean    unregister_document        (KzSearch *search, const gchar *uri);
 static gboolean    update_index		      (KzSearch *search);
 static gboolean    purge_index		      (KzSearch *search);
@@ -96,8 +102,6 @@
 static void        make_index                 (KzSearch *search);
 static gboolean    exist_index_dir            (KzSearch *search);
 
-static gboolean _update_index (gpointer data);
-
 static KzSearchHyperEstraier *the_kz_search_hyper_estraier = NULL;
 
 static GObjectClass *parent_class;
@@ -357,71 +361,59 @@
 	return create_search_result_html(text);
 }
 
-static gboolean
-_update_index (gpointer data)
+gboolean
+register_document (KzSearch *search, const gchar *uri, const gchar *encoding, const gchar *title, const gchar *contents, GTime mtime)
 {
-	const gchar *estindex_prefix = "estcmd gather -sd -cm ";
-	gchar *index_dir;
-	gchar *command;
+	ESTDB *db;
+	ESTDOC *doc;
+	int ret, ecode, success;
+	gchar *dbname, *time_str;
 	gchar *filename;
-	gint in;
-	gint argc;
-	gchar **argv = NULL;
-	GSpawnFlags flags;
-	GPid pid;
-	GIOChannel *io;
 
-	index_dir = g_strconcat(g_get_home_dir(), HISTORY_INDEX, NULL);
+	dbname = g_strdup_printf("%s%s", g_get_home_dir(), HISTORY_INDEX);
+	db = est_db_open(dbname, ESTDBWRITER | ESTDBCREAT, &ecode);
+	g_free(dbname);
+	if (!db)
+	{
+		g_warning("db open error: %s", est_err_msg(ecode));
+		return FALSE;
+	}
 
-	command = g_strconcat(estindex_prefix,
-			      index_dir,
-			      " - ",	/* read filename from stdin */
-			      NULL);
-	g_free(index_dir);
+	doc = est_doc_new();
 
-	g_shell_parse_argv(command,
-			   &argc,
-			   &argv,
-			   NULL);
+	filename = g_strdup_printf("file://%s", uri);
+	est_doc_add_attr(doc, ESTDATTRURI, filename);
+	g_free(filename);
 
-	flags = G_SPAWN_SEARCH_PATH |
-		G_SPAWN_STDOUT_TO_DEV_NULL;
-	g_spawn_async_with_pipes(NULL,
-		      		 argv,
-				 NULL,
-		   		 flags,
-		      		 NULL,
-		      		 NULL,
-		      		 &pid,
-				 &in,
-				 NULL,
-				 NULL,
-		      		 NULL);
-	g_strfreev(argv);
-	g_free(command);
+	est_doc_add_attr(doc, ESTDATTRTITLE, title);
 
-	/* set filename to add index */
-	filename = g_strconcat((gchar*)data, "\n", NULL); 	
-	io = g_io_channel_unix_new(in);
-	g_io_channel_set_encoding(io, NULL, NULL);
-	g_io_channel_write_chars(io, filename, strlen(filename), NULL, NULL);
-	g_io_channel_shutdown(io, TRUE, NULL);
-	g_io_channel_unref(io);
+	time_str = cbdatestrwww(mtime, 0);
+	est_doc_add_attr(doc, ESTDATTRMDATE, time_str);
+	g_free(time_str);
 
-	g_free(filename);
-	g_free(data);
-	
-	return FALSE;
-}
+	if (contents)
+	{
+		gchar *raw_text;
+		raw_text = remove_tag(contents, strlen(contents));
+		est_doc_add_text(doc, raw_text);
+		g_free(raw_text);
+	}
 
-gboolean
-register_document (KzSearch *search, const gchar *uri, const gchar *title, GTime mtime)
-{
-	/* cbdatesrtwww(time, 0); */
+	success = est_db_put_doc(db, doc, ESTPDCLEAN);
+	if (!success)
+	{
+		g_warning("register error: %s", est_err_msg(ecode));
+	}
 
-	g_idle_add (_update_index, (gpointer)uri);
+	est_doc_delete(doc);
 
-	return TRUE;
+	ret = est_db_close(db, &ecode);
+	if (!ret)
+	{
+		g_warning("db close error: %s", est_err_msg(ecode));
+	}
+
+	return (success != 0) ? TRUE : FALSE;
 }
 
 gboolean


More information about the Kazehakase-cvs mailing list
Back to archive index