mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
notmuch-index-message: Fix handling of thread_id terms.
We now emit one term per thread_id, rather than the comma-separated super-term we were doing previously.
This commit is contained in:
parent
535b14dcba
commit
736bad40ac
1 changed files with 41 additions and 22 deletions
|
@ -277,18 +277,25 @@ insert_thread_id (GHashTable *thread_ids, Xapian::Document doc)
|
||||||
g_hash_table_insert (thread_ids, strdup (value), NULL);
|
g_hash_table_insert (thread_ids, strdup (value), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
/* Return one or more thread_ids, (as a GPtrArray of strings), for the
|
||||||
find_thread_id (Xapian::Database db,
|
* given message based on looking into the database for any messages
|
||||||
GPtrArray *parents,
|
* referenced in parents, and also for any messages in the database
|
||||||
const char *message_id)
|
* referencing message_id.
|
||||||
|
*
|
||||||
|
* Caller should free all strings in the array and the array itself,
|
||||||
|
* (g_ptr_array_free) when done. */
|
||||||
|
static GPtrArray *
|
||||||
|
find_thread_ids (Xapian::Database db,
|
||||||
|
GPtrArray *parents,
|
||||||
|
const char *message_id)
|
||||||
{
|
{
|
||||||
Xapian::PostingIterator child, children_end;
|
Xapian::PostingIterator child, children_end;
|
||||||
Xapian::Document doc;
|
Xapian::Document doc;
|
||||||
GHashTable *thread_ids;
|
GHashTable *thread_ids;
|
||||||
GList *keys, *l;
|
GList *keys, *l;
|
||||||
GString *result = NULL;
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
const char *parent_message_id;
|
const char *parent_message_id;
|
||||||
|
GPtrArray *result;
|
||||||
|
|
||||||
thread_ids = g_hash_table_new (g_str_hash, g_str_equal);
|
thread_ids = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
|
|
||||||
|
@ -304,21 +311,15 @@ find_thread_id (Xapian::Database db,
|
||||||
insert_thread_id (thread_ids, doc);
|
insert_thread_id (thread_ids, doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = g_ptr_array_new ();
|
||||||
|
|
||||||
keys = g_hash_table_get_keys (thread_ids);
|
keys = g_hash_table_get_keys (thread_ids);
|
||||||
for (l = keys; l; l = l->next) {
|
for (l = keys; l; l = l->next) {
|
||||||
char *id = (char *) l->data;
|
char *id = (char *) l->data;
|
||||||
if (result == NULL) {
|
g_ptr_array_add (result, id);
|
||||||
result = g_string_new (id);
|
|
||||||
} else {
|
|
||||||
g_string_append_printf (result, ",%s", id);
|
|
||||||
}
|
|
||||||
free (id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result)
|
return result;
|
||||||
return g_string_free (result, FALSE);
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a term for each message-id in the References header of the
|
/* Add a term for each message-id in the References header of the
|
||||||
|
@ -440,12 +441,12 @@ index_file (Xapian::WritableDatabase db,
|
||||||
GMimeParser *parser;
|
GMimeParser *parser;
|
||||||
GMimeMessage *message;
|
GMimeMessage *message;
|
||||||
InternetAddressList *addresses;
|
InternetAddressList *addresses;
|
||||||
GPtrArray *parents;
|
GPtrArray *parents, *thread_ids;
|
||||||
|
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
const char *subject, *refs, *in_reply_to, *from;
|
const char *subject, *refs, *in_reply_to, *from;
|
||||||
const char *message_id, *thread_id;
|
const char *message_id;
|
||||||
|
|
||||||
time_t time;
|
time_t time;
|
||||||
struct tm gm_time_tm;
|
struct tm gm_time_tm;
|
||||||
|
@ -501,7 +502,7 @@ index_file (Xapian::WritableDatabase db,
|
||||||
|
|
||||||
message_id = g_mime_message_get_message_id (message);
|
message_id = g_mime_message_get_message_id (message);
|
||||||
|
|
||||||
thread_id = find_thread_id (db, parents, message_id);
|
thread_ids = find_thread_ids (db, parents, message_id);
|
||||||
|
|
||||||
for (i = 0; i < parents->len; i++)
|
for (i = 0; i < parents->len; i++)
|
||||||
g_free (g_ptr_array_index (parents, i));
|
g_free (g_ptr_array_index (parents, i));
|
||||||
|
@ -536,10 +537,28 @@ index_file (Xapian::WritableDatabase db,
|
||||||
add_term (doc, "msgid", message_id);
|
add_term (doc, "msgid", message_id);
|
||||||
doc.add_value (NOTMUCH_VALUE_MESSAGE_ID, message_id);
|
doc.add_value (NOTMUCH_VALUE_MESSAGE_ID, message_id);
|
||||||
|
|
||||||
if (thread_id) {
|
if (thread_ids->len) {
|
||||||
add_term (doc, "thread", thread_id);
|
unsigned int i;
|
||||||
doc.add_value (NOTMUCH_VALUE_THREAD, thread_id);
|
GString *thread_id;
|
||||||
free ((void *) thread_id);
|
char *id;
|
||||||
|
|
||||||
|
for (i = 0; i < thread_ids->len; i++) {
|
||||||
|
id = (char *) thread_ids->pdata[i];
|
||||||
|
|
||||||
|
add_term (doc, "thread", id);
|
||||||
|
|
||||||
|
if (i == 0)
|
||||||
|
thread_id = g_string_new (id);
|
||||||
|
else
|
||||||
|
g_string_append_printf (thread_id, ",%s", id);
|
||||||
|
|
||||||
|
free (id);
|
||||||
|
}
|
||||||
|
g_ptr_array_free (thread_ids, TRUE);
|
||||||
|
|
||||||
|
doc.add_value (NOTMUCH_VALUE_THREAD, thread_id->str);
|
||||||
|
|
||||||
|
g_string_free (thread_id, TRUE);
|
||||||
} else {
|
} else {
|
||||||
/* If not referenced thread, use the message ID */
|
/* If not referenced thread, use the message ID */
|
||||||
add_term (doc, "thread", message_id);
|
add_term (doc, "thread", message_id);
|
||||||
|
|
Loading…
Reference in a new issue