$Log$
+ Revision 647.9 2005/05/18 04:02:54 ajc
+ * Completed the "search for all of these words" functionality. All we need
+ to do now is genericize its calling syntax so it can be called from the
+ IMAP service.
+
Revision 647.8 2005/05/18 03:22:27 ajc
* Finished the indexer and the first part of the search function...
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
+
struct cdbdata *cdb_bucket;
int num_msgs;
long *msgs;
+ int num_all_msgs = 0;
+ long *all_msgs = NULL;
if (CtdlAccessCheck(ac_logged_in)) return;
extract_token(search_string, argbuf, 0, '|', sizeof search_string);
if (cdb_bucket != NULL) {
num_msgs = cdb_bucket->len / sizeof(long);
msgs = (long *)cdb_bucket->ptr;
- for (j=0; j<num_msgs; ++j) {
- cprintf("Token <%d> is in msg <%ld>\n", tokens[i], msgs[j]);
- }
+
+ num_all_msgs += num_msgs;
+ all_msgs = realloc(all_msgs, num_all_msgs*sizeof(long) );
+ memcpy(&all_msgs[num_all_msgs - num_msgs], msgs, num_msgs*sizeof(long) );
+
cdb_free(cdb_bucket);
}
}
free(tokens);
+ qsort(all_msgs, num_all_msgs, sizeof(long), longcmp);
+
+ /*
+ * At this point, if a message appears num_tokens 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]) {
+ cprintf("%ld\n", all_msgs[j]);
+ }
+ }
+
+ free(all_msgs);
}
cprintf("000\n");
}