]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/modules/fulltext/serv_fulltext.c
serv_fulltext: wordbreaker now returns a libcitadel Array
[citadel.git] / citadel / server / modules / fulltext / serv_fulltext.c
index 4f04baad649f300a9fca3d1b4d5f331b4171f480..c71232e082b123a2c2849f8b5296631253fe19e1 100644 (file)
@@ -80,9 +80,8 @@ void ft_flush_cache(void) {
 
 // Index or de-index a message.  (op == 1 to index, 0 to de-index)
 void ft_index_message(long msgnum, int op) {
-       int num_tokens = 0;
-       int *tokens = NULL;
        int i, j;
+       Array *t = NULL;
        struct cdbdata cdb_bucket;
        StrBuf *msgtext;
        char *txt;
@@ -114,17 +113,17 @@ void ft_index_message(long msgnum, int op) {
                syslog(LOG_DEBUG, "fulltext: wordbreaking message %ld (%d bytes)", msgnum, StrLength(msgtext));
        }
        txt = SmashStrBuf(&msgtext);
-       wordbreaker(txt, &num_tokens, &tokens);
+       t = wordbreaker(txt);
        free(txt);
 
-       syslog(LOG_DEBUG, "fulltext: %sindexing message %ld [%d tokens]", (op ? "" : "de"), msgnum, num_tokens);
-       if (num_tokens > 0) {
-               for (i=0; i<num_tokens; ++i) {
+       syslog(LOG_DEBUG, "fulltext: %sindexing message %ld [%d tokens]", (op ? "" : "de"), msgnum, array_len(t));
+       if (array_len(t) > 0) {
+               for (i=0; i<array_len(t); ++i) {
 
                        // Add the message to the relevant token bucket
 
                        // search for tokens[i]
-                       tok = tokens[i];
+                       memcpy(&tok, array_get_element_at(t, i), sizeof(int));
 
                        if ( (tok >= 0) && (tok <= 65535) ) {
                                // fetch the bucket, Liza
@@ -164,7 +163,7 @@ void ft_index_message(long msgnum, int op) {
                        }
                }
 
-               free(tokens);
+               array_free(t);
        }
 }
 
@@ -291,8 +290,7 @@ void do_fulltext_indexing(void) {
 // (This one does the "all of these words" search.)
 // Caller is responsible for freeing the message list.
 void ft_search(int *fts_num_msgs, long **fts_msgs, const char *search_string) {
-       int num_tokens = 0;
-       int *tokens = NULL;
+       Array *t = NULL;
        int i, j;
        struct cdbdata cdb_bucket;
        int num_all_msgs = 0;
@@ -302,12 +300,12 @@ void ft_search(int *fts_num_msgs, long **fts_msgs, const char *search_string) {
        long *ret_msgs = NULL;
        int tok;
 
-       wordbreaker(search_string, &num_tokens, &tokens);
-       if (num_tokens > 0) {
-               for (i=0; i<num_tokens; ++i) {
+       t = wordbreaker(search_string);
+       if (array_len(t) > 0) {
+               for (i=0; i<array_len(t); ++i) {
 
                        // search for tokens[i]
-                       tok = tokens[i];
+                       memcpy(&tok, array_get_element_at(t, i), sizeof(int));
 
                        // fetch the bucket, Liza
                        if (ftc_msgs[tok] == NULL) {
@@ -330,15 +328,15 @@ void ft_search(int *fts_num_msgs, long **fts_msgs, const char *search_string) {
                        }
 
                }
-               free(tokens);
+               array_free(t);
                if (all_msgs != NULL) {
                        qsort(all_msgs, num_all_msgs, sizeof(long), longcmp);
 
-                       // At this point, if a message appears num_tokens times in the
+                       // At this point, if a message appears array_len(t) times in the
                        // list, then it contains all of the search tokens.
-                       if (num_all_msgs >= num_tokens)
-                               for (j=0; j<(num_all_msgs-num_tokens+1); ++j) {
-                                       if (all_msgs[j] == all_msgs[j+num_tokens-1]) {
+                       if (num_all_msgs >= 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;