[gnome-photos/sam/tracker3] tracker: Query both the content and the file resource



commit af82ab6fc9768aa830ee17ccf2fdc5a84e04168a
Author: Sam Thursfield <sam afuera me uk>
Date:   Wed May 27 13:09:10 2020 +0200

    tracker: Query both the content and the file resource
    
    In Tracker 3, a file and its contents are treated as separate resources.
    The term 'file' is used as in GFile, in that it can refer to both local
    and remote resources.
    
    See https://gitlab.gnome.org/GNOME/tracker/-/issues/205

 src/photos-item-manager.c  |  2 +-
 src/photos-query-builder.c | 14 +++++++-------
 src/photos-source.c        | 14 +++++++-------
 3 files changed, 15 insertions(+), 15 deletions(-)
---
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 74ac4a6c..20f44ab0 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -717,7 +717,7 @@ photos_item_manager_wait_for_changes_timeout (gpointer user_data)
       g_autoptr (PhotosQuery) query = NULL;
       g_autofree gchar *sparql = NULL;
 
-      sparql = g_strdup_printf ("SELECT ?urn nie:url (?urn) WHERE { ?urn nie:url '%s' }", uri);
+      sparql = g_strdup_printf ("SELECT ?urn <%s> WHERE { ?urn nie:isStoredAs <%s> }", uri, uri);
       query = photos_query_new (NULL, sparql);
       photos_tracker_queue_select (self->queue,
                                    query,
diff --git a/src/photos-query-builder.c b/src/photos-query-builder.c
index 2c52a130..8d935be2 100644
--- a/src/photos-query-builder.c
+++ b/src/photos-query-builder.c
@@ -81,7 +81,7 @@ photos_query_builder_inner_where (PhotosSearchContextState *state, gboolean glob
         }
     }
 
-  sparql = g_strdup_printf ("WHERE { %s %s }",
+  sparql = g_strdup_printf ("WHERE { ?urn nie:isStoredAs ?file . %s %s }",
                             srch_typ_mngr_where,
                             (item_mngr_where != NULL) ? item_mngr_where : "");
 
@@ -108,7 +108,7 @@ photos_query_builder_where (PhotosSearchContextState *state, gboolean global, gi
     filter = photos_query_builder_filter (state, flags);
 
   sparql = g_strdup_printf ("WHERE {{"
-                            "    SELECT ?urn rdf:type (?urn) AS ?type %s %s GROUP BY (?urn)"
+                            "    SELECT ?urn ?file rdf:type (?urn) AS ?type %s %s GROUP BY (?urn)"
                             "  }"
                             "  %s %s"
                             "}",
@@ -148,18 +148,18 @@ photos_query_builder_query (PhotosSearchContextState *state,
     }
 
   sparql = g_strconcat ("SELECT ?urn "
-                        "nie:url (?urn) "
-                        "nfo:fileName (?urn) "
+                        "?file "
+                        "nfo:fileName (?file) "
                         "nie:mimeType (?urn) "
                         "nie:title (?urn) "
                         "tracker:coalesce (nco:fullname (?creator), nco:fullname (?publisher), '') "
-                        "tracker:coalesce (nfo:fileLastModified (?urn), nie:contentLastModified (?urn)) AS 
?mtime "
+                        "tracker:coalesce (nfo:fileLastModified (?file), nie:contentLastModified (?urn)) AS 
?mtime "
                         "nao:identifier (?urn) "
                         "rdf:type (?urn) "
-                        "nie:dataSource(?urn) "
+                        "nie:dataSource(?file) "
                         "( EXISTS { ?urn nao:hasTag nao:predefined-tag-favorite } ) "
                         "( EXISTS { ?urn nco:contributor ?contributor FILTER ( ?contributor != ?creator ) } 
) "
-                        "tracker:coalesce(nfo:fileCreated (?urn), nie:contentCreated (?urn)) "
+                        "tracker:coalesce(nfo:fileCreated (?file), nie:contentCreated (?urn)) "
                         "nfo:width (?urn) "
                         "nfo:height (?urn) "
                         "nfo:equipment (?urn) "
diff --git a/src/photos-source.c b/src/photos-source.c
index db6f2de9..4eee4f18 100644
--- a/src/photos-source.c
+++ b/src/photos-source.c
@@ -94,7 +94,7 @@ photos_source_build_filter_local (void)
         continue;
 
       tracker_uri = photos_utils_convert_path_to_uri (tracker_dirs[i]);
-      g_string_append_printf (tracker_filter, " || fn:contains (nie:url (?urn), '%s')", tracker_uri);
+      g_string_append_printf (tracker_filter, " || fn:contains (?file, '%s')", tracker_uri);
     }
 
   path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
@@ -109,11 +109,11 @@ photos_source_build_filter_local (void)
   export_path = g_build_filename (path, PHOTOS_EXPORT_SUBPATH, NULL);
   export_uri = photos_utils_convert_path_to_uri (export_path);
 
-  filter = g_strdup_printf ("(((fn:contains (nie:url (?urn), '%s')"
-                            "   || fn:contains (nie:url (?urn), '%s')"
-                            "   || fn:contains (nie:url (?urn), '%s')"
+  filter = g_strdup_printf ("(((fn:contains (?file, '%s')"
+                            "   || fn:contains (?file, '%s')"
+                            "   || fn:contains (?file, '%s')"
                             "   %s)"
-                            "  && !fn:contains (nie:url (?urn), '%s'))"
+                            "  && !fn:contains (?file, '%s'))"
                             " || fn:starts-with (nao:identifier (?urn), '%s')"
                             " || (?urn = nfo:image-category-screenshot))",
                             desktop_uri,
@@ -137,7 +137,7 @@ photos_source_build_filter_resource (PhotosSource *self)
 
   if (self->object != NULL)
     {
-      filter = g_strdup_printf ("(nie:dataSource (?urn) = '%s')", self->id);
+      filter = g_strdup_printf ("(nie:dataSource (?file) = '%s')", self->id);
     }
   else if (self->mount != NULL)
     {
@@ -146,7 +146,7 @@ photos_source_build_filter_resource (PhotosSource *self)
 
       root = g_mount_get_root (self->mount);
       uri = g_file_get_uri (root);
-      filter = g_strdup_printf ("(fn:starts-with (nie:url (?urn), '%s'))", uri);
+      filter = g_strdup_printf ("(fn:starts-with (?file, '%s'))", uri);
     }
   else
     {


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