/* Add the message to the relevant token bucket */
- /* FIXME lock the file */
- cdb_bucket = cdb_fetch(CDB_FULLTEXT, &tokens[i], sizeof(int));
+ /* FIXME do we need to lock the file here? */
+ cdb_bucket = cdb_fetch(CDB_FULLTEXT, &tokens[i],
+ sizeof(int));
if (cdb_bucket == NULL) {
cdb_bucket = malloc(sizeof(struct cdbdata));
cdb_bucket->len = 0;
if (op == 1) { /* add to index */
++num_msgs;
- cdb_bucket->ptr = realloc(cdb_bucket->ptr, num_msgs*sizeof(long) );
+ cdb_bucket->ptr = realloc(cdb_bucket->ptr,
+ num_msgs*sizeof(long));
msgs = (long *) cdb_bucket->ptr;
msgs[num_msgs - 1] = msgnum;
}
}
}
- /* sort and purge dups
- *
- * This whole section is commented out because it's
- * no longer needed -- since the tokenizer already
- * does a merge/purge on the tokens it returns, and
- * we're guaranteed to always be indexing a message
- * with a number higher than any already in the index.
- *
- if ( (op == 1) && (num_msgs > 1) ) {
- msgs = (long *) cdb_bucket->ptr;
- qsort(msgs, num_msgs, sizeof(long), longcmp);
- for (j=0; j<(num_msgs-1); ++j) {
- if (msgs[j] == msgs[j+1]) {
- memmove(&msgs[j], &msgs[j+1], ((num_msgs - j - 1)*sizeof(long)));
- --num_msgs;
- --j;
- }
- }
- }
- */
-
cdb_store(CDB_FULLTEXT, &tokens[i], sizeof(int),
msgs, (num_msgs*sizeof(long)) );
cdb_free(cdb_bucket);
- /* FIXME unlock the file */
+ /* FIXME do we need to unlock the file here? */
}
free(tokens);
static time_t last_index = 0L;
static time_t last_progress = 0L;
+ /*
+ * Don't do this if the site doesn't have it enabled.
+ */
+ if (!config.c_enable_fulltext) {
+ return;
+ }
+
/*
* Make sure we don't run the indexer too frequently.
* FIXME move the setting into config
/*
* If we've switched wordbreaker modules, burn the index and start
- * over. FIXME write this...
+ * over.
*/
if (CitControl.fulltext_wordbreaker != FT_WORDBREAKER_ID) {
lprintf(CTDL_INFO, "(re)initializing full text index\n");
last_progress = time(NULL);
}
ft_index_message(ft_newmsgs[i], 1);
+
+ /* Check to see if we need to quit early */
+ if (time_to_die) {
+ lprintf(CTDL_DEBUG, "Indexer quitting early\n");
+ ft_newhighest = ft_newmsgs[i];
+ break;
+ }
+
}
free(ft_newmsgs);
return;
}
+/*
+ * Main loop for the indexer thread.
+ */
+void *indexer_thread(void *arg) {
+ struct CitContext indexerCC;
+
+ lprintf(CTDL_DEBUG, "indexer_thread() initializing\n");
+
+ memset(&indexerCC, 0, sizeof(struct CitContext));
+ indexerCC.internal_pgm = 1;
+ indexerCC.cs_pid = 0;
+ pthread_setspecific(MyConKey, (void *)&indexerCC );
+
+ cdb_allocate_tsd();
+
+ while (!time_to_die) {
+ do_fulltext_indexing();
+ sleep(1);
+ }
+
+ lprintf(CTDL_DEBUG, "indexer_thread() exiting\n");
+ pthread_exit(NULL);
+}
+
+
/*
* API call to perform searches.
char search_string[256];
if (CtdlAccessCheck(ac_logged_in)) return;
+
+ if (!config.c_enable_fulltext) {
+ cprintf("%d Full text index is not enabled on this server.\n",
+ ERROR + CMD_NOT_SUPPORTED);
+ }
+
extract_token(search_string, argbuf, 0, '|', sizeof search_string);
ft_search(&num_msgs, &msgs, search_string);
char *serv_fulltext_init(void)
{
- CtdlRegisterSessionHook(do_fulltext_indexing, EVT_TIMER);
CtdlRegisterProtoHook(cmd_srch, "SRCH", "Full text search");
return "$Id$";
}