[grilo-plugins] tracker: Allow partial SPARQL queries in query()



commit df9fb8f99a3f25a3d1725bce3b657dad4c872ff5
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Fri Jan 21 13:40:59 2011 +0100

    tracker: Allow partial SPARQL queries in query()
    
    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 116a59b..2d6e78b 100644
--- a/src/tracker/grl-tracker.c
+++ b/src/tracker/grl-tracker.c
@@ -71,6 +71,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 "                                       \
@@ -823,13 +830,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: id=%u", __FUNCTION__, qs->query_id);
@@ -841,6 +865,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 = tracker_operation_initiate (source, priv, qs->query_id);



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