From: Art Cancro Date: Mon, 16 May 2005 21:08:45 +0000 (+0000) Subject: * Began writing all the "glue" for the indexer. X-Git-Tag: v7.86~4916 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=ae02d47b9b3ee099a42fffa1675c6e178956e974 * Began writing all the "glue" for the indexer. --- diff --git a/citadel/serv_extensions.h b/citadel/serv_extensions.h index 1a2ed6028..6f6543ab9 100644 --- a/citadel/serv_extensions.h +++ b/citadel/serv_extensions.h @@ -32,6 +32,7 @@ char *serv_test_init(void); char *serv_upgrade_init(void); char *serv_vandelay_init(void); char *serv_vcard_init(void); +char *serv_fulltext_init(void); /* */ diff --git a/citadel/serv_fulltext.c b/citadel/serv_fulltext.c index 0cbcd2e24..6597988b6 100644 --- a/citadel/serv_fulltext.c +++ b/citadel/serv_fulltext.c @@ -40,12 +40,60 @@ #include "database.h" #include "msgbase.h" #include "control.h" +#include "room_ops.h" #include "tools.h" #include "serv_fulltext.h" #include "ft_wordbreaker.h" +long ft_newhighest = 0L; +long *ft_newmsgs = NULL; +int ft_num_msgs = 0; +int ft_num_alloc = 0; + + +void ft_index_msg(long msgnum, void *userdata) { + + if ((msgnum > CitControl.MMfulltext) && (msgnum <= ft_newhighest)) { + ++ft_num_msgs; + if (ft_num_msgs > ft_num_alloc) { + ft_num_alloc += 1024; + ft_newmsgs = realloc(ft_newmsgs, (ft_num_alloc * sizeof(long))); + } + ft_newmsgs[ft_num_msgs - 1] = msgnum; + } + +} + +/* + * Scan a room for messages to index. + */ +void ft_index_room(struct ctdlroom *qrbuf, void *data) +{ + getroom(&CC->room, qrbuf->QRname); + CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, ft_index_msg, NULL); +} + + +/* + * Compare function + */ +int longcmp(const void *rec1, const void *rec2) { + long i1, i2; + + i1 = *(const long *)rec1; + i2 = *(const long *)rec2; + + if (i1 > i2) return(1); + if (i1 < i2) return(-1); + return(0); +} + + + void do_fulltext_indexing(void) { + int i; + lprintf(CTDL_DEBUG, "do_fulltext_indexing() started\n"); /* @@ -58,12 +106,41 @@ void do_fulltext_indexing(void) { lprintf(CTDL_DEBUG, "Nothing to do!\n"); return; } + + /* + * Make sure we don't run the indexer too frequently. + * FIXME write this... + */ /* * If we've switched wordbreaker modules, burn the index and start * over. FIXME write this... */ + /* + * Now go through each room and find messages to index. + */ + ft_newhighest = CitControl.MMhighest; + ForEachRoom(ft_index_room, NULL); /* merge ptrs */ + + if (ft_num_msgs > 0) { + qsort(ft_newmsgs, ft_num_msgs, sizeof(long), longcmp); /* sort */ + if (i>1) 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)*sizeof(long))); + --ft_num_msgs; + } + } + + /* Here it is ... do each message! */ + for (i=0; i