On sam, nov 24, 2007 at 11:31:34 +0000, Pierre Habouzit wrote:
Package: tracker Severity: normal Tags: patch Hi, you may want to have a look at http://bugs.debian.org/452074 for a background on why. Though, the same upstream author released a rework of QDBM named Tokyo Cabinet, that just hit unstable. Here is a patch that does the following
And of course I messed up and forgot to add the patch â here it is. -- ÂOÂ Pierre Habouzit ÂÂO madcoder debian org OOO http://www.madism.org
diff --git a/configure.ac b/configure.ac
index 126f653..9c305e8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -207,7 +207,6 @@ fi
AM_CONDITIONAL(HAVE_RECENT_GLIB, test "$have_recent_glib" = "yes")
-
####################################################################
# External QDBM check
####################################################################
@@ -233,6 +232,17 @@ AC_SUBST(QDBM_CFLAGS)
AC_SUBST(QDBM_LIBS)
+####################################################################
+# check for Tokyo Cabinet
+####################################################################
+
+TOKYOCABINET_REQUIRED=1.0.6
+
+PKG_CHECK_MODULES(TOKYOCABINET, [ tokyocabinet >= $TOKYOCABINET_REQUIRED ])
+
+AC_SUBST(TOKYOCABINET_CFLAGS)
+AC_SUBST(TOKYOCABINET_LIBS)
+
##################################################################
# check for libxml2
diff --git a/src/trackerd/Makefile.am b/src/trackerd/Makefile.am
index 39fcc98..25f8076 100644
--- a/src/trackerd/Makefile.am
+++ b/src/trackerd/Makefile.am
@@ -9,6 +9,7 @@ INCLUDES = \
$(DBUS_CFLAGS) \
$(SQLITE3_CFLAGS) \
$(QDBM_CFLAGS) \
+ $(TOKYOCABINET_CFLAGS) \
$(UNAC_CFLAGS)
@@ -107,6 +108,7 @@ trackerd_LDADD = \
$(GMIME_LIBS) \
$(SQLITE3_LIBS) \
$(QDBM_LIBS) \
+ $(TOKYOCABINET_LIBS) \
$(UNAC_LIBS) \
$(GTHREAD_LIBS) \
-lz \
diff --git a/src/trackerd/tracker-cache.c b/src/trackerd/tracker-cache.c
index 7b9ef15..f04eff9 100644
--- a/src/trackerd/tracker-cache.c
+++ b/src/trackerd/tracker-cache.c
@@ -156,7 +156,7 @@ tracker_cache_flush_all (gboolean cache_full)
/* determine is index has been written to significantly before and create new ones if so */
if (tracker_indexer_size (tracker->file_index) > 4000000) {
index_con.file_index = create_merge_index ("file-index.tmp.");
- tracker_log ("flushing to %s", dpname (index_con.file_index->word_index));
+ tracker_log ("flushing to %s", index_con.file_index->word_index->path);
using_file_tmp = TRUE;
} else {
index_con.file_index = tracker->file_index;
diff --git a/src/trackerd/tracker-dbus-search.c b/src/trackerd/tracker-dbus-search.c
index ae29f3b..e2e1100 100644
--- a/src/trackerd/tracker-dbus-search.c
+++ b/src/trackerd/tracker-dbus-search.c
@@ -956,20 +956,20 @@ tracker_dbus_method_search_suggest (DBusRec *rec)
Indexer *index = tracker->file_index;
- dpiterinit (index->word_index);
+ tchdbiterinit (index->word_index);
g_get_current_time (&start);
- str = dpiternext (index->word_index, NULL);
+ str = tchdbiternext (index->word_index, NULL);
while (str != NULL) {
dist = levenshtein (term, str, 0);
if (dist != -1 && dist < maxdist) {
hits = 0;
- if ((tmp = dpget (index->word_index, str, -1, 0, -1, &tsiz)) != NULL) {
+ if ((tmp = tchdbget3 (index->word_index, str, -1, &tsiz, -1)) != NULL) {
hits = tsiz / sizeof (WordDetails);
free (tmp);
if (tsiz % sizeof (WordDetails) != 0) {
- tracker_set_error (rec, "Possible data error from dpget Aborting
tracker_dbus_method_search_suggest.");
+ tracker_set_error (rec, "Possible data error from tchdbget Aborting
tracker_dbus_method_search_suggest.");
g_free (str);
if (winner_str) {
g_free (winner_str);
@@ -998,7 +998,7 @@ tracker_dbus_method_search_suggest (DBusRec *rec)
tracker_log ("Timeout in tracker_dbus_method_search_suggest");
break;
}
- str = dpiternext (index->word_index, NULL);
+ str = tchdbiternext (index->word_index, NULL);
}
if (winner_str == NULL) {
diff --git a/src/trackerd/tracker-indexer.c b/src/trackerd/tracker-indexer.c
index e0db318..478c5b0 100644
--- a/src/trackerd/tracker-indexer.c
+++ b/src/trackerd/tracker-indexer.c
@@ -45,7 +45,7 @@ get_score (WordDetails *details)
a[0] = (details->amalgamated >> 16) & 0xFF;
a[1] = (details->amalgamated >> 8) & 0xFF;
- return (a[0] << 8) | (a[1]);
+ return (a[0] << 8) | (a[1]);
}
@@ -71,13 +71,13 @@ tracker_indexer_calc_amalgamated (gint service, gint score)
service_type = (guint8) service;
- /* amalgamate and combine score and service_type into a single 32-bit int for compact storage */
+ /* amalgamate and combine score and service_type into a single 32-bit int for compact storage */
a[0] = service_type;
a[1] = (score16 >> 8 ) & 0xFF ;
a[2] = score16 & 0xFF ;
a[3] = 0;
- return (a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3];
+ return (a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3];
}
@@ -107,7 +107,7 @@ copy_search_hit (SearchHit *src)
}
-static gint
+static gint
compare_words (const void *a, const void *b)
{
WordDetails *ap, *bp;
@@ -119,7 +119,7 @@ compare_words (const void *a, const void *b)
}
-static gint
+static gint
compare_search_hits (const void *a, const void *b)
{
SearchHit *ap, *bp;
@@ -131,7 +131,7 @@ compare_search_hits (const void *a, const void *b)
}
-static gint
+static gint
compare_search_words (const void *a, const void *b)
{
SearchWord *ap, *bp;
@@ -139,11 +139,11 @@ compare_search_words (const void *a, const void *b)
ap = (SearchWord *)a;
bp = (SearchWord *)b;
- return (ap->hit_count - bp->hit_count);
+ return (ap->hit_count - bp->hit_count);
}
-void
+void
tracker_index_free_hit_list (GSList *hit_list)
{
GSList *lst;
@@ -167,15 +167,15 @@ get_preferred_bucket_count (Indexer *indexer)
if (tracker->index_bucket_ratio < 1) {
- result = (dprnum (indexer->word_index)/2);
+ result = (tchdbrnum (indexer->word_index)/2);
} else if (tracker->index_bucket_ratio > 3) {
- result = (dprnum (indexer->word_index) * 4);
+ result = (tchdbrnum (indexer->word_index) * 4);
} else {
- result = (tracker->index_bucket_ratio * dprnum (indexer->word_index));
+ result = (tracker->index_bucket_ratio * tchdbrnum (indexer->word_index));
}
tracker_log ("Preferred bucket count is %d", result);
@@ -183,31 +183,52 @@ get_preferred_bucket_count (Indexer *indexer)
return result;
}
+bool
+tracker_update_index (const gchar *name, TCHDB *db)
+{
+ DEPOT *qdb = dpopen (name, DP_OREADER | DP_ONOLCK, 0);
+ char *k, *v;
+ int klen, vlen;
+
+ if (!qdb)
+ return false;
+
+ unlink (name);
+ if (!tchdbopen (db, name, HDBOWRITER | HDBOCREAT | HDBONOLCK)) {
+ g_assert ("FATAL: index file is dead (suggest delete index file and restart trackerd)");
+ }
+
+ dpiterinit (qdb);
+ while ((k = dpiternext (qdb, &klen))) {
+ v = dpget (qdb, k, klen, 0, -1, &vlen);
+ tchdbput (db, k, klen, v, vlen);
+ free (v);
+ free (k);
+ }
+ dpclose (qdb);
+ return true;
+}
+
-static inline DEPOT *
+static inline TCHDB *
open_index (const gchar *name)
{
- DEPOT *word_index;
+ TCHDB *word_index = tchdbnew();
+ bool result;
tracker_log ("Opening index %s", name);
- if (strstr (name, "tmp")) {
- word_index = dpopen (name, DP_OWRITER | DP_OCREAT | DP_ONOLCK,
tracker->min_index_bucket_count);
- } else {
- word_index = dpopen (name, DP_OWRITER | DP_OCREAT | DP_ONOLCK,
tracker->max_index_bucket_count);
+ result = tchdbopen (word_index, name, HDBOWRITER | HDBOCREAT | HDBONOLCK);
+ if (!result && tchdbecode (word_index) == TCEMETA) {
+ /* probably a qdbm database, try to upgrade it */
+ result = tracker_update_index (name, word_index);
}
- if (!word_index) {
- tracker_log ("%s index was not closed properly and caused error %s- attempting repair", name,
dperrmsg (dpecode));
- if (dprepair (name)) {
- word_index = dpopen (name, DP_OWRITER | DP_OCREAT | DP_ONOLCK,
tracker->min_index_bucket_count);
- } else {
- g_assert ("FATAL: index file is dead (suggest delete index file and restart
trackerd)");
- }
+ if (!result) {
+ g_assert ("FATAL: index file is dead (suggest delete index file and restart trackerd)");
}
return word_index;
-
}
@@ -215,19 +236,19 @@ Indexer *
tracker_indexer_open (const gchar *name)
{
char *word_dir;
- DEPOT *word_index;
+ TCHDB *word_index;
Indexer *result;
word_dir = g_build_filename (tracker->data_dir, name, NULL);
word_index = open_index (word_dir);
-
+
g_free (word_dir);
result = g_new0 (Indexer, 1);
result->main_index = FALSE;
-
+
result->needs_merge = FALSE;
result->name = g_strdup (name);
@@ -236,14 +257,12 @@ tracker_indexer_open (const gchar *name)
result->word_mutex = g_mutex_new ();
- dpsetalign (word_index , 8);
-
/* re optimize database if bucket count < rec count */
int bucket_count, rec_count;
- bucket_count = dpbnum (result->word_index);
- rec_count = dprnum (result->word_index);
+ bucket_count = tchdbbnum (result->word_index);
+ rec_count = tchdbrnum (result->word_index);
tracker_log ("Bucket count (max is %d) is %d and Record Count is %d",
tracker->max_index_bucket_count, bucket_count, rec_count);
@@ -253,14 +272,15 @@ tracker_indexer_open (const gchar *name)
void
tracker_indexer_close (Indexer *indexer)
-{
+{
g_return_if_fail (indexer);
g_mutex_lock (indexer->word_mutex);
- if (!dpclose (indexer->word_index)) {
- tracker_log ("Index closure has failed due to %s", dperrmsg (dpecode));
+ if (!tchdbclose (indexer->word_index)) {
+ tracker_log ("Index closure has failed due to %s", tchdberrmsg (tchdbecode
(indexer->word_index)));
}
+ tchdbdel (indexer->word_index);
g_mutex_unlock (indexer->word_mutex);
g_mutex_free (indexer->word_mutex);
@@ -272,7 +292,7 @@ tracker_indexer_close (Indexer *indexer)
void
tracker_indexer_free (Indexer *indexer, gboolean remove_file)
{
-
+
if (remove_file) {
@@ -282,14 +302,14 @@ tracker_indexer_free (Indexer *indexer, gboolean remove_file)
g_mutex_lock (indexer->word_mutex);
- dpremove (dbname);
+ unlink (dbname);
g_mutex_unlock (indexer->word_mutex);
g_free (dbname);
} else {
g_mutex_lock (indexer->word_mutex);
- dpclose (indexer->word_index);
+ tchdbdel (indexer->word_index);
g_mutex_unlock (indexer->word_mutex);
}
@@ -299,14 +319,14 @@ tracker_indexer_free (Indexer *indexer, gboolean remove_file)
g_free (indexer);
-
+
}
guint32
tracker_indexer_size (Indexer *indexer)
{
- return dpfsiz (indexer->word_index);
+ return tchdbfsiz (indexer->word_index);
}
@@ -314,7 +334,7 @@ void
tracker_indexer_sync (Indexer *indexer)
{
g_mutex_lock (indexer->word_mutex);
- dpsync (indexer->word_index);
+ tchdbsync (indexer->word_index);
g_mutex_unlock (indexer->word_mutex);
}
@@ -322,7 +342,7 @@ tracker_indexer_sync (Indexer *indexer)
gboolean
tracker_indexer_optimize (Indexer *indexer)
{
-
+
int num, b_count;
if (tracker->shutdown) {
@@ -344,34 +364,33 @@ tracker_indexer_optimize (Indexer *indexer)
tracker_log ("No. of buckets per division is %d", b_count);
tracker_log ("Please wait while optimization of indexes takes place...");
- tracker_log ("Index has file size %10.0f and bucket count of %d of which %d are used...",
tracker_indexer_size (indexer), dpbnum (indexer->word_index), dpbusenum (indexer->word_index));
-
+ tracker_log ("Index has file size %10.0f and bucket count of %d...", tracker_indexer_size (indexer),
indexer->word_index->bnum);
+
g_mutex_lock (indexer->word_mutex);
- if (!dpoptimize (indexer->word_index, b_count)) {
+ if (!tchdboptimize (indexer->word_index, b_count, 8, -1, UINT8_MAX)) {
g_mutex_unlock (indexer->word_mutex);
- tracker_log ("Optimization has failed due to %s", dperrmsg (dpecode));
+ tracker_log ("Optimization has failed due to %s", tchdberrmsg (tchdbecode
(indexer->word_index)));
return FALSE;
}
g_mutex_unlock (indexer->word_mutex);
- tracker_log ("Index has been successfully optimized to file size %10.0f and with bucket count of %d
of which %d are used...", tracker_indexer_size (indexer), dpbnum (indexer->word_index), dpbusenum
(indexer->word_index));
-
-
+ tracker_log ("Index has been successfully optimized to file size %10.0f and with bucket count of
%d...", tracker_indexer_size (indexer), indexer->word_index->bnum);
+
+
return TRUE;
}
-static inline gboolean
+static inline gboolean
has_word (Indexer *index, const char *word)
{
char buffer [32];
- int count = dpgetwb (index->word_index, word, -1, 0, 32, buffer);
+ int count = tchdbget3(index->word_index, word, -1, buffer, sizeof(buffer));
return (count > 7);
-
}
@@ -405,23 +424,23 @@ tracker_indexer_apply_changes (Indexer *dest, Indexer *src, gboolean update)
/* halve the interval value as notebook hard drives are smaller */
if (tracker->battery_state_file) interval = interval / 2;
- dpiterinit (src->word_index);
-
- while ((str = dpiternext (src->word_index, NULL))) {
-
+ tchdbiterinit (src->word_index);
+
+ while ((str = tchdbiternext (src->word_index, NULL))) {
+
i++;
if (i > 1 && (i % interval == 0)) {
- dpsync (dest->word_index);
+ tchdbsync (dest->word_index);
LoopEvent event = tracker_cache_event_check (NULL, FALSE);
if (event==EVENT_SHUTDOWN) {
return;
- }
+ }
}
-
- bytes = dpgetwb (src->word_index, str, -1, 0, buff_size, buffer);
+
+ bytes = tchdbget3 (src->word_index, str, -1, buffer, buff_size);
if (bytes < 1) continue;
@@ -435,13 +454,13 @@ tracker_indexer_apply_changes (Indexer *dest, Indexer *src, gboolean update)
} else {
tracker_indexer_append_word_chunk (dest, str, (WordDetails *) buffer, bytes / sz);
}
-
- dpout (src->word_index, str, -1);
+
+ tchdbout (src->word_index, str, -1);
g_free (str);
}
-
- dpsync (dest->word_index);
+
+ tchdbsync (dest->word_index);
/* delete src and recreate if file update index */
@@ -499,7 +518,7 @@ tracker_indexer_merge_indexes (IndexType type)
const char *prefix;
int i = 0, index_count, interval = 5000;
gboolean final_exists;
-
+
if (type == INDEX_TYPE_FILES) {
prefix = "file-index.tmp.";
index_list = g_slist_prepend (index_list, tracker->file_index);
@@ -520,7 +539,7 @@ tracker_indexer_merge_indexes (IndexType type)
g_free (tmp);
}
-
+
file_list = tracker_get_files_with_prefix (tracker->data_dir, prefix);
if (!file_list || !file_list->data) {
@@ -584,16 +603,16 @@ tracker_indexer_merge_indexes (IndexType type)
for (l=index_list; l && l->data; l=l->next) {
index = l->data;
- dpiterinit (index->word_index);
-
- while ((str = dpiternext (index->word_index, NULL))) {
+ tchdbiterinit (index->word_index);
+
+ while ((str = tchdbiternext (index->word_index, NULL))) {
char buffer[MAX_HIT_BUFFER];
int offset;
int sz = sizeof (WordDetails);
int buff_size = MAX_HITS_FOR_WORD * sz;
-
+
if (!has_word (final_index, str)) {
@@ -606,10 +625,10 @@ tracker_indexer_merge_indexes (IndexType type)
return;
}
}
-
+
if (i > interval && (i % interval == 0)) {
- dpsync (final_index->word_index);
+ tchdbsync (final_index->word_index);
guint32 size = tracker_indexer_size (final_index);
@@ -628,8 +647,8 @@ tracker_indexer_merge_indexes (IndexType type)
/* halve the interval value as notebook hard drives are smaller */
if (tracker->battery_state_file) interval = interval / 2;
}
-
- offset = dpgetwb (index->word_index, str, -1, 0, buff_size, buffer);
+
+ offset = tchdbget3 (index->word_index, str, -1, buffer, buff_size);
if (offset < 1) continue;
@@ -639,7 +658,7 @@ tracker_indexer_merge_indexes (IndexType type)
}
if (offset > 7 && offset < buff_size) {
-
+
GSList *list;
Indexer *tmp_index;
int tmp_offset;
@@ -650,9 +669,9 @@ tracker_indexer_merge_indexes (IndexType type)
tmp_index = list->data;
if (!tmp_index) continue;
-
- tmp_offset = dpgetwb (tmp_index->word_index, str, -1, 0,
(buff_size - offset), tmp_buffer);
-
+
+ tmp_offset = tchdbget3 (tmp_index->word_index, str, -1,
tmp_buffer, (buff_size - offset));
+
if (tmp_offset > 0 && (tmp_offset % sz != 0)) {
tracker_error ("possible corruption found during
merge of word %s - purging word from index", str);
continue;
@@ -664,15 +683,15 @@ tracker_indexer_merge_indexes (IndexType type)
offset += tmp_offset;
- }
+ }
}
-
- dpput (final_index->word_index, str, -1, buffer, offset, DP_DOVER);
+
+ tchdbput (final_index->word_index, str, -1, buffer, offset);
}
-
+
}
g_free (str);
@@ -687,33 +706,33 @@ tracker_indexer_merge_indexes (IndexType type)
/* remove existing main index */
g_mutex_lock (index->word_mutex);
- char *fname = dpname (index->word_index);
+ char *fname = g_strdup (index->word_index->path);
+
+ tchdbdel (index->word_index);
- dpclose (index->word_index);
+ unlink (fname);
- dpremove (fname);
+ char *final_name = g_strdup (final_index->word_index->path);
- char *final_name = dpname (final_index->word_index);
-
tracker_indexer_close (final_index);
-
+
/* rename and reopen final index as main index */
-
+
rename (final_name, fname);
- index->word_index = open_index (fname);
+ index->word_index = open_index (fname);
g_free (fname);
- g_free (final_name);
+ g_free (final_name);
g_mutex_unlock (index->word_mutex);
}
-
+
}
-
+
g_slist_free (index_list);
-
+
}
@@ -735,13 +754,13 @@ tracker_indexer_append_word_chunk (Indexer *indexer, const gchar *word, WordDeta
g_return_val_if_fail (word_detail_count > 0, FALSE);
g_mutex_lock (indexer->word_mutex);
- if (!dpput (indexer->word_index, word, -1, (char *) details, (word_detail_count * sizeof
(WordDetails)), DP_DCAT)) {
+ if (!tchdbputcat (indexer->word_index, word, -1, (char *) details, (word_detail_count * sizeof
(WordDetails)))) {
g_mutex_unlock (indexer->word_mutex);
return FALSE;
}
g_mutex_unlock (indexer->word_mutex);
- return TRUE;
+ return TRUE;
}
@@ -804,7 +823,7 @@ tracker_indexer_append_word_list (Indexer *indexer, const gchar *word, GSList *l
/* use for deletes or updates of multiple entities when they are not new */
gboolean
tracker_indexer_update_word_chunk (Indexer *indexer, const gchar *word, WordDetails *detail_chunk, gint
word_detail_count)
-{
+{
int tsiz, j, i, score;
char *tmp;
WordDetails *word_details;
@@ -821,7 +840,7 @@ tracker_indexer_update_word_chunk (Indexer *indexer, const gchar *word, WordDeta
g_mutex_lock (indexer->word_mutex);
- if ((tmp = dpget (indexer->word_index, word, -1, 0, MAX_HIT_BUFFER, &tsiz)) != NULL) {
+ if ((tmp = tchdbget (indexer->word_index, word, -1, &tsiz)) != NULL) {
WordDetails *details = (WordDetails *) tmp;
@@ -843,19 +862,19 @@ tracker_indexer_update_word_chunk (Indexer *indexer, const gchar *word, WordDeta
/* NB the paramter score can be negative */
score = get_score (&details[i]) + get_score (word_details);
-
- /* check for deletion */
+
+ /* check for deletion */
if (score < 1) {
-
+
gint k;
-
+
/* shift all subsequent records in array down one place */
for (k = i + 1; k < hit_count; k++) {
details[k - 1] = details[k];
}
hit_count--;
-
+
} else {
details[i].amalgamated = tracker_indexer_calc_amalgamated
(get_service_type (&details[i]), score);
}
@@ -871,23 +890,23 @@ tracker_indexer_update_word_chunk (Indexer *indexer, const gchar *word, WordDeta
tracker_debug ("could not update word hit %s - appending", word);
}
}
-
+
/* write back if we have modded anything */
if (write_back) {
- dpput (indexer->word_index, word, -1, (char *) details, (hit_count * sizeof
(WordDetails)), DP_DOVER);
+ tchdbput (indexer->word_index, word, -1, (char *) details, (hit_count * sizeof
(WordDetails)));
}
- g_mutex_unlock (indexer->word_mutex);
+ g_mutex_unlock (indexer->word_mutex);
if (list) {
tracker_indexer_append_word_list (indexer, word, list);
g_slist_free (list);
}
-
+
return TRUE;
}
- g_mutex_unlock (indexer->word_mutex);
+ g_mutex_unlock (indexer->word_mutex);
/* none of the updates can be applied if word does not exist so return them all to be appended later
*/
return tracker_indexer_append_word_chunk (indexer, word, detail_chunk, word_detail_count);
@@ -939,11 +958,11 @@ tracker_remove_dud_hits (Indexer *indexer, const gchar *word, GSList *dud_list)
g_return_val_if_fail (indexer, FALSE);
g_return_val_if_fail (word, FALSE);
g_return_val_if_fail (dud_list, FALSE);
-
+
g_mutex_lock (indexer->word_mutex);
/* check if existing record is there */
- if ((tmp = dpget (indexer->word_index, word, -1, 0, MAX_HIT_BUFFER, &tsiz)) != NULL) {
+ if ((tmp = tchdbget (indexer->word_index, word, -1, &tsiz)) != NULL) {
if (tsiz >= (int) sizeof (WordDetails)) {
@@ -952,7 +971,7 @@ tracker_remove_dud_hits (Indexer *indexer, const gchar *word, GSList *dud_list)
details = (WordDetails *) tmp;
pnum = tsiz / sizeof (WordDetails);
- wi = 0;
+ wi = 0;
for (i = 0; i < pnum; i++) {
@@ -972,7 +991,7 @@ tracker_remove_dud_hits (Indexer *indexer, const gchar *word, GSList *dud_list)
}
/* make size of array one size smaller */
- tsiz -= sizeof (WordDetails);
+ tsiz -= sizeof (WordDetails);
pnum--;
break;
@@ -981,10 +1000,10 @@ tracker_remove_dud_hits (Indexer *indexer, const gchar *word, GSList *dud_list)
}
}
- dpput (indexer->word_index, word, -1, (char *) details, tsiz, DP_DOVER);
-
- g_mutex_unlock (indexer->word_mutex);
-
+ tchdbput (indexer->word_index, word, -1, (char *) details, tsiz);
+
+ g_mutex_unlock (indexer->word_mutex);
+
g_free (tmp);
return TRUE;
@@ -1014,9 +1033,9 @@ count_hit_size_for_word (Indexer *indexer, const gchar *word)
{
int tsiz;
- g_mutex_lock (indexer->word_mutex);
- tsiz = dpvsiz (indexer->word_index, word, -1);
- g_mutex_unlock (indexer->word_mutex);
+ g_mutex_lock (indexer->word_mutex);
+ tsiz = tchdbvsiz (indexer->word_index, word, -1);
+ g_mutex_unlock (indexer->word_mutex);
return tsiz;
}
@@ -1046,7 +1065,7 @@ tracker_create_query (Indexer *indexer, gint *service_array, gint service_array_
result->service_array = service_array;
result->service_array_count = service_array_count;
result->offset = offset;
- result->limit = limit;
+ result->limit = limit;
return result;
}
@@ -1105,14 +1124,14 @@ get_hits_for_single_word (SearchQuery *query, SearchWord *search_word, gint *ret
/* some results might be dud so get an extra 50 to compensate */
int limit = query->limit + 50;
-
+
if (tracker->shutdown) {
return NULL;
}
g_mutex_lock (query->indexer->word_mutex);
- if ((tmp = dpget (query->indexer->word_index, search_word->word, -1, 0, MAX_HIT_BUFFER, &tsiz)) !=
NULL) {
+ if ((tmp = tchdbget (query->indexer->word_index, search_word->word, -1, &tsiz)) != NULL) {
g_mutex_unlock (query->indexer->word_mutex);
@@ -1121,11 +1140,11 @@ get_hits_for_single_word (SearchQuery *query, SearchWord *search_word, gint *ret
int pnum;
details = (WordDetails *) tmp;
-
+
pnum = tsiz / sizeof (WordDetails);
tracker_debug ("total hit count (excluding service divisions) is %d", pnum);
-
+
qsort (details, pnum, sizeof (WordDetails), compare_words);
int i;
@@ -1149,7 +1168,7 @@ get_hits_for_single_word (SearchQuery *query, SearchWord *search_word, gint *ret
hit = word_details_to_search_hit (&details[i]);
result = g_slist_prepend (result, hit);
-
+
limit--;
} else {
@@ -1188,7 +1207,7 @@ get_intermediate_hits (SearchQuery *query, GHashTable *match_table, SearchWord *
g_mutex_lock (query->indexer->word_mutex);
- if ((tmp = dpget (query->indexer->word_index, search_word->word, -1, 0, MAX_HIT_BUFFER, &tsiz)) !=
NULL) {
+ if ((tmp = tchdbget (query->indexer->word_index, search_word->word, -1, &tsiz)) != NULL) {
g_mutex_unlock (query->indexer->word_mutex);
@@ -1198,9 +1217,9 @@ get_intermediate_hits (SearchQuery *query, GHashTable *match_table, SearchWord *
int count;
details = (WordDetails *) tmp;
-
+
count = tsiz / sizeof (WordDetails);
-
+
int i;
for (i = 0; i < count; i++) {
@@ -1212,7 +1231,7 @@ get_intermediate_hits (SearchQuery *query, GHashTable *match_table, SearchWord *
if (match_table) {
gpointer pscore;
guint32 score;
-
+
pscore = g_hash_table_lookup (match_table, GUINT_TO_POINTER
(details[i].id));
if (bool_op == BoolAnd && !pscore) {
@@ -1221,7 +1240,7 @@ get_intermediate_hits (SearchQuery *query, GHashTable *match_table, SearchWord *
score = GPOINTER_TO_UINT (pscore) + get_idf_score
(&details[i], search_word->idf);
- g_hash_table_insert (result, GUINT_TO_POINTER
(details[i].id), GUINT_TO_POINTER (score));
+ g_hash_table_insert (result, GUINT_TO_POINTER
(details[i].id), GUINT_TO_POINTER (score));
} else {
int idf_score = get_idf_score (&details[i], search_word->idf);
@@ -1271,10 +1290,10 @@ get_final_hits (SearchQuery *query, GHashTable *match_table, SearchWord *search_
if (!match_table || g_hash_table_size (match_table) < 1) {
return NULL;
}
-
+
g_mutex_lock (query->indexer->word_mutex);
- if ((tmp = dpget (query->indexer->word_index, search_word->word, -1, 0, MAX_HIT_BUFFER, &tsiz)) !=
NULL) {
+ if ((tmp = tchdbget (query->indexer->word_index, search_word->word, -1, &tsiz)) != NULL) {
g_mutex_unlock (query->indexer->word_mutex);
@@ -1284,9 +1303,9 @@ get_final_hits (SearchQuery *query, GHashTable *match_table, SearchWord *search_
int size, count;
details = (WordDetails *) tmp;
-
+
count = tsiz / sizeof (WordDetails);
-
+
size = g_hash_table_size (match_table);
if (bool_op == BoolAnd) {
@@ -1294,7 +1313,7 @@ get_final_hits (SearchQuery *query, GHashTable *match_table, SearchWord *search_
} else {
result = g_malloc0 (sizeof (SearchHit) * (size + count));
}
-
+
int i;
for (i = 0; i < count; i++) {
@@ -1305,7 +1324,7 @@ get_final_hits (SearchQuery *query, GHashTable *match_table, SearchWord *search_
gpointer pscore;
int score;
-
+
pscore = g_hash_table_lookup (match_table, GUINT_TO_POINTER
(details[i].id));
if (bool_op == BoolAnd && !pscore) {
@@ -1318,7 +1337,7 @@ get_final_hits (SearchQuery *query, GHashTable *match_table, SearchWord *search_
result[rnum].service_id = details[i].id;
result[rnum].service_type_id = service;
result[rnum].score = score;
-
+
rnum++;
}
}
@@ -1334,7 +1353,7 @@ get_final_hits (SearchQuery *query, GHashTable *match_table, SearchWord *search_
return NULL;
}
- if ((limit + offset) < rnum) {
+ if ((limit + offset) < rnum) {
count = limit + offset;
} else {
count = rnum;
@@ -1428,7 +1447,7 @@ tracker_indexer_get_hits (SearchQuery *query)
if (table) {
g_hash_table_destroy (table);
}
-
+
return TRUE;
}
}
@@ -1446,7 +1465,7 @@ prepend_key_pointer (gpointer key, gpointer value, gpointer data)
}
-static GSList *
+static GSList *
g_hash_table_key_slist (GHashTable *table)
{
GSList *rv = NULL;
@@ -1494,7 +1513,7 @@ tracker_get_hit_counts (SearchQuery *query)
if (parent_id != -1) {
count = GPOINTER_TO_UINT (g_hash_table_lookup (table, GUINT_TO_POINTER
(parent_id))) + 1;
-
+
g_hash_table_insert (table, GUINT_TO_POINTER (parent_id), GUINT_TO_POINTER
(count));
}
}
@@ -1509,7 +1528,7 @@ tracker_get_hit_counts (SearchQuery *query)
if (tracker_indexer_get_hits (query)) {
GSList *tmp;
-
+
for (tmp = query->hits; tmp; tmp=tmp->next) {
SearchHit *hit = tmp->data;
guint32 count = GPOINTER_TO_UINT (g_hash_table_lookup (table, GUINT_TO_POINTER
(hit->service_type_id))) + 1;
@@ -1540,7 +1559,7 @@ tracker_get_hit_counts (SearchQuery *query)
gint len, i;
len = g_slist_length (list);
-
+
gchar **res = g_new0 (gchar *, len + 1);
res[len] = NULL;
diff --git a/src/trackerd/tracker-indexer.h b/src/trackerd/tracker-indexer.h
index eb3b035..26f2d4a 100644
--- a/src/trackerd/tracker-indexer.h
+++ b/src/trackerd/tracker-indexer.h
@@ -23,8 +23,13 @@
#define _TRACKER_INDEXER_H
+#include <stdbool.h>
+#include <stdint.h>
#include <stdlib.h>
+#include <time.h>
#include <glib.h>
+#include <tcutil.h>
+#include <tchdb.h>
#include <depot.h>
#include "tracker-utils.h"
@@ -52,7 +57,7 @@ typedef struct {
typedef struct {
- DEPOT *word_index; /* file hashtable handle for the word -> {serviceID, ServiceTypeID,
Score} */
+ TCHDB *word_index; /* file hashtable handle for the word -> {serviceID, ServiceTypeID,
Score} */
GMutex *word_mutex;
char *name;
gpointer emails; /* pointer to email indexer */
Attachment:
pgpvTTcyihzmW.pgp
Description: PGP signature