From 930dc6cb6381b5c8d23afc52554b7fd9f2cd8b2e Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 30 Aug 2023 23:13:11 -0400 Subject: [PATCH] search function is complete --- citadel/server/ctdl_module.h | 2 +- .../server/modules/fulltext/serv_fulltext.c | 118 ++++++++---------- .../server/modules/fulltext/serv_fulltext.h | 24 +--- citadel/server/serv_extensions.c | 5 +- 4 files changed, 63 insertions(+), 86 deletions(-) diff --git a/citadel/server/ctdl_module.h b/citadel/server/ctdl_module.h index 51470ddae..54c8ed61b 100644 --- a/citadel/server/ctdl_module.h +++ b/citadel/server/ctdl_module.h @@ -142,7 +142,7 @@ void CtdlUnregisterServiceHook(int tcp_port, void CtdlRegisterFixedOutputHook(char *content_type, void (*output_function) (char *supplied_data, int len)); void CtdlUnRegisterFixedOutputHook(char *content_type); void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg)); -void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name); +void CtdlRegisterSearchFuncHook(Array (*)(const char *), char *name); /* * if you say a) (which may take a while) diff --git a/citadel/server/modules/fulltext/serv_fulltext.c b/citadel/server/modules/fulltext/serv_fulltext.c index caa5f17e7..167e050d4 100644 --- a/citadel/server/modules/fulltext/serv_fulltext.c +++ b/citadel/server/modules/fulltext/serv_fulltext.c @@ -116,7 +116,15 @@ void ft_index_message(long msgnum, int op) { if (op == 1) { // indexing, add this message to the bucket memcpy(&newbucket[0], cdb_bucket.ptr, cdb_bucket.len); - memcpy(&newbucket[nmsgs++], &msgnum, sizeof(long)); + int already_there = 0; + for (j=0; j 0) { - for (i=0; i 0)) { + for (i=0; i 0) { - all_msgs = realloc(all_msgs, num_all_msgs*sizeof(long) ); - memcpy(&all_msgs[num_all_msgs-ftc_num_msgs[tok]], ftc_msgs[tok], ftc_num_msgs[tok]*sizeof(long) ); + // We need to return any message containing ALL of the tokens. + // If a message number appears in the array `n` times, where `n` is the number of search words, + // that means it matched all search words. + array_sort(r, longcmp); + for (i=0; i= array_len(t)) - for (j=0; j<(num_all_msgs-array_len(t)+1); ++j) { - if (all_msgs[j] == all_msgs[j+array_len(t)-1]) { - ++num_ret_msgs; - if (num_ret_msgs > num_ret_alloc) { - num_ret_alloc += 64; - ret_msgs = realloc(ret_msgs, (num_ret_alloc*sizeof(long)) ); - } - ret_msgs[num_ret_msgs - 1] = all_msgs[j]; - - } - } - free(all_msgs); + if (count != array_len(t)) { + array_delete_element_at(r, i); + --i; } } - *fts_num_msgs = num_ret_msgs; - *fts_msgs = ret_msgs; -#endif + array_free(t); + return(r); } // This search command is for diagnostic purposes and may be removed or replaced. void cmd_srch(char *argbuf) { - int num_msgs = 0; - long *msgs = NULL; int i; - char search_string[256]; + char search_string[SIZ]; + Array *matches = NULL; + long msgnum; if (CtdlAccessCheck(ac_logged_in)) return; @@ -324,15 +313,18 @@ void cmd_srch(char *argbuf) { } extract_token(search_string, argbuf, 0, '|', sizeof search_string); - ft_search(&num_msgs, &msgs, search_string); + matches = ft_search(search_string); - cprintf("%d %d msgs match all search words:\n", LISTING_FOLLOWS, num_msgs); - if (num_msgs > 0) { - for (i=0; i 0)) { + for (i=0; inext = SearchFunctionHookTable; newfcn->name = name; newfcn->fcn_ptr = fcn_ptr; -- 2.39.2