[PATCH 2/2] tracker: Allow partial SPARQL queries in query()
- From: "Juan A. Suarez Romero" <jasuarez igalia com>
- To: grilo-list gnome org
- Subject: [PATCH 2/2] tracker: Allow partial SPARQL queries in query()
- Date: Fri, 21 Jan 2011 17:03:45 +0100
Besides using a full query SPARQL sentence in the query() function, now
users can also use a partial query, specifying only the sentence that
will be used in the "WHERE" clause.
Plugin will build the complete full query using the metadata keys, count
and offset.
Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>
---
src/tracker/grl-tracker.c | 41 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 40 insertions(+), 1 deletions(-)
diff --git a/src/tracker/grl-tracker.c b/src/tracker/grl-tracker.c
index 186bafd..f8fc44d 100644
--- a/src/tracker/grl-tracker.c
+++ b/src/tracker/grl-tracker.c
@@ -69,6 +69,13 @@ enum {
/* --- Other --- */
+#define TRACKER_QUERY_REQUEST \
+ "SELECT rdf:type(?urn) %s " \
+ "WHERE { %s } " \
+ "ORDER BY DESC(nfo:fileLastModified(?urn)) " \
+ "OFFSET %i " \
+ "LIMIT %i"
+
#define TRACKER_SEARCH_REQUEST \
"SELECT rdf:type(?urn) %s " \
"WHERE " \
@@ -778,13 +785,30 @@ grl_tracker_source_supported_keys (GrlMetadataSource *source)
* WHERE { ?song a nmm:MusicPiece }
* </programlisting>
* </informalexample>
+ *
+ * Alternatively, we can use a partial SPARQL query: just specify the sentence
+ * in the WHERE part. In this case, "?urn" is the ontology concept to be used in
+ * the clause.
+ *
+ * An example of such partial query:
+ *
+ * <informalexample>
+ * <programlisting>
+ * ?urn a nfo:Media
+ * </programlisting>
+ * </informalexample>
+ *
+ * In this case, all data required to build a full SPARQL query will be get from
+ * the query spec.
*/
static void
grl_tracker_source_query (GrlMediaSource *source,
GrlMediaSourceQuerySpec *qs)
{
- GrlTrackerSourcePriv *priv = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
GError *error = NULL;
+ GrlTrackerSourcePriv *priv = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
+ gchar *sparql_final;
+ gchar *sparql_select;
struct OperationSpec *os;
GRL_DEBUG ("%s", __FUNCTION__);
@@ -796,6 +820,21 @@ grl_tracker_source_query (GrlMediaSource *source,
goto send_error;
}
+ /* Check if it is a full sparql query */
+ if (g_ascii_strncasecmp (qs->query, "select ", 7) != 0) {
+ sparql_select = get_select_string (source, qs->keys);
+ sparql_final = g_strdup_printf (TRACKER_QUERY_REQUEST,
+ sparql_select,
+ qs->query,
+ qs->skip,
+ qs->count);
+ g_free (qs->query);
+ g_free (sparql_select);
+ qs->query = sparql_final;
+ grl_tracker_source_query (source, qs);
+ return;
+ }
+
GRL_DEBUG ("select : %s", qs->query);
os = g_slice_new0 (struct OperationSpec);
--
1.7.3.4
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]