// 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;
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
}
}
- free(tokens);
+ array_free(t);
}
}
// (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;
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) {
}
}
- 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;