svnno****@sourc*****
svnno****@sourc*****
Wed Mar 28 09:24:12 JST 2007
Revision: 3063 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=kazehakase&view=rev&rev=3063 Author: kous Date: 2007-03-28 09:24:11 +0900 (Wed, 28 Mar 2007) Log Message: ----------- * module/search/kz-hyper-estraier-search.c: keep DB opened while object is alive. Modified Paths: -------------- kazehakase/trunk/ChangeLog kazehakase/trunk/module/search/kz-hyper-estraier-search.c Modified: kazehakase/trunk/ChangeLog =================================================================== --- kazehakase/trunk/ChangeLog 2007-03-28 00:02:30 UTC (rev 3062) +++ kazehakase/trunk/ChangeLog 2007-03-28 00:24:11 UTC (rev 3063) @@ -1,5 +1,8 @@ 2007-03-28 Kouhei Sutou <kou****@cozmi*****> + * module/search/kz-hyper-estraier-search.c: keep DB opened while + object is alive. + * configure.ac (EST_VERSION): removed. * module/search/kz-hyper-estraier-search.c Modified: kazehakase/trunk/module/search/kz-hyper-estraier-search.c =================================================================== --- kazehakase/trunk/module/search/kz-hyper-estraier-search.c 2007-03-28 00:02:30 UTC (rev 3062) +++ kazehakase/trunk/module/search/kz-hyper-estraier-search.c 2007-03-28 00:24:11 UTC (rev 3063) @@ -2,21 +2,21 @@ /* * Copyright (C) 2007 Kouhei Sutou <kou****@cozmi*****> - * copyright (c) 2004 hiroyuki ikezoe + * Copyright (C) 2004 Hiroyuki Ikezoe * - * this program is free software; you can redistribute it and/or modify - * it under the terms of the gnu general public license as published by - * the free software foundation; either version 2, or (at your option) + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) * any later version. * - * this program is distributed in the hope that it will be useful, - * but without any warranty; without even the implied warranty of - * merchantability or fitness for a particular purpose. see the - * gnu general public license for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * you should have received a copy of the gnu general public license - * along with this program; if not, write to the free software - * foundation, inc., 59 temple place - suite 330, boston, ma 02111-1307, usa. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <ctype.h> @@ -39,9 +39,9 @@ #define KZ_TYPE_HYPER_ESTRAIER_SEARCH (kz_type_hyper_estraier_search) #define KZ_HYPER_ESTRAIER_SEARCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KZ_TYPE_HYPER_ESTRAIER_SEARCH, KzHyperEstraierSearch)) #define KZ_IS_HYPER_ESTRAIER_SEARCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KZ_TYPE_HYPER_ESTRAIER_SEARCH)) -#define KZ_HYPER_ESTRAIER_SEARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KZ_TYPE_HYPER_ESTRAISER_SEARCH, KzHyperEstraierSearchClass)) -#define KZ_IS_HYPER_ESTRAISER_SEARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KZ_TYPE_HYPER_ESTRAISER_SEARCH)) -#define KZ_HYPER_ESTRAIER_SEARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KZ_TYPE_HYPER_ESTRAISER_SEARCH, KzHyperEstraierSearchClass)) +#define KZ_HYPER_ESTRAIER_SEARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KZ_TYPE_HYPER_ESTRAIER_SEARCH, KzHyperEstraierSearchClass)) +#define KZ_IS_HYPER_ESTRAIER_SEARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KZ_TYPE_HYPER_ESTRAIER_SEARCH)) +#define KZ_HYPER_ESTRAIER_SEARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KZ_TYPE_HYPER_ESTRAIER_SEARCH, KzHyperEstraierSearchClass)) typedef struct _KzHyperEstraierSearch KzHyperEstraierSearch; @@ -52,6 +52,8 @@ gchar *dbname; gchar *cache_path; size_t cache_path_len; + + ESTMTDB *db; }; typedef struct _KzHyperEstraierSearchClass KzHyperEstraierSearchClass; @@ -173,6 +175,37 @@ } static void +close_db (KzHyperEstraierSearch *search) +{ + g_return_if_fail(KZ_IS_HYPER_ESTRAIER_SEARCH(search)); + + if (search->db) + { + int ecode; + if (!est_mtdb_close(search->db, &ecode)) + g_warning("db close error: %s", est_err_msg(ecode)); + } + + search->db = NULL; +} + +static void +open_db (KzHyperEstraierSearch *search) +{ + int ecode; + + g_return_if_fail(KZ_IS_HYPER_ESTRAIER_SEARCH(search)); + g_return_if_fail(search->dbname); + + if (search->db) + close_db(search); + + search->db = est_mtdb_open(search->dbname, ESTDBWRITER, &ecode); + if (!search->db) + g_warning("db open error: %s", est_err_msg(ecode)); +} + +static void kz_hyper_estraier_search_init (KzHyperEstraierSearch *search) { search->cache_path = g_strdup(KZ_GET_HISTORY_DIR); @@ -180,6 +213,8 @@ NULL); search->cache_path_len = strlen(search->cache_path); + + open_db(search); } static void @@ -188,6 +223,9 @@ KzHyperEstraierSearch *search; search = KZ_HYPER_ESTRAIER_SEARCH(object); + + close_db(search); + if (search->dbname) g_free(search->dbname); if (search->cache_path) @@ -204,10 +242,9 @@ static gchar * create_search_result_html (KzSearch *search, const gchar *text) { - ESTMTDB *db; ESTCOND *cond; CBLIST *highlights; - int ecode, *results, n_results, i, ret; + int *results, n_results, i; gchar *except_word, *tmp; gchar **texts; GString *html, *phrase; @@ -215,12 +252,6 @@ KzHyperEstraierSearch *he_search; he_search = KZ_HYPER_ESTRAIER_SEARCH(search); - db = est_mtdb_open(he_search->dbname, ESTDBREADER, &ecode); - if (!db) - { - g_warning("db open error: %s", est_err_msg(ecode)); - return NULL; - } cond = est_cond_new(); texts = g_strsplit(text, " ", -1); @@ -256,7 +287,7 @@ KZ_CONF_GET("History", "max_results", max_results, INT); half_of_summary = num_summary / 2; - results = est_mtdb_search(db, cond, &n_results, NULL); + results = est_mtdb_search(he_search->db, cond, &n_results, NULL); html = g_string_sized_new(0); @@ -275,7 +306,7 @@ gchar *desc, *cache_str = NULL; const gchar *cache_link, *thumb_uri, *thumb_filename; - doc = est_mtdb_get_doc(db, results[i], 0); + doc = est_mtdb_get_doc(he_search->db, results[i], 0); if (!doc) continue; @@ -315,10 +346,6 @@ cblistclose(highlights); est_cond_delete(cond); - ret = est_mtdb_close(db, &ecode); - if (!ret) - g_warning("db close error: %s", est_err_msg(ecode)); - g_string_append_printf(html, FOOTER, _EST_PROJURL, "Hyper Estraier", _EST_VERSION); g_string_append(html, "</body></html>"); @@ -376,9 +403,8 @@ gboolean register_document (KzSearch *search, const gchar *uri, const gchar *title, const gchar *contents, GTime mtime) { - ESTMTDB *db; ESTDOC *doc; - int ret, ecode, success; + int ecode, success; gchar *time_str, *filename, *text = NULL; gchar *tmp_filename, *tmp_path; KzHyperEstraierSearch *he_search; @@ -386,12 +412,6 @@ g_return_val_if_fail (uri, FALSE); he_search = KZ_HYPER_ESTRAIER_SEARCH(search); - db = est_mtdb_open(he_search->dbname, ESTDBWRITER | ESTDBCREAT, &ecode); - if (!db) - { - g_warning("db open error: %s", est_err_msg(ecode)); - return FALSE; - } doc = est_doc_new(); @@ -417,68 +437,42 @@ g_free(text); } - success = est_mtdb_put_doc(db, doc, ESTPDCLEAN); + success = est_mtdb_put_doc(he_search->db, doc, ESTPDCLEAN); if (!success) g_warning("register error: %s", est_err_msg(ecode)); est_doc_delete(doc); - ret = est_mtdb_close(db, &ecode); - if (!ret) - g_warning("db close error: %s", est_err_msg(ecode)); - return (success != 0) ? TRUE : FALSE; } gboolean unregister_document (KzSearch *search, const gchar *uri) { - ESTMTDB *db; - int id, ret, ecode; + int id; gboolean success; KzHyperEstraierSearch *he_search; he_search = KZ_HYPER_ESTRAIER_SEARCH(search); - db = est_mtdb_open(he_search->dbname, ESTDBWRITER, &ecode); - if (!db) - { - g_warning("db open error: %s", est_err_msg(ecode)); - return FALSE; - } - id = est_mtdb_uri_to_id(db, uri); + id = est_mtdb_uri_to_id(he_search->db, uri); if (id == -1) success = FALSE; else - success = est_mtdb_out_doc(db, id, ESTODCLEAN) != 0; + success = est_mtdb_out_doc(he_search->db, id, ESTODCLEAN) != 0; - ret = est_mtdb_close(db, &ecode); - if (!ret) - g_warning("db close error: %s", est_err_msg(ecode)); - return success; } static GPid optimize_index (KzSearch *search) { - ESTMTDB *db; - int ret, ecode; KzHyperEstraierSearch *he_search; he_search = KZ_HYPER_ESTRAIER_SEARCH(search); - db = est_mtdb_open(he_search->dbname, ESTDBREADER, &ecode); - if (!db) - { - g_warning("db open error: %s", est_err_msg(ecode)); - return FALSE; - } - est_mtdb_optimize(db, 0); + est_mtdb_optimize(he_search->db, 0); - ret = est_mtdb_close(db, &ecode); - if (!ret) - g_warning("db close error: %s", est_err_msg(ecode)); #warning FIXME! return GSource or something. return 0; }