]> git.notmuchmail.org Git - notmuch/commitdiff
libnotmuch: Underlying support for doing partial-results searches.
authorCarl Worth <cworth@cworth.org>
Fri, 13 Nov 2009 00:47:27 +0000 (16:47 -0800)
committerCarl Worth <cworth@cworth.org>
Fri, 13 Nov 2009 00:47:27 +0000 (16:47 -0800)
The library interface now allows the caller to do incremental searches,
(such as one page of results at a time). Next we'll just need to hook
this up to "notmuch search" and the emacs interface.

lib/notmuch.h
lib/query.cc
notmuch-dump.c
notmuch-reply.c
notmuch-search.c
notmuch-show.c
notmuch-tag.c

index 4004af907d2e808c07e449b6b0d9d64d418a5bb5..c67376ebd2b0fdeef2016c53b7537f9c253ca282 100644 (file)
@@ -313,6 +313,14 @@ notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);
  * object is owned by the query and as such, will only be valid until
  * notmuch_query_destroy.
  *
  * object is owned by the query and as such, will only be valid until
  * notmuch_query_destroy.
  *
+ * The 'first' and 'max_threads' arguments can be used to obtain
+ * partial results from the search. For example, to get results 10 at
+ * a time, pass 'max_threads' as 10 and for 'first' pass the values 0,
+ * 10, 20, etc. As a special case, a value of -1 for 'max_threads'
+ * indicates that no limiting is to be performed. So a search with
+ * 'first' == 0 and 'max_threads' == -1 will return the complete
+ * results of the search.
+ *
  * Typical usage might be:
  *
  *     notmuch_query_t *query;
  * Typical usage might be:
  *
  *     notmuch_query_t *query;
@@ -345,13 +353,22 @@ notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);
  * to call it if the query is about to be destroyed).
  */
 notmuch_threads_t *
  * to call it if the query is about to be destroyed).
  */
 notmuch_threads_t *
-notmuch_query_search_threads (notmuch_query_t *query);
+notmuch_query_search_threads (notmuch_query_t *query,
+                             int first, int max_threads);
 
 /* Execute a query for messages, returning a notmuch_messages_t object
  * which can be used to iterate over the results. The returned
  * messages object is owned by the query and as such, will only be
  * valid until notmuch_query_destroy.
  *
 
 /* Execute a query for messages, returning a notmuch_messages_t object
  * which can be used to iterate over the results. The returned
  * messages object is owned by the query and as such, will only be
  * valid until notmuch_query_destroy.
  *
+ * The 'first' and 'max_messages' arguments can be used to obtain
+ * partial results from the search. For example, to get results 10 at
+ * a time, pass 'max_messages' as 10 and for 'first' pass the values
+ * 0, 10, 20, etc. As a special case, a value of -1 for 'max_messages'
+ * indicates that no limiting is to be performed. So a search with
+ * 'first' == 0 and 'max_messages' == -1 will return the complete
+ * results of the search.
+ *
  * Typical usage might be:
  *
  *     notmuch_query_t *query;
  * Typical usage might be:
  *
  *     notmuch_query_t *query;
@@ -384,7 +401,8 @@ notmuch_query_search_threads (notmuch_query_t *query);
  * reason to call it if the query is about to be destroyed).
  */
 notmuch_messages_t *
  * reason to call it if the query is about to be destroyed).
  */
 notmuch_messages_t *
-notmuch_query_search_messages (notmuch_query_t *query);
+notmuch_query_search_messages (notmuch_query_t *query,
+                              int first, int max_messages);
 
 /* Destroy a notmuch_query_t along with any associated resources.
  *
 
 /* Destroy a notmuch_query_t along with any associated resources.
  *
index ed576614fe0a630d0ba04c8d69768b5b1f87e45a..1777e47dc044daa339c7ec0988e3d0fbef3de5a9 100644 (file)
@@ -88,7 +88,9 @@ _notmuch_messages_destructor (notmuch_messages_t *messages)
 }
 
 notmuch_messages_t *
 }
 
 notmuch_messages_t *
-notmuch_query_search_messages (notmuch_query_t *query)
+notmuch_query_search_messages (notmuch_query_t *query,
+                              int first,
+                              int max_messages)
 {
     notmuch_database_t *notmuch = query->notmuch;
     const char *query_string = query->query_string;
 {
     notmuch_database_t *notmuch = query->notmuch;
     const char *query_string = query->query_string;
@@ -138,7 +140,9 @@ notmuch_query_search_messages (notmuch_query_t *query)
 
        enquire.set_query (final_query);
 
 
        enquire.set_query (final_query);
 
-       mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());
+       if (max_messages == -1)
+           max_messages = notmuch->xapian_db->get_doccount ();
+       mset = enquire.get_mset (first, max_messages);
 
        messages->notmuch = notmuch;
 
 
        messages->notmuch = notmuch;
 
@@ -171,7 +175,9 @@ _notmuch_threads_destructor (notmuch_threads_t *threads)
 }
 
 notmuch_threads_t *
 }
 
 notmuch_threads_t *
-notmuch_query_search_threads (notmuch_query_t *query)
+notmuch_query_search_threads (notmuch_query_t *query,
+                             int first,
+                             int max_threads)
 {
     notmuch_threads_t *threads;
     notmuch_thread_t *thread;
 {
     notmuch_threads_t *threads;
     notmuch_thread_t *thread;
@@ -179,6 +185,7 @@ notmuch_query_search_threads (notmuch_query_t *query)
     notmuch_messages_t *messages;
     notmuch_message_t *message;
     GHashTable *seen;
     notmuch_messages_t *messages;
     notmuch_message_t *message;
     GHashTable *seen;
+    int messages_seen = 0, threads_seen = 0;
 
     threads = talloc (query, notmuch_threads_t);
     if (threads == NULL)
 
     threads = talloc (query, notmuch_threads_t);
     if (threads == NULL)
@@ -193,29 +200,48 @@ notmuch_query_search_threads (notmuch_query_t *query)
     seen = g_hash_table_new_full (g_str_hash, g_str_equal,
                                  free, NULL);
 
     seen = g_hash_table_new_full (g_str_hash, g_str_equal,
                                  free, NULL);
 
-    for (messages = notmuch_query_search_messages (query);
-        notmuch_messages_has_more (messages);
-        notmuch_messages_advance (messages))
+    while (threads_seen < first + max_threads)
     {
     {
-       message = notmuch_messages_get (messages);
+       int messages_seen_previously = messages_seen;
 
 
-       thread_id = notmuch_message_get_thread_id (message);
-
-       if (! g_hash_table_lookup_extended (seen,
-                                           thread_id, NULL,
-                                           (void **) &thread))
+       for (messages = notmuch_query_search_messages (query,
+                                                      messages_seen,
+                                                      max_threads);
+            notmuch_messages_has_more (messages);
+            notmuch_messages_advance (messages))
        {
        {
-           thread = _notmuch_thread_create (query, query->notmuch,
-                                            thread_id);
+           message = notmuch_messages_get (messages);
 
 
-           g_hash_table_insert (seen, xstrdup (thread_id), thread);
+           thread_id = notmuch_message_get_thread_id (message);
 
 
-           g_ptr_array_add (threads->threads, thread);
-       }
+           if (! g_hash_table_lookup_extended (seen,
+                                               thread_id, NULL,
+                                               (void **) &thread))
+           {
+               if (threads_seen > first) {
+                   thread = _notmuch_thread_create (query, query->notmuch,
+                                                    thread_id);
+                   g_ptr_array_add (threads->threads, thread);
+               } else {
+                   thread = NULL;
+               }
+
+               g_hash_table_insert (seen, xstrdup (thread_id), thread);
+
+               threads_seen++;
+           }
 
 
-       _notmuch_thread_add_message (thread, message);
+           if (thread)
+               _notmuch_thread_add_message (thread, message);
 
 
-       notmuch_message_destroy (message);
+           notmuch_message_destroy (message);
+
+           messages_seen++;
+       }
+
+       /* Stop if we're not seeing any more messages. */
+       if (messages_seen == messages_seen_previously)
+           break;
     }
 
     g_hash_table_unref (seen);
     }
 
     g_hash_table_unref (seen);
index e1fe72356dd09d1dfb4511c1685ad31928473ccf..4c6e3211022c34e25b54205db17593a796d10535 100644 (file)
@@ -57,7 +57,7 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
        output = stdout;
     }
 
        output = stdout;
     }
 
-    for (messages = notmuch_query_search_messages (query);
+    for (messages = notmuch_query_search_messages (query, 0, -1);
         notmuch_messages_has_more (messages);
         notmuch_messages_advance (messages))
     {
         notmuch_messages_has_more (messages);
         notmuch_messages_advance (messages))
     {
index f26bd5521d278be7bb812684da16bc7d5a413f57..86e9b3a29b1048b3371b734097cf49477656a2ac 100644 (file)
@@ -211,7 +211,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
        return 1;
     }
 
        return 1;
     }
 
-    for (messages = notmuch_query_search_messages (query);
+    for (messages = notmuch_query_search_messages (query, 0, -1);
         notmuch_messages_has_more (messages);
         notmuch_messages_advance (messages))
     {
         notmuch_messages_has_more (messages);
         notmuch_messages_advance (messages))
     {
index 38ca75d63ade2582c40db3bf7db6f08ace0d5c68..41e317a221961ebdab9d82ada88a9f4dc0935fae 100644 (file)
@@ -53,7 +53,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
        return 1;
     }
 
        return 1;
     }
 
-    for (threads = notmuch_query_search_threads (query);
+    for (threads = notmuch_query_search_threads (query, 0, -1);
         notmuch_threads_has_more (threads);
         notmuch_threads_advance (threads))
     {
         notmuch_threads_has_more (threads);
         notmuch_threads_advance (threads))
     {
index 41b33641c67143599c2d4f5b76f8554ade93297b..9f81ae161f1fa4975df8cf721630fbab818539c9 100644 (file)
@@ -153,7 +153,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
        return 1;
     }
 
        return 1;
     }
 
-    for (messages = notmuch_query_search_messages (query);
+    for (messages = notmuch_query_search_messages (query, 0, -1);
         notmuch_messages_has_more (messages);
         notmuch_messages_advance (messages))
     {
         notmuch_messages_has_more (messages);
         notmuch_messages_advance (messages))
     {
index ada52e45d4295a1a6dffed64edea60bec411aa01..80582acf4733213f1efee8d7f7845b0b54ff87b8 100644 (file)
@@ -86,7 +86,7 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
        return 1;
     }
 
        return 1;
     }
 
-    for (messages = notmuch_query_search_messages (query);
+    for (messages = notmuch_query_search_messages (query, 0, -1);
         notmuch_messages_has_more (messages);
         notmuch_messages_advance (messages))
     {
         notmuch_messages_has_more (messages);
         notmuch_messages_advance (messages))
     {