]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/modules/autocompletion/serv_autocompletion.c
dammit, learn to spell
[citadel.git] / citadel / server / modules / autocompletion / serv_autocompletion.c
index 3f025521fe76b4250c3d8851ddf68671758a7ac5..413bf472b739920999baeff92ae7e3768206cecb 100644 (file)
@@ -3,12 +3,13 @@
 // Copyright (c) 1987-2023 by the citadel.org team
 //
 // This program is open source software.  Use, duplication, or disclosure
-// are subject to the terms of the GNU General Public License version 3.
+// is subject to the terms of the GNU General Public License version 3.
 
 #include "../../ctdl_module.h"
 #include "serv_autocompletion.h"
 #include "../../config.h"
 #include "../../room_ops.h"
+#include "../fulltext/serv_fulltext.h"
 
 
 // Convert a structured name into a friendly name.  Caller must free the
@@ -49,7 +50,7 @@ void hunt_for_autocomplete(long msgnum, char *search_string) {
        msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) return;
 
-       v = vcard_load(msg->cm_fields[eMesageText]);
+       v = vcard_load(msg->cm_fields[eMessageText]);
        CM_Free(msg);
 
        // Try to match from a friendly name (the "fn" field).  If there is
@@ -109,13 +110,12 @@ void cmd_auto(char *argbuf) {
        char search_string[256];
        long *msglist = NULL;
        int num_msgs = 0;
-       long *fts_msgs = NULL;
-       int fts_num_msgs = 0;
        int r = 0;
        int i = 0;
        int j = 0;
        int search_match = 0;
        char *rooms_to_try[] = { USERCONTACTSROOM, ADDRESS_BOOK_ROOM };
+       Array *fts = NULL;
                
        if (CtdlAccessCheck(ac_logged_in)) return;
        extract_token(search_string, argbuf, 0, '|', sizeof search_string);
@@ -134,21 +134,23 @@ void cmd_auto(char *argbuf) {
 
                        // Search-reduce the results if we have the full text index available
                        if (CtdlGetConfigInt("c_enable_fulltext")) {
-                               CtdlModuleDoSearch(&fts_num_msgs, &fts_msgs, search_string, "fulltext");
-                               if (fts_msgs) {
+                               fts = CtdlFullTextSearch(search_string);
+                               if (fts) {
                                        for (i=0; i<num_msgs; ++i) {
                                                search_match = 0;
-                                               for (j=0; j<fts_num_msgs; ++j) {
-                                                       if (msglist[i] == fts_msgs[j]) {
+                                               for (j=0; j<array_len(fts); ++j) {
+                                                       long smsgnum;
+                                                       memcpy(&smsgnum, array_get_element_at(fts, j), sizeof(long));
+                                                       if (msglist[i] == smsgnum) {
                                                                search_match = 1;
-                                                               j = fts_num_msgs + 1;   // end the search 
+                                                               j = array_len(fts) + 1; // end the search 
                                                        }
                                                }
                                                if (!search_match) {
                                                        msglist[i] = 0;                 // invalidate this result
                                                }
                                        }
-                                       free(fts_msgs);
+                                       array_free(fts);
                                }
                                else {
                                        // If no results, invalidate the whole list