[PATCH] allow to not sort the search results

Sebastian Spaeth Sebastian at SSpaeth.de
Tue Apr 13 23:30:55 PDT 2010


previously we were always sorting the returned results by some string value,
but sometimes we might just be interested in the number of results, and don't
need any sorting.

Also add a --sort=unsorted command line option to notmuch search to test this.
A search that matches 1200 messages, returns in default sort in 0.982 seconds
and unsorted in 0.978 seconds with very little variance (with a warm cache).
Xapian contributor Olly Betts says that the speed gains for a cold cache are
likely to be much higher though.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 lib/notmuch.h    |    3 ++-
 lib/query.cc     |    2 ++
 notmuch-search.c |    2 ++
 3 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/lib/notmuch.h b/lib/notmuch.h
index a7e66dd..bae48a6 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -346,7 +346,8 @@ notmuch_query_create (notmuch_database_t *database,
 typedef enum {
     NOTMUCH_SORT_OLDEST_FIRST,
     NOTMUCH_SORT_NEWEST_FIRST,
-    NOTMUCH_SORT_MESSAGE_ID
+    NOTMUCH_SORT_MESSAGE_ID,
+    NOTMUCH_SORT_UNSORTED
 } notmuch_sort_t;
 
 /* Specify the sorting desired for this query. */
diff --git a/lib/query.cc b/lib/query.cc
index 10f8dc8..4148f9b 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -148,6 +148,8 @@ notmuch_query_search_messages (notmuch_query_t *query)
 	case NOTMUCH_SORT_MESSAGE_ID:
 	    enquire.set_sort_by_value (NOTMUCH_VALUE_MESSAGE_ID, FALSE);
 	    break;
+        case NOTMUCH_SORT_UNSORTED:
+	    break;
 	}
 
 #if DEBUG_QUERY
diff --git a/notmuch-search.c b/notmuch-search.c
index 4e3514b..854a9ae 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -217,6 +217,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
 		sort = NOTMUCH_SORT_OLDEST_FIRST;
 	    } else if (strcmp (opt, "newest-first") == 0) {
 		sort = NOTMUCH_SORT_NEWEST_FIRST;
+	    } else if (strcmp (opt, "unsorted") == 0) {
+		sort = NOTMUCH_SORT_UNSORTED;
 	    } else {
 		fprintf (stderr, "Invalid value for --sort: %s\n", opt);
 		return 1;
-- 
1.6.3.3



More information about the notmuch mailing list