"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "modules/fulltext/serv_fulltext.c" between
citadel-9.01.tar.gz and citadel-902.tar.gz

About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).

serv_fulltext.c  (citadel-9.01):serv_fulltext.c  (citadel-902)
/* /*
* This module handles fulltext indexing of the message base. * This module handles fulltext indexing of the message base.
* Copyright (c) 2005-2011 by the citadel.org team * Copyright (c) 2005-2015 by the citadel.org team
* *
* This program is open source software; you can redistribute it and/or * 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 * modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 3 of the License, or * by the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
skipping to change at line 121 skipping to change at line 121
void ft_index_message(long msgnum, int op) { void ft_index_message(long msgnum, int op) {
int num_tokens = 0; int num_tokens = 0;
int *tokens = NULL; int *tokens = NULL;
int i, j; int i, j;
struct cdbdata *cdb_bucket; struct cdbdata *cdb_bucket;
StrBuf *msgtext; StrBuf *msgtext;
char *txt; char *txt;
int tok; int tok;
struct CtdlMessage *msg = NULL; struct CtdlMessage *msg = NULL;
msg = CtdlFetchMessage(msgnum, 1); msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) { if (msg == NULL) {
syslog(LOG_ERR, "ft_index_message() could not load msg %ld", msgn um); syslog(LOG_ERR, "ft_index_message() could not load msg %ld", msgn um);
return; return;
} }
if (!CM_IsEmpty(msg, eSuppressIdx)) { if (!CM_IsEmpty(msg, eSuppressIdx)) {
syslog(LOG_DEBUG, "ft_index_message() excluded msg %ld", msgnum); syslog(LOG_DEBUG, "ft_index_message() excluded msg %ld", msgnum);
CM_Free(msg); CM_Free(msg);
return; return;
} }
skipping to change at line 208 skipping to change at line 208
free(tokens); free(tokens);
} }
} }
/* /*
* Add a message to the list of those to be indexed. * Add a message to the list of those to be indexed.
*/ */
void ft_index_msg(long msgnum, void *userdata) { void ft_index_msg(long msgnum, void *userdata) {
if ((msgnum > CitControl.MMfulltext) && (msgnum <= ft_newhighest)) { if ((msgnum > CtdlGetConfigLong("MMfulltext")) && (msgnum <= ft_newhighes t)) {
++ft_num_msgs; ++ft_num_msgs;
if (ft_num_msgs > ft_num_alloc) { if (ft_num_msgs > ft_num_alloc) {
ft_num_alloc += 1024; ft_num_alloc += 1024;
ft_newmsgs = realloc(ft_newmsgs, ft_newmsgs = realloc(ft_newmsgs,
(ft_num_alloc * sizeof(long))); (ft_num_alloc * sizeof(long)));
} }
ft_newmsgs[ft_num_msgs - 1] = msgnum; ft_newmsgs[ft_num_msgs - 1] = msgnum;
} }
} }
skipping to change at line 248 skipping to change at line 248
static time_t last_progress = 0L; static time_t last_progress = 0L;
time_t run_time = 0L; time_t run_time = 0L;
time_t end_time = 0L; time_t end_time = 0L;
static int is_running = 0; static int is_running = 0;
if (is_running) return; /* Concurrency check - only one can run * / if (is_running) return; /* Concurrency check - only one can run * /
is_running = 1; is_running = 1;
/* /*
* Don't do this if the site doesn't have it enabled. * Don't do this if the site doesn't have it enabled.
*/ */
if (!config.c_enable_fulltext) { if (!CtdlGetConfigInt("c_enable_fulltext")) {
return; return;
} }
/* /*
* Make sure we don't run the indexer too frequently. * Make sure we don't run the indexer too frequently.
* FIXME move the setting into config * FIXME move the setting into config
*/ */
if ( (time(NULL) - last_index) < 300L) { if ( (time(NULL) - last_index) < 300L) {
return; return;
} }
/* /*
* Check to see whether the fulltext index is up to date; if there * 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. * are no messages to index, don't waste any more time trying.
*/ */
if ((CitControl.MMfulltext >= CitControl.MMhighest) && (CitControl.fullte if (
xt_wordbreaker == FT_WORDBREAKER_ID)) { (CtdlGetConfigLong("MMfulltext") >= CtdlGetConfigLong("MMhighest"
))
&& (CtdlGetConfigInt("MM_fulltext_wordbreaker") == FT_WORDBREAKER
_ID)
) {
return; /* nothing to do! */ return; /* nothing to do! */
} }
run_time = time(NULL); run_time = time(NULL);
syslog(LOG_DEBUG, "do_fulltext_indexing() started (%ld)", run_time); syslog(LOG_DEBUG, "do_fulltext_indexing() started (%ld)", run_time);
/* /*
* If we've switched wordbreaker modules, burn the index and start * If we've switched wordbreaker modules, burn the index and start
* over. * over.
*/ */
begin_critical_section(S_CONTROL); begin_critical_section(S_CONTROL);
if (CitControl.fulltext_wordbreaker != FT_WORDBREAKER_ID) { if (CtdlGetConfigInt("MM_fulltext_wordbreaker") != FT_WORDBREAKER_ID) {
syslog(LOG_DEBUG, "wb ver on disk = %d, code ver = %d", syslog(LOG_DEBUG, "wb ver on disk = %d, code ver = %d",
CitControl.fulltext_wordbreaker, FT_WORDBREAKER_ID CtdlGetConfigInt("MM_fulltext_wordbreaker"), FT_WORDBREAK ER_ID
); );
syslog(LOG_INFO, "(re)initializing full text index"); syslog(LOG_INFO, "(re)initializing full text index");
cdb_trunc(CDB_FULLTEXT); cdb_trunc(CDB_FULLTEXT);
CitControl.MMfulltext = 0L; CtdlSetConfigLong("MMfulltext", 0);
put_control();
} }
end_critical_section(S_CONTROL); end_critical_section(S_CONTROL);
/* /*
* Now go through each room and find messages to index. * Now go through each room and find messages to index.
*/ */
ft_newhighest = CitControl.MMhighest; ft_newhighest = CtdlGetConfigLong("MMhighest");
CtdlForEachRoom(ft_index_room, NULL); /* load all msg pointers */ CtdlForEachRoom(ft_index_room, NULL); /* load all msg pointers */
if (ft_num_msgs > 0) { if (ft_num_msgs > 0) {
qsort(ft_newmsgs, ft_num_msgs, sizeof(long), longcmp); qsort(ft_newmsgs, ft_num_msgs, sizeof(long), longcmp);
for (i=0; i<(ft_num_msgs-1); ++i) { /* purge dups */ for (i=0; i<(ft_num_msgs-1); ++i) { /* purge dups */
if (ft_newmsgs[i] == ft_newmsgs[i+1]) { if (ft_newmsgs[i] == ft_newmsgs[i+1]) {
memmove(&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 - 1)*sizeof(long)));
--ft_num_msgs; --ft_num_msgs;
--i; --i;
skipping to change at line 350 skipping to change at line 352
if (server_shutting_down) { if (server_shutting_down) {
is_running = 0; is_running = 0;
return; return;
} }
syslog(LOG_DEBUG, "do_fulltext_indexing() duration (%ld)", end_time - run _time); syslog(LOG_DEBUG, "do_fulltext_indexing() duration (%ld)", end_time - run _time);
/* Save our place so we don't have to do this again */ /* Save our place so we don't have to do this again */
ft_flush_cache(); ft_flush_cache();
begin_critical_section(S_CONTROL); begin_critical_section(S_CONTROL);
CitControl.MMfulltext = ft_newhighest; CtdlSetConfigLong("MMfulltext", ft_newhighest);
CitControl.fulltext_wordbreaker = FT_WORDBREAKER_ID; CtdlSetConfigInt("MM_fulltext_wordbreaker", FT_WORDBREAKER_ID);
put_control();
end_critical_section(S_CONTROL); end_critical_section(S_CONTROL);
last_index = time(NULL); last_index = time(NULL);
syslog(LOG_DEBUG, "do_fulltext_indexing() finished"); syslog(LOG_DEBUG, "do_fulltext_indexing() finished");
is_running = 0; is_running = 0;
return; return;
} }
/* /*
* API call to perform searches. * API call to perform searches.
skipping to change at line 449 skipping to change at line 450
* This search command is for diagnostic purposes and may be removed or replaced . * This search command is for diagnostic purposes and may be removed or replaced .
*/ */
void cmd_srch(char *argbuf) { void cmd_srch(char *argbuf) {
int num_msgs = 0; int num_msgs = 0;
long *msgs = NULL; long *msgs = NULL;
int i; int i;
char search_string[256]; char search_string[256];
if (CtdlAccessCheck(ac_logged_in)) return; if (CtdlAccessCheck(ac_logged_in)) return;
if (!config.c_enable_fulltext) { if (!CtdlGetConfigInt("c_enable_fulltext")) {
cprintf("%d Full text index is not enabled on this server.\n", cprintf("%d Full text index is not enabled on this server.\n",
ERROR + CMD_NOT_SUPPORTED); ERROR + CMD_NOT_SUPPORTED);
return; return;
} }
extract_token(search_string, argbuf, 0, '|', sizeof search_string); extract_token(search_string, argbuf, 0, '|', sizeof search_string);
ft_search(&num_msgs, &msgs, search_string); ft_search(&num_msgs, &msgs, search_string);
cprintf("%d %d msgs match all search words:\n", cprintf("%d %d msgs match all search words:\n",
LISTING_FOLLOWS, num_msgs); LISTING_FOLLOWS, num_msgs);
skipping to change at line 482 skipping to change at line 483
void initialize_ft_cache(void) { void initialize_ft_cache(void) {
memset(ftc_num_msgs, 0, (65536 * sizeof(int))); memset(ftc_num_msgs, 0, (65536 * sizeof(int)));
memset(ftc_msgs, 0, (65536 * sizeof(long *))); memset(ftc_msgs, 0, (65536 * sizeof(long *)));
} }
void ft_delete_remove(char *room, long msgnum) void ft_delete_remove(char *room, long msgnum)
{ {
if (room) return; if (room) return;
/* Remove from fulltext index */ /* Remove from fulltext index */
if (config.c_enable_fulltext) { if (CtdlGetConfigInt("c_enable_fulltext")) {
ft_index_message(msgnum, 0); ft_index_message(msgnum, 0);
} }
} }
/*****************************************************************************/ /*****************************************************************************/
CTDL_MODULE_INIT(fulltext) CTDL_MODULE_INIT(fulltext)
{ {
if (!threading) if (!threading)
{ {
 End of changes. 12 change blocks. 
16 lines changed or deleted 18 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS