Blame SOURCES/tracker3.patch

564002
From ca0d487aac3b9cf21e520a00b94cb3eaf833b9a3 Mon Sep 17 00:00:00 2001
564002
From: Carlos Garnacho <carlosg@gnome.org>
564002
Date: Thu, 24 Dec 2020 12:19:49 +0100
564002
Subject: [PATCH 1/5] Obtain TrackerSparqlConnection in a single point
564002
564002
The is_available vmethod tries to create a connection if it's not
564002
there. But the BraseroSearchTracker initialization already tries to
564002
obtain the SPARQL connection. Let this method return wether
564002
initialiation was successful.
564002
---
564002
 src/brasero-search-tracker.c | 6 ------
564002
 1 file changed, 6 deletions(-)
564002
564002
diff --git a/src/brasero-search-tracker.c b/src/brasero-search-tracker.c
564002
index fe7be2bd..f8c29c0d 100644
564002
--- a/src/brasero-search-tracker.c
564002
+++ b/src/brasero-search-tracker.c
564002
@@ -56,12 +56,6 @@ brasero_search_tracker_is_available (BraseroSearchEngine *engine)
564002
 	BraseroSearchTrackerPrivate *priv;
564002
 
564002
 	priv = BRASERO_SEARCH_TRACKER_PRIVATE (engine);
564002
-	GError *error = NULL;
564002
-	if (priv->connection)
564002
-		return TRUE;
564002
-	
564002
-	priv->cancellable = g_cancellable_new ();
564002
- 	priv->connection = tracker_sparql_connection_get (priv->cancellable, &error);
564002
 	return (priv->connection != NULL);
564002
 }
564002
 
564002
-- 
564002
GitLab
564002
564002
564002
From c0dace005ec34b345845aacd1f929fd618b199af Mon Sep 17 00:00:00 2001
564002
From: Carlos Garnacho <carlosg@gnome.org>
564002
Date: Thu, 24 Dec 2020 12:37:13 +0100
564002
Subject: [PATCH 2/5] Fix ORDER BY clauses in Tracker search
564002
564002
The ?urn variable is not defined anywhere else in the query, so
564002
ordering is left undefined. Access the url/filename properly here.
564002
---
564002
 src/brasero-search-tracker.c | 2 +-
564002
 1 file changed, 1 insertion(+), 1 deletion(-)
564002
564002
diff --git a/src/brasero-search-tracker.c b/src/brasero-search-tracker.c
564002
index f8c29c0d..94085070 100644
564002
--- a/src/brasero-search-tracker.c
564002
+++ b/src/brasero-search-tracker.c
564002
@@ -307,7 +307,7 @@ brasero_search_tracker_query_start_real (BraseroSearchEngine *search,
564002
 	g_string_append (query, ")");
564002
 
564002
 	g_string_append (query,
564002
-			 "} ORDER BY DESC(nie:url(?urn)) DESC(nfo:fileName(?urn))");
564002
+			 "} ORDER BY DESC(?url) DESC(nfo:fileName(?file))");
564002
 
564002
 	tracker_sparql_connection_query_async (priv->connection,
564002
 					       query->str,
564002
-- 
564002
GitLab
564002
564002
564002
From f7181445bf9c88b7fab1bb5237d602b491694a9e Mon Sep 17 00:00:00 2001
564002
From: Carlos Garnacho <carlosg@gnome.org>
564002
Date: Thu, 24 Dec 2020 13:04:03 +0100
564002
Subject: [PATCH 3/5] Only use fts:rank with FTS searches
564002
564002
This fixes two things:
564002
- The use of fts:match depends on priv->keywords being set, but
564002
  fts:rank() has undefined behavior if fts:match is not present.
564002
  Its value is returned in the cursor, but fortunately unused,
564002
  so it can go away.
564002
564002
- Fixes "garbage" being added at the end of the query, concretely
564002
  ") } ORDER BY ... " is appended at the supposed end of the query
564002
  string. Older SPARQL parser implementations would allow garbage
564002
  at the end of its parsing state, I suspect "LIMIT 0 OFFSET 10000"
564002
  was just a mean to push it to that state that it'd allow the
564002
  remaining string, so that is gone too.
564002
---
564002
 src/brasero-search-tracker.c | 21 +++++++++------------
564002
 1 file changed, 9 insertions(+), 12 deletions(-)
564002
564002
diff --git a/src/brasero-search-tracker.c b/src/brasero-search-tracker.c
564002
index 94085070..ae1d388a 100644
564002
--- a/src/brasero-search-tracker.c
564002
+++ b/src/brasero-search-tracker.c
564002
@@ -234,7 +234,7 @@ brasero_search_tracker_query_start_real (BraseroSearchEngine *search,
564002
 
564002
 	priv = BRASERO_SEARCH_TRACKER_PRIVATE (search);
564002
 
564002
-	query = g_string_new ("SELECT ?file ?url ?mime fts:rank(?file) "	/* Which variables should be returned */
564002
+	query = g_string_new ("SELECT ?file ?url ?mime "			/* Which variables should be returned */
564002
 			      "WHERE {"						/* Start defining the search and its scope */
564002
 			      "  ?file a nfo:FileDataObject . "			/* File must be a file (not a stream, ...) */
564002
 	                      "  ?file nie:url ?url . "				/* Get the url of the file */
564002
@@ -293,21 +293,18 @@ brasero_search_tracker_query_start_real (BraseroSearchEngine *search,
564002
 				 " ) ");
564002
 	}
564002
 
564002
-	if (priv->keywords)
564002
+	if (priv->keywords) {
564002
 		g_string_append_printf (query,
564002
 					"  ?file fts:match \"%s\" ",		/* File must match possible keywords */
564002
 					priv->keywords);
564002
 
564002
-	g_string_append (query,
564002
-			 " } "
564002
-			 "ORDER BY ASC(fts:rank(?file)) "
564002
-			 "OFFSET 0 "
564002
-			 "LIMIT 10000");
564002
-
564002
-	g_string_append (query, ")");
564002
-
564002
-	g_string_append (query,
564002
-			 "} ORDER BY DESC(?url) DESC(nfo:fileName(?file))");
564002
+		g_string_append (query,
564002
+				 " } "
564002
+				 "ORDER BY ASC(fts:rank(?file))");
564002
+	} else {
564002
+		g_string_append (query,
564002
+				 "} ORDER BY DESC(?url) DESC(nfo:fileName(?file))");
564002
+	}
564002
 
564002
 	tracker_sparql_connection_query_async (priv->connection,
564002
 					       query->str,
564002
-- 
564002
GitLab
564002
564002
564002
From ede7758e2fae487d57be641a120c4c02bfd249f1 Mon Sep 17 00:00:00 2001
564002
From: Carlos Garnacho <carlosg@gnome.org>
564002
Date: Thu, 24 Dec 2020 13:15:21 +0100
564002
Subject: [PATCH 4/5] Observe nfo:FileDataObject/nie:InformationElement split
564002
564002
These resources are interpreted differently in Tracker 3.0 compared
564002
to older versions, the newer version makes those 2 different resources
564002
(one representing the "file", other the "content) that relate to each
564002
other. In older tracker versions, these 2 aspects were conflated in
564002
a single resource.
564002
564002
The query is implicitly crossing that barrier, so make it explicit.
564002
With this change, the query may run with either version.
564002
---
564002
 src/brasero-search-tracker.c | 5 +++--
564002
 1 file changed, 3 insertions(+), 2 deletions(-)
564002
564002
diff --git a/src/brasero-search-tracker.c b/src/brasero-search-tracker.c
564002
index ae1d388a..9aa06289 100644
564002
--- a/src/brasero-search-tracker.c
564002
+++ b/src/brasero-search-tracker.c
564002
@@ -238,7 +238,8 @@ brasero_search_tracker_query_start_real (BraseroSearchEngine *search,
564002
 			      "WHERE {"						/* Start defining the search and its scope */
564002
 			      "  ?file a nfo:FileDataObject . "			/* File must be a file (not a stream, ...) */
564002
 	                      "  ?file nie:url ?url . "				/* Get the url of the file */
564002
-	                      "  ?file nie:mimeType ?mime . ");			/* Get its mime */
564002
+	                      "  ?file nie:mimeType ?mime . "			/* Get its mime */
564002
+			      "  ?content nie:isStoredAs ?file . ");		/* Get the resource representing the content */
564002
 
564002
 	if (priv->mimes) {
564002
 		int i;
564002
@@ -259,7 +260,7 @@ brasero_search_tracker_query_start_real (BraseroSearchEngine *search,
564002
 		gboolean param_added = FALSE;
564002
 
564002
 		g_string_append (query,
564002
-				 "  ?file a ?type . "
564002
+				 "  ?content a ?type . "
564002
 				 "  FILTER ( ");
564002
 
564002
 		if (priv->scope & BRASERO_SEARCH_SCOPE_MUSIC) {
564002
-- 
564002
GitLab
564002
564002
564002
From 05589be7da3a0dfb00617df049d129abba703c36 Mon Sep 17 00:00:00 2001
564002
From: Carlos Garnacho <carlosg@gnome.org>
564002
Date: Thu, 24 Dec 2020 13:22:43 +0100
564002
Subject: [PATCH 5/5] Support Tracker 3.0
564002
564002
Add the compile-time checks, and add the minimal code catering for
564002
the API changes. In 3.0 connections are no longer singletons.
564002
---
564002
 configure.ac                 | 6 +++++-
564002
 src/brasero-search-tracker.c | 8 ++++++++
564002
 2 files changed, 13 insertions(+), 1 deletion(-)
564002
564002
diff --git a/configure.ac b/configure.ac
564002
index d0c7a870..96afc551 100644
564002
--- a/configure.ac
564002
+++ b/configure.ac
564002
@@ -388,7 +388,7 @@ AC_ARG_ENABLE(search,
564002
 if test x"$enable_search" != "xno"; then
564002
         # Try to figure out the tracker API version to use
564002
         tracker_api="0.10"
564002
-        m4_foreach([VERSION], [[0.10], [0.12], [0.14], [0.16], [0.18], [1.0], [2.0]],
564002
+        m4_foreach([VERSION], [[0.10], [0.12], [0.14], [0.16], [0.18], [1.0], [2.0], [3.0]],
564002
                               [PKG_CHECK_EXISTS([tracker-sparql-VERSION >= $TRACKER_REQUIRED],
564002
                                                 [tracker_api="VERSION"])
564002
                               ])
564002
@@ -408,6 +408,10 @@ if test x"$enable_search" = "xyes"; then
564002
 	AC_SUBST(BRASERO_SEARCH_LIBS)
564002
 	build_tracker="yes"
564002
 	build_search="yes"
564002
+
564002
+	if test x"$tracker_api" = x"3.0"; then
564002
+		AC_DEFINE(HAVE_TRACKER3, 1, [define if tracker3 is available])
564002
+	fi
564002
 else
564002
 	build_search="no"
564002
 fi
564002
diff --git a/src/brasero-search-tracker.c b/src/brasero-search-tracker.c
564002
index 9aa06289..40c5f1ac 100644
564002
--- a/src/brasero-search-tracker.c
564002
+++ b/src/brasero-search-tracker.c
564002
@@ -17,6 +17,8 @@
564002
  * with this program.  If not, see <http://www.gnu.org/licenses/>.
564002
  */
564002
 
564002
+#include "config.h"
564002
+
564002
 #include <stdlib.h>
564002
 
564002
 #include <libtracker-sparql/tracker-sparql.h>
564002
@@ -444,7 +446,13 @@ brasero_search_tracker_init (BraseroSearchTracker *object)
564002
 
564002
 	priv = BRASERO_SEARCH_TRACKER_PRIVATE (object);
564002
 	priv->cancellable = g_cancellable_new ();
564002
+
564002
+#ifdef HAVE_TRACKER3
564002
+	priv->connection = tracker_sparql_connection_bus_new ("org.freedesktop.Tracker3.Miner.Files",
564002
+							      NULL, NULL, &error);
564002
+#else
564002
 	priv->connection = tracker_sparql_connection_get (priv->cancellable, &error);
564002
+#endif
564002
 
564002
 	if (error) {
564002
 		g_warning ("Could not establish a connection to Tracker: %s", error->message);
564002
-- 
564002
GitLab
564002