Siegfried Gevatter has proposed merging lp:~rainct/zeitgeist/fts-sorting into 
lp:zeitgeist.

Requested reviews:
  Michal Hruby (mhr3)

For more details, see:
https://code.launchpad.net/~rainct/zeitgeist/fts-sorting/+merge/97985
-- 
https://code.launchpad.net/~rainct/zeitgeist/fts-sorting/+merge/97985
Your team Zeitgeist Framework Team is subscribed to branch lp:zeitgeist.
=== modified file 'extensions/fts++/indexer.cpp'
--- extensions/fts++/indexer.cpp	2012-03-16 20:03:05 +0000
+++ extensions/fts++/indexer.cpp	2012-03-16 20:45:24 +0000
@@ -778,7 +778,10 @@
     }
     else
     {
-      enquire->set_sort_by_value (VALUE_TIMESTAMP, true);
+      bool reversed_sort = not
+          zeitgeist_db_reader_sort_order_for_result_type_is_asc (zg_reader,
+                                                                 result_type);
+      enquire->set_sort_by_value (VALUE_TIMESTAMP, reversed_sort);
     }
 
     if (result_type == ZEITGEIST_RESULT_TYPE_MOST_RECENT_SUBJECTS ||
@@ -786,7 +789,20 @@
         result_type == ZEITGEIST_RESULT_TYPE_MOST_POPULAR_SUBJECTS ||
         result_type == ZEITGEIST_RESULT_TYPE_LEAST_POPULAR_SUBJECTS)
     {
-        enquire->set_collapse_key (VALUE_URI_HASH);
+      enquire->set_collapse_key (VALUE_URI_HASH);
+    }
+    else if (result_type == ZEITGEIST_RESULT_TYPE_MOST_RECENT_ORIGIN ||
+        result_type == ZEITGEIST_RESULT_TYPE_LEAST_RECENT_ORIGIN ||
+        result_type == ZEITGEIST_RESULT_TYPE_MOST_POPULAR_ORIGIN ||
+        result_type == ZEITGEIST_RESULT_TYPE_LEAST_POPULAR_ORIGIN)
+    {
+      // FIXME: not really correct but close :)
+      enquire->set_collapse_key (VALUE_URI_HASH);
+    }
+    else if (result_type == ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS ||
+        result_type == ZEITGEIST_RESULT_TYPE_LEAST_RECENT_EVENTS)
+    {
+      enquire->set_collapse_key (VALUE_EVENT_ID);
     }
 
     Xapian::Query q(query_parser->parse_query (query_string, QUERY_PARSER_FLAGS));
@@ -1096,12 +1112,9 @@
       return NULL;
     }
 
-    bool reversed_sort =
-      result_type == ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS ||
-      result_type == ZEITGEIST_RESULT_TYPE_MOST_RECENT_SUBJECTS ||
-      result_type == ZEITGEIST_RESULT_TYPE_MOST_POPULAR_SUBJECTS ||
-      result_type == ZEITGEIST_RESULT_TYPE_MOST_RECENT_ORIGIN ||
-      result_type == ZEITGEIST_RESULT_TYPE_MOST_POPULAR_ORIGIN;
+    bool reversed_sort = not
+        zeitgeist_db_reader_sort_order_for_result_type_is_asc (zg_reader,
+                                                               result_type);
 
     if (result_type == RELEVANCY_RESULT_TYPE)
     {

=== modified file 'src/db-reader.vala'
--- src/db-reader.vala	2012-03-14 12:31:51 +0000
+++ src/db-reader.vala	2012-03-16 20:45:24 +0000
@@ -160,6 +160,56 @@
         return results;
     }
 
+    /*
+     * Returns true if the results for the given result_type will be sorted
+     * ascendantly by date, false if they'll be sorted descendingly.
+     **/
+    public bool sort_order_for_result_type_is_asc (uint result_type)
+    {
+        switch (result_type)
+        {
+            // FIXME: Why are LEAST_POPULAR_* using ASC?
+            case ResultType.LEAST_RECENT_EVENTS:
+            case ResultType.LEAST_RECENT_EVENT_ORIGIN:
+            case ResultType.LEAST_POPULAR_EVENT_ORIGIN:
+            case ResultType.LEAST_RECENT_SUBJECTS:
+            case ResultType.LEAST_POPULAR_SUBJECTS:
+            case ResultType.LEAST_RECENT_CURRENT_URI:
+            case ResultType.LEAST_POPULAR_CURRENT_URI:
+            case ResultType.LEAST_RECENT_ACTOR:
+            case ResultType.LEAST_POPULAR_ACTOR:
+            case ResultType.OLDEST_ACTOR:
+            case ResultType.LEAST_RECENT_ORIGIN:
+            case ResultType.LEAST_POPULAR_ORIGIN:
+            case ResultType.LEAST_RECENT_SUBJECT_INTERPRETATION:
+            case ResultType.LEAST_POPULAR_SUBJECT_INTERPRETATION:
+            case ResultType.LEAST_RECENT_MIMETYPE:
+            case ResultType.LEAST_POPULAR_MIMETYPE:
+                return true;
+
+            case ResultType.MOST_RECENT_EVENTS:
+            case ResultType.MOST_RECENT_EVENT_ORIGIN:
+            case ResultType.MOST_POPULAR_EVENT_ORIGIN:
+            case ResultType.MOST_RECENT_SUBJECTS:
+            case ResultType.MOST_POPULAR_SUBJECTS:
+            case ResultType.MOST_RECENT_CURRENT_URI:
+            case ResultType.MOST_POPULAR_CURRENT_URI:
+            case ResultType.MOST_RECENT_ACTOR:
+            case ResultType.MOST_POPULAR_ACTOR:
+            case ResultType.MOST_RECENT_ORIGIN:
+            case ResultType.MOST_POPULAR_ORIGIN:
+            case ResultType.MOST_RECENT_SUBJECT_INTERPRETATION:
+            case ResultType.MOST_POPULAR_SUBJECT_INTERPRETATION:
+            case ResultType.MOST_RECENT_MIMETYPE:
+            case ResultType.MOST_POPULAR_MIMETYPE:
+                return false;
+
+            default:
+                warning ("Unrecognized ResultType: %u", result_type);
+                return true;
+        }
+    }
+
     public uint32[] find_event_ids_for_clause (WhereClause where,
         uint max_events, uint result_type) throws EngineError
     {

_______________________________________________
Mailing list: https://launchpad.net/~zeitgeist
Post to     : zeitgeist@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zeitgeist
More help   : https://help.launchpad.net/ListHelp

Reply via email to