[nautilus/wip/oholy/search-engine-fixes: 4/5] nautilus-search-engine: Propagate dates to calculate rank
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/oholy/search-engine-fixes: 4/5] nautilus-search-engine: Propagate dates to calculate rank
- Date: Tue, 15 Feb 2022 11:28:56 +0000 (UTC)
commit a3c9b11c766e5eddbc530d1c42413685b2d27159
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 2c246edb3..1dbf5a25e 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 if (type == NAUTILUS_QUERY_SEARCH_TYPE_CREATED)
{
- 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 2d89e42f4..306fe3bd1 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 if (type == NAUTILUS_QUERY_SEARCH_TYPE_CREATED)
{
- current_file_time = ctime;
+ current_file_time = g_date_time_to_unix (ctime);
}
found = nautilus_file_date_in_between (current_file_time,
@@ -386,15 +387,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]