searchengine: Ensure some GFileInfo fields
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 7 Mar 2023 23:01:53 +0000 (00:01 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Wed, 8 Mar 2023 10:33:10 +0000 (11:33 +0100)
The search provider should make it sure there are some
specific GFileInfo fields set. Fix the mimetype extraction
from the query, and use that to fill in the missing gaps
the best we can.

gtk/gtksearchenginetracker3.c

index cb4dd2d6ce3b882f1f1bcf5f1e3d53145060c161..5ce8916f3972b48a1785871fd4b63f4dec23f822 100644 (file)
@@ -41,7 +41,7 @@
 #define SEARCH_QUERY_BASE(__PATTERN__)                                 \
   "SELECT ?url "                                                       \
   "       nfo:fileName(?urn) "                                        \
-  "       nie:mimeType(?urn)"                                         \
+  "       nie:mimeType(?ie)"                                           \
   "       nfo:fileSize(?urn)"                                         \
   "       nfo:fileLastModified(?urn)"                                 \
   "FROM tracker:FileSystem "                                           \
@@ -49,6 +49,7 @@
   "  ?urn a nfo:FileDataObject ;"                                      \
   "       nie:url ?url ; "                                             \
   "       fts:match ~match . "                                         \
+  "  OPTIONAL { ?urn nie:interpretedAs ?ie } ."                        \
   __PATTERN__                                                          \
   "} "                                                                 \
   "ORDER BY DESC(fts:rank(?urn)) DESC(?url)"
@@ -142,7 +143,18 @@ create_file_info (GFile               *file,
 
   str = tracker_sparql_cursor_get_string (cursor, 2, NULL);
   if (str)
-    g_file_info_set_content_type (info, str);
+    {
+      g_file_info_set_content_type (info, str);
+      g_file_info_set_attribute_uint32 (info, "standard::type",
+                                        strcmp (str, "inode/directory") == 0 ?
+                                        G_FILE_TYPE_DIRECTORY :
+                                        G_FILE_TYPE_REGULAR);
+    }
+  else
+    {
+      g_file_info_set_content_type (info, "application/text");
+      g_file_info_set_attribute_uint32 (info, "standard::type", G_FILE_TYPE_UNKNOWN);
+    }
 
   g_file_info_set_size (info,
                         tracker_sparql_cursor_get_integer (cursor, 3));