No more search hooks. Modules can call each other now and that's a lot simpler.
We also eliminated the index cache, because it made things a lot more complex, and
a modern database is going to mmap most of the index as it gets used anyway.
#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
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);
// 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
// API call to perform searches.
// (This one does the "all of these words" search.)
// Caller is responsible for freeing the message list.
-Array *ft_search(const char *search_string) {
+Array *CtdlFullTextSearch(const char *search_string) {
int i, j, tok;
struct cdbdata cdb_bucket;
long msgnum, smsgnum;
}
extract_token(search_string, argbuf, 0, '|', sizeof search_string);
- matches = ft_search(search_string);
+ matches = CtdlFullTextSearch(search_string);
cprintf("%d %d msgs match all search words:\n", LISTING_FOLLOWS, array_len(matches));
if ((matches != NULL) && (array_len(matches) > 0)) {
if (!threading) {
CtdlRegisterProtoHook(cmd_srch, "SRCH", "Full text search");
CtdlRegisterDeleteHook(ft_delete_remove);
- //CtdlRegisterSearchFuncHook(ft_search, "fulltext");
CtdlRegisterSessionHook(do_fulltext_indexing, EVT_TIMER, PRIO_CLEANUP + 300);
}
// return our module name for the log
// is subject to the terms of the GNU General Public License, version 3.
void ft_index_message(long msgnum, int op);
-Array *ft_search(const char *search_string);
+Array *CtdlFullTextSearch(const char *search_string);
*/
#include "../../ctdl_module.h"
-
-
#include "../../sysdep.h"
#include <stdlib.h>
#include <unistd.h>
#include "imap_fetch.h"
#include "imap_search.h"
#include "../../genstamp.h"
+#include "../fulltext/serv_fulltext.h"
/*
void imap_do_search(int num_items, ConstStr *itemlist, int is_uid) {
citimap *Imap = IMAP;
int i, j, k;
- int fts_num_msgs = 0;
- long *fts_msgs = NULL;
int is_in_list = 0;
int num_results = 0;
+ Array *fts = NULL;
/* Strip parentheses. We realize that this method will not work
* in all cases, but it seems to work with all currently available
*/
if (CtdlGetConfigInt("c_enable_fulltext")) for (i=0; i<(num_items-1); ++i) {
if (!strcasecmp(itemlist[i].Key, "BODY")) {
- CtdlModuleDoSearch(&fts_num_msgs, &fts_msgs, itemlist[i+1].Key, "fulltext");
- if (fts_num_msgs > 0) {
+ fts = CtdlFullTextSearch(itemlist[i+1].Key);
+ if ((fts) && (array_len(fts) > 0)) {
for (j=0; j < Imap->num_msgs; ++j) {
if (Imap->flags[j] & IMAP_SELECTED) {
is_in_list = 0;
- for (k=0; k<fts_num_msgs; ++k) {
- if (Imap->msgids[j] == fts_msgs[k]) {
+ for (k=0; k<array_len(fts); ++k) {
+ long smsgnum;
+ memcpy(&smsgnum, array_get_element_at(fts, k), sizeof(long));
+ if (Imap->msgids[j] == smsgnum) {
++is_in_list;
}
}
Imap->flags[j] = Imap->flags[j] & ~IMAP_SELECTED;
}
}
- if (fts_msgs) {
- free(fts_msgs);
+ if (fts) {
+ array_free(fts);
}
}
}
#include "euidindex.h"
#include "msgbase.h"
#include "journaling.h"
+#include "modules/fulltext/serv_fulltext.h"
struct addresses_to_be_filed *atbf = NULL;
int is_seen = 0;
long lastold = 0L;
int printed_lastold = 0;
- int num_search_msgs = 0;
- long *search_msgs = NULL;
regex_t re;
int need_to_free_re = 0;
regmatch_t pm;
+ Array *search = NULL;
if ((content_type) && (!IsEmptyStr(content_type))) {
regcomp(&re, content_type, 0);
* NULL means use any search function available.
* otherwise replace with a char * to name of search routine
*/
- CtdlModuleDoSearch(search_string, "fulltext");
- //FIXME FOOFOO DO ARRAY
+ search = CtdlFullTextSearch(search_string);
- if (num_search_msgs > 0) {
+ if (array_len(search) > 0) {
int orig_num_msgs;
orig_num_msgs = num_msgs;
num_msgs = 0;
for (i=0; i<orig_num_msgs; ++i) {
- for (j=0; j<num_search_msgs; ++j) {
- if (msglist[i] == search_msgs[j]) {
+ for (j=0; j<array_len(search); ++j) {
+ long smsgnum;
+ memcpy(&smsgnum, array_get_element_at(search, j), sizeof(long));
+ if (msglist[i] == smsgnum) {
msglist[num_msgs++] = msglist[i];
}
}
else {
num_msgs = 0; /* No messages qualify */
}
- if (search_msgs != NULL) free(search_msgs);
+ if (search != NULL) array_free(search);
/* Now that we've purged messages which don't contain the search
* string, treat a MSGS_SEARCH just like a MSGS_ALL from this