[nautilus/wip/antoniof/search-engine-fixes-42-backport: 5/7] nautilus-search-engine: Propagate dates to calculate rank




commit 0840fa09ab851922e57f999738a8b7c23bbe1823
Author: Ondrej Holy <oholy redhat com>
Date:   Tue Feb 15 10:53:15 2022 +0100

    nautilus-search-engine: Propagate dates to calculate rank
    
    The access and modification dates are used to calculate rank, but are
    not propagated from all providers. Let's propagate them from all providers.
    
    Relates: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2152

 src/nautilus-search-engine-model.c  | 18 +++++++++++++++---
 src/nautilus-search-engine-simple.c | 26 +++++++++++++-------------
 2 files changed, 28 insertions(+), 16 deletions(-)
---
diff --git a/src/nautilus-search-engine-model.c b/src/nautilus-search-engine-model.c
index 8bf7da941..6d91cc65d 100644
--- a/src/nautilus-search-engine-model.c
+++ b/src/nautilus-search-engine-model.c
@@ -147,6 +147,10 @@ model_directory_ready_cb (NautilusDirectory *directory,
 
     for (l = files; l != NULL; l = l->next)
     {
+        g_autoptr (GDateTime) mtime = NULL;
+        g_autoptr (GDateTime) atime = NULL;
+        g_autoptr (GDateTime) ctime = NULL;
+
         file = l->data;
 
         display_name = nautilus_file_get_display_name (file);
@@ -167,6 +171,10 @@ model_directory_ready_cb (NautilusDirectory *directory,
             }
         }
 
+        mtime = g_date_time_new_from_unix_local (nautilus_file_get_mtime (file));
+        atime = g_date_time_new_from_unix_local (nautilus_file_get_atime (file));
+        ctime = g_date_time_new_from_unix_local (nautilus_file_get_btime (file));
+
         date_range = nautilus_query_get_date_range (model->query);
         if (found && date_range != NULL)
         {
@@ -179,15 +187,15 @@ model_directory_ready_cb (NautilusDirectory *directory,
 
             if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
             {
-                current_file_unix_time = nautilus_file_get_atime (file);
+                current_file_unix_time = g_date_time_to_unix (atime);
             }
             else if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
             {
-                current_file_unix_time = nautilus_file_get_mtime (file);
+                current_file_unix_time = g_date_time_to_unix (mtime);
             }
             else
             {
-                current_file_unix_time = nautilus_file_get_btime (file);
+                current_file_unix_time = g_date_time_to_unix (ctime);
             }
 
             found = nautilus_file_date_in_between (current_file_unix_time,
@@ -201,6 +209,10 @@ model_directory_ready_cb (NautilusDirectory *directory,
             uri = nautilus_file_get_uri (file);
             hit = nautilus_search_hit_new (uri);
             nautilus_search_hit_set_fts_rank (hit, match);
+            nautilus_search_hit_set_modification_time (hit, mtime);
+            nautilus_search_hit_set_access_time (hit, atime);
+            nautilus_search_hit_set_creation_time (hit, ctime);
+
             hits = g_list_prepend (hits, hit);
 
             g_free (uri);
diff --git a/src/nautilus-search-engine-simple.c b/src/nautilus-search-engine-simple.c
index 3ed02e016..bf3eea1c2 100644
--- a/src/nautilus-search-engine-simple.c
+++ b/src/nautilus-search-engine-simple.c
@@ -295,9 +295,6 @@ visit_directory (GFile            *dir,
     gboolean is_hidden, found;
     const char *id;
     gboolean visited;
-    guint64 atime;
-    guint64 mtime;
-    guint64 ctime;
     GDateTime *initial_date;
     GDateTime *end_date;
     gchar *uri;
@@ -323,6 +320,10 @@ visit_directory (GFile            *dir,
 
     while ((info = g_file_enumerator_next_file (enumerator, data->cancellable, NULL)) != NULL)
     {
+        g_autoptr (GDateTime) mtime = NULL;
+        g_autoptr (GDateTime) atime = NULL;
+        g_autoptr (GDateTime) ctime = NULL;
+
         display_name = g_file_info_get_display_name (info);
         if (display_name == NULL)
         {
@@ -354,9 +355,9 @@ visit_directory (GFile            *dir,
             }
         }
 
-        mtime = g_file_info_get_attribute_uint64 (info, "time::modified");
-        atime = g_file_info_get_attribute_uint64 (info, "time::access");
-        ctime = g_file_info_get_attribute_uint64 (info, "time::created");
+        mtime = g_file_info_get_modification_date_time (info);
+        atime = g_file_info_get_access_date_time (info);
+        ctime = g_file_info_get_creation_date_time (info);
 
         if (found && date_range != NULL)
         {
@@ -367,15 +368,15 @@ visit_directory (GFile            *dir,
 
             if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
             {
-                current_file_time = atime;
+                current_file_time = g_date_time_to_unix (atime);
             }
             else if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
             {
-                current_file_time = mtime;
+                current_file_time = g_date_time_to_unix (mtime);
             }
             else
             {
-                current_file_time = ctime;
+                current_file_time = g_date_time_to_unix (ctime);
             }
             found = nautilus_file_date_in_between (current_file_time,
                                                    initial_date,
@@ -385,15 +386,14 @@ visit_directory (GFile            *dir,
         if (found)
         {
             NautilusSearchHit *hit;
-            GDateTime *date;
 
             uri = g_file_get_uri (child);
             hit = nautilus_search_hit_new (uri);
             g_free (uri);
             nautilus_search_hit_set_fts_rank (hit, match);
-            date = g_date_time_new_from_unix_local (mtime);
-            nautilus_search_hit_set_modification_time (hit, date);
-            g_date_time_unref (date);
+            nautilus_search_hit_set_modification_time (hit, mtime);
+            nautilus_search_hit_set_access_time (hit, atime);
+            nautilus_search_hit_set_creation_time (hit, ctime);
 
             data->hits = g_list_prepend (data->hits, hit);
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]