Exemplo n.º 1
0
void ft_delete_remove(char *room, long msgnum)
{
	if (room) return;
	
	/* Remove from fulltext index */
	if (CtdlGetConfigInt("c_enable_fulltext")) {
		ft_index_message(msgnum, 0);
	}
}
Exemplo n.º 2
0
void ft_delete_remove(char *room, long msgnum)
{
	if (room) return;
	
	/* Remove from fulltext index */
	if (config.c_enable_fulltext) {
		ft_index_message(msgnum, 0);
	}
}
Exemplo n.º 3
0
/*
 * Begin the fulltext indexing process.
 */
void do_fulltext_indexing(void) {
	int i;
	static time_t last_index = 0L;
	static time_t last_progress = 0L;
	time_t run_time = 0L;
	time_t end_time = 0L;
	static int is_running = 0;
	if (is_running) return;         /* Concurrency check - only one can run */
	is_running = 1;
	
	/*
	 * Don't do this if the site doesn't have it enabled.
	 */
	if (!CtdlGetConfigInt("c_enable_fulltext")) {
		return;
	}

	/*
	 * Make sure we don't run the indexer too frequently.
	 * FIXME move the setting into config
	 */
 
	if ( (time(NULL) - last_index) < 300L) {
		return;
	}

	/*
	 * Check to see whether the fulltext index is up to date; if there
	 * are no messages to index, don't waste any more time trying.
	 */
	if (
		(CtdlGetConfigLong("MMfulltext") >= CtdlGetConfigLong("MMhighest"))
		&& (CtdlGetConfigInt("MM_fulltext_wordbreaker") == FT_WORDBREAKER_ID)
	) {
		return;		/* nothing to do! */
	}
	
	run_time = time(NULL);
	syslog(LOG_DEBUG, "do_fulltext_indexing() started (%ld)", run_time);
	
	/*
	 * If we've switched wordbreaker modules, burn the index and start
	 * over.
	 */
	begin_critical_section(S_CONTROL);
	if (CtdlGetConfigInt("MM_fulltext_wordbreaker") != FT_WORDBREAKER_ID) {
		syslog(LOG_DEBUG, "wb ver on disk = %d, code ver = %d",
			CtdlGetConfigInt("MM_fulltext_wordbreaker"), FT_WORDBREAKER_ID
		);
		syslog(LOG_INFO, "(re)initializing full text index");
		cdb_trunc(CDB_FULLTEXT);
		CtdlSetConfigLong("MMfulltext", 0);
	}
	end_critical_section(S_CONTROL);

	/*
	 * Now go through each room and find messages to index.
	 */
	ft_newhighest = CtdlGetConfigLong("MMhighest");
	CtdlForEachRoom(ft_index_room, NULL);	/* load all msg pointers */

	if (ft_num_msgs > 0) {
		qsort(ft_newmsgs, ft_num_msgs, sizeof(long), longcmp);
		for (i=0; i<(ft_num_msgs-1); ++i) { /* purge dups */
			if (ft_newmsgs[i] == ft_newmsgs[i+1]) {
				memmove(&ft_newmsgs[i], &ft_newmsgs[i+1],
					((ft_num_msgs - i - 1)*sizeof(long)));
				--ft_num_msgs;
				--i;
			}
		}

		/* Here it is ... do each message! */
		for (i=0; i<ft_num_msgs; ++i) {
			if (time(NULL) != last_progress) {
				syslog(LOG_DEBUG,
					"Indexed %d of %d messages (%d%%)",
						i, ft_num_msgs,
						((i*100) / ft_num_msgs)
				);
				last_progress = time(NULL);
			}
			ft_index_message(ft_newmsgs[i], 1);

			/* Check to see if we need to quit early */
			if (server_shutting_down) {
				syslog(LOG_DEBUG, "Indexer quitting early");
				ft_newhighest = ft_newmsgs[i];
				break;
			}

			/* Check to see if we have to maybe flush to disk */
			if (i >= FT_MAX_CACHE) {
				syslog(LOG_DEBUG, "Time to flush.");
				ft_newhighest = ft_newmsgs[i];
				break;
			}

		}

		free(ft_newmsgs);
		ft_num_msgs = 0;
		ft_num_alloc = 0;
		ft_newmsgs = NULL;
	}
	end_time = time(NULL);

	if (server_shutting_down) {
		is_running = 0;
		return;
	}
	
	syslog(LOG_DEBUG, "do_fulltext_indexing() duration (%ld)", end_time - run_time);
		
	/* Save our place so we don't have to do this again */
	ft_flush_cache();
	begin_critical_section(S_CONTROL);
	CtdlSetConfigLong("MMfulltext", ft_newhighest);
	CtdlSetConfigInt("MM_fulltext_wordbreaker", FT_WORDBREAKER_ID);
	end_critical_section(S_CONTROL);
	last_index = time(NULL);

	syslog(LOG_DEBUG, "do_fulltext_indexing() finished");
	is_running = 0;
	return;
}