stable now but there are GIANT PIECES MISSING
[citadel.git] / citadel / modules / fulltext / serv_fulltext.c
index 40645a294b7cdb4eb2e5dba6226adf24f7f91169..dc5b2b15c7e95e6a6808b4fc86b029190315d1b3 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This module handles fulltext indexing of the message base.
- * Copyright (c) 2005-2017 by the citadel.org team
+ * Copyright (c) 2005-2021 by the citadel.org team
  *
  * This program is open source software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as published
 #include <pwd.h>
 #include <errno.h>
 #include <sys/types.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
+#include <time.h>
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
@@ -80,6 +69,7 @@ int longcmp(const void *rec1, const void *rec2) {
        return(0);
 }
 
+
 /*
  * Flush our index cache out to disk.
  */
@@ -120,7 +110,7 @@ void ft_index_message(long msgnum, int op) {
        int tok;
        struct CtdlMessage *msg = NULL;
 
-       msg = CtdlFetchMessage(msgnum, 1, 1);
+       msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) {
                syslog(LOG_ERR, "fulltext: ft_index_message() could not load msg %ld", msgnum);
                return;
@@ -204,7 +194,6 @@ void ft_index_message(long msgnum, int op) {
 }
 
 
-
 /*
  * Add a message to the list of those to be indexed.
  */
@@ -214,14 +203,14 @@ void ft_index_msg(long msgnum, void *userdata) {
                ++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 = realloc(ft_newmsgs, (ft_num_alloc * sizeof(long)));
                }
                ft_newmsgs[ft_num_msgs - 1] = msgnum;
        }
 
 }
 
+
 /*
  * Scan a room for messages to index.
  */
@@ -240,7 +229,6 @@ void ft_index_room(struct ctdlroom *qrbuf, void *data)
  */
 void do_fulltext_indexing(void) {
        int i;
-       static time_t last_index = 0L;
        static time_t last_progress = 0L;
        static int is_running = 0;
        if (is_running) return;         /* Concurrency check - only one can run */
@@ -254,33 +242,7 @@ void do_fulltext_indexing(void) {
        }
 
        /*
-        * Make sure we don't run the indexer too frequently.
-        * FIXME move the setting into config
-        */
-       time_t now = time(NULL);
-       if ( (now - last_index) < 300L) {
-               syslog(LOG_DEBUG,
-                       "fulltext: indexing interval not yet reached; last run was %ldm%lds ago",
-                       ((now - last_index) / 60),
-                       ((now - last_index) % 60)
-               );
-               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! */
-       }
-       
-       /*
-        * If we've switched wordbreaker modules, burn the index and start
-        * over.
+        * 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) {
@@ -293,6 +255,13 @@ void do_fulltext_indexing(void) {
        }
        end_critical_section(S_CONTROL);
 
+       /*
+        * Silently return if our fulltext index is up to date with new messages.
+        */
+       if ((CtdlGetConfigLong("MMfulltext") >= CtdlGetConfigLong("MMhighest"))) {
+               return;         /* nothing to do! */
+       }
+
        /*
         * Now go through each room and find messages to index.
         */
@@ -355,7 +324,6 @@ void do_fulltext_indexing(void) {
        CtdlSetConfigLong("MMfulltext", ft_newhighest);
        CtdlSetConfigInt("MM_fulltext_wordbreaker", FT_WORDBREAKER_ID);
        end_critical_section(S_CONTROL);
-       last_index = time(NULL);
 
        syslog(LOG_DEBUG, "fulltext: indexing finished");
        is_running = 0;
@@ -363,7 +331,6 @@ void do_fulltext_indexing(void) {
 }
 
 
-
 /*
  * API call to perform searches.
  * (This one does the "all of these words" search.)
@@ -473,6 +440,7 @@ void cmd_srch(char *argbuf) {
        cprintf("000\n");
 }
 
+
 /*
  * Zero out our index cache.
  */
@@ -492,6 +460,7 @@ void ft_delete_remove(char *room, long msgnum)
        }
 }
 
+
 /*****************************************************************************/
 
 CTDL_MODULE_INIT(fulltext)
@@ -499,11 +468,9 @@ CTDL_MODULE_INIT(fulltext)
        if (!threading)
        {
                initialize_ft_cache();
-               initialize_noise_words();
                CtdlRegisterProtoHook(cmd_srch, "SRCH", "Full text search");
                CtdlRegisterDeleteHook(ft_delete_remove);
                CtdlRegisterSearchFuncHook(ft_search, "fulltext");
-               CtdlRegisterCleanupHook(noise_word_cleanup);
                CtdlRegisterSessionHook(do_fulltext_indexing, EVT_TIMER, PRIO_CLEANUP + 300);
        }
        /* return our module name for the log */