[PATCH 1/3] sorting: add the ability to sort by from and subject

William Casarin jb55 at jb55.com
Mon Sep 4 09:00:38 PDT 2017


* add {from,subject}-{ascending,descending} sort options
---
I'm not sure if we want to eventually refactor ascending and descending
into a separate option, but I decided to keep it this way for now.

 lib/notmuch.h    | 16 ++++++++++++++++
 lib/query.cc     | 12 ++++++++++++
 notmuch-search.c |  4 ++++
 3 files changed, 32 insertions(+)

diff --git a/lib/notmuch.h b/lib/notmuch.h
index 66ecb5fc..f5764683 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -764,6 +764,22 @@ typedef enum {
      */
     NOTMUCH_SORT_NEWEST_FIRST,
     /**
+     * Sort by from: in ascending order
+     */
+    NOTMUCH_SORT_FROM_ASC,
+    /**
+     * Sort by from: in descending order
+     */
+    NOTMUCH_SORT_FROM_DESC,
+    /**
+     * Sort by subject: in ascending order
+     */
+    NOTMUCH_SORT_SUBJECT_ASC,
+    /**
+     * Sort by subject: in descending order
+     */
+    NOTMUCH_SORT_SUBJECT_DESC,
+    /**
      * Sort by message-id.
      */
     NOTMUCH_SORT_MESSAGE_ID,
diff --git a/lib/query.cc b/lib/query.cc
index 9c6ecc8d..106814a8 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -327,6 +327,18 @@ _notmuch_query_search_documents (notmuch_query_t *query,
 	case NOTMUCH_SORT_NEWEST_FIRST:
 	    enquire.set_sort_by_value (NOTMUCH_VALUE_TIMESTAMP, TRUE);
 	    break;
+	case NOTMUCH_SORT_FROM_ASC:
+	    enquire.set_sort_by_value (NOTMUCH_VALUE_FROM, FALSE);
+	    break;
+	case NOTMUCH_SORT_FROM_DESC:
+	    enquire.set_sort_by_value (NOTMUCH_VALUE_FROM, TRUE);
+	    break;
+	case NOTMUCH_SORT_SUBJECT_ASC:
+	    enquire.set_sort_by_value (NOTMUCH_VALUE_SUBJECT, FALSE);
+	    break;
+	case NOTMUCH_SORT_SUBJECT_DESC:
+	    enquire.set_sort_by_value (NOTMUCH_VALUE_SUBJECT, TRUE);
+	    break;
 	case NOTMUCH_SORT_MESSAGE_ID:
 	    enquire.set_sort_by_value (NOTMUCH_VALUE_MESSAGE_ID, FALSE);
 	    break;
diff --git a/notmuch-search.c b/notmuch-search.c
index 380e9d8f..b80647e9 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -789,6 +789,10 @@ static const notmuch_opt_desc_t common_options[] = {
     { NOTMUCH_OPT_KEYWORD, &search_context.sort, "sort", 's',
       (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
 			      { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
+			      { "from-ascending", NOTMUCH_SORT_FROM_ASC },
+			      { "from-descending", NOTMUCH_SORT_FROM_DESC },
+			      { "subject-ascending", NOTMUCH_SORT_SUBJECT_ASC },
+			      { "subject-descending", NOTMUCH_SORT_SUBJECT_DESC },
 			      { 0, 0 } } },
     { NOTMUCH_OPT_KEYWORD, &search_context.format_sel, "format", 'f',
       (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
-- 
2.13.2



More information about the notmuch mailing list