[tracker/subqueries] libtracker-data: Add support for tracker:secondaryIndex
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/subqueries] libtracker-data: Add support for tracker:secondaryIndex
- Date: Mon, 18 Jan 2010 12:54:39 +0000 (UTC)
commit 0b95fec7445cca40546769af312abc22c2fa437f
Author: Jürg Billeter <j bitron ch>
Date: Mon Dec 7 17:48:45 2009 +0100
libtracker-data: Add support for tracker:secondaryIndex
This will create a two-column index in SQLite.
data/ontologies/11-rdf.ontology | 5 ++
data/ontologies/34-nmo.ontology | 1 +
src/libtracker-common/tracker-property.c | 55 +++++++++++++++++++++++++++
src/libtracker-common/tracker-property.h | 3 +
src/libtracker-data/tracker-data-manager.c | 57 ++++++++++++++++++++++------
5 files changed, 109 insertions(+), 12 deletions(-)
---
diff --git a/data/ontologies/11-rdf.ontology b/data/ontologies/11-rdf.ontology
index 4b0d051..1972265 100644
--- a/data/ontologies/11-rdf.ontology
+++ b/data/ontologies/11-rdf.ontology
@@ -75,6 +75,11 @@ tracker:indexed a rdf:Property ;
rdfs:domain rdf:Property ;
rdfs:range xsd:boolean .
+tracker:secondaryIndex a rdf:Property ;
+ nrl:maxCardinality 1 ;
+ rdfs:domain rdf:Property ;
+ rdfs:range rdf:Property .
+
tracker:fulltextIndexed a rdf:Property ;
nrl:maxCardinality 1 ;
rdfs:domain rdf:Property ;
diff --git a/data/ontologies/34-nmo.ontology b/data/ontologies/34-nmo.ontology
index 8ddf223..4878496 100644
--- a/data/ontologies/34-nmo.ontology
+++ b/data/ontologies/34-nmo.ontology
@@ -258,6 +258,7 @@ nmo:conversation a rdf:Property ;
nmo:communicationChannel a rdf:Property ;
rdfs:comment "Connects this message to a communication channel. Every message must only be in a single channel." ;
tracker:indexed true ;
+ tracker:secondaryIndex nmo:sentDate ;
nrl:maxCardinality 1 ;
rdfs:domain nmo:Message ;
rdfs:range nmo:CommunicationChannel .
diff --git a/src/libtracker-common/tracker-property.c b/src/libtracker-common/tracker-property.c
index 08b2593..f6a20bc 100644
--- a/src/libtracker-common/tracker-property.c
+++ b/src/libtracker-common/tracker-property.c
@@ -49,6 +49,7 @@ struct _TrackerPropertyPriv {
gint weight;
gint id;
gboolean indexed;
+ TrackerProperty *secondary_index;
gboolean fulltext_indexed;
gboolean embedded;
gboolean multiple_values;
@@ -78,6 +79,7 @@ enum {
PROP_RANGE,
PROP_WEIGHT,
PROP_INDEXED,
+ PROP_SECONDARY_INDEX,
PROP_FULLTEXT_INDEXED,
PROP_EMBEDDED,
PROP_MULTIPLE_VALUES,
@@ -218,6 +220,13 @@ tracker_property_class_init (TrackerPropertyClass *klass)
TRUE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
+ PROP_SECONDARY_INDEX,
+ g_param_spec_object ("secondary-index",
+ "secondary-index",
+ "Secondary index property",
+ TRACKER_TYPE_PROPERTY,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
PROP_FULLTEXT_INDEXED,
g_param_spec_boolean ("fulltext-indexed",
"fulltext-indexed",
@@ -298,6 +307,10 @@ property_finalize (GObject *object)
g_object_unref (priv->range);
}
+ if (priv->secondary_index) {
+ g_object_unref (priv->secondary_index);
+ }
+
g_array_free (priv->super_properties, TRUE);
(G_OBJECT_CLASS (tracker_property_parent_class)->finalize) (object);
@@ -338,6 +351,9 @@ property_get_property (GObject *object,
case PROP_INDEXED:
g_value_set_boolean (value, priv->indexed);
break;
+ case PROP_SECONDARY_INDEX:
+ g_value_set_object (value, priv->secondary_index);
+ break;
case PROP_FULLTEXT_INDEXED:
g_value_set_boolean (value, priv->fulltext_indexed);
break;
@@ -397,6 +413,10 @@ property_set_property (GObject *object,
tracker_property_set_indexed (TRACKER_PROPERTY (object),
g_value_get_boolean (value));
break;
+ case PROP_SECONDARY_INDEX:
+ tracker_property_set_secondary_index (TRACKER_PROPERTY (object),
+ g_value_get_object (value));
+ break;
case PROP_FULLTEXT_INDEXED:
tracker_property_set_fulltext_indexed (TRACKER_PROPERTY (object),
g_value_get_boolean (value));
@@ -578,6 +598,19 @@ tracker_property_get_indexed (TrackerProperty *field)
}
+TrackerProperty *
+tracker_property_get_secondary_index (TrackerProperty *field)
+{
+ TrackerPropertyPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_PROPERTY (field), NULL);
+
+ priv = GET_PRIV (field);
+
+ return priv->secondary_index;
+}
+
+
gboolean
tracker_property_get_fulltext_indexed (TrackerProperty *field)
{
@@ -830,6 +863,28 @@ tracker_property_set_indexed (TrackerProperty *field,
}
void
+tracker_property_set_secondary_index (TrackerProperty *field,
+ TrackerProperty *value)
+{
+ TrackerPropertyPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_PROPERTY (field));
+
+ priv = GET_PRIV (field);
+
+ if (priv->secondary_index) {
+ g_object_unref (priv->secondary_index);
+ priv->secondary_index = NULL;
+ }
+
+ if (value) {
+ priv->secondary_index = g_object_ref (value);
+ }
+
+ g_object_notify (G_OBJECT (field), "secondary-index");
+}
+
+void
tracker_property_set_fulltext_indexed (TrackerProperty *field,
gboolean value)
{
diff --git a/src/libtracker-common/tracker-property.h b/src/libtracker-common/tracker-property.h
index 1ec000d..3d68834 100644
--- a/src/libtracker-common/tracker-property.h
+++ b/src/libtracker-common/tracker-property.h
@@ -81,6 +81,7 @@ TrackerClass * tracker_property_get_range (TrackerProperty
gint tracker_property_get_weight (TrackerProperty *property);
gint tracker_property_get_id (TrackerProperty *property);
gboolean tracker_property_get_indexed (TrackerProperty *property);
+TrackerProperty * tracker_property_get_secondary_index (TrackerProperty *property);
gboolean tracker_property_get_fulltext_indexed (TrackerProperty *property);
gboolean tracker_property_get_embedded (TrackerProperty *property);
gboolean tracker_property_get_multiple_values (TrackerProperty *property);
@@ -103,6 +104,8 @@ void tracker_property_set_id (TrackerProperty
gint value);
void tracker_property_set_indexed (TrackerProperty *property,
gboolean value);
+void tracker_property_set_secondary_index (TrackerProperty *property,
+ TrackerProperty *value);
void tracker_property_set_fulltext_indexed (TrackerProperty *property,
gboolean value);
void tracker_property_set_embedded (TrackerProperty *property,
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index c36ffca..1c2b25d 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -223,6 +223,22 @@ load_ontology_statement (const gchar *ontology_file,
if (strcmp (object, "true") == 0) {
tracker_property_set_indexed (property, TRUE);
}
+ } else if (g_strcmp0 (predicate, TRACKER_PREFIX "secondaryIndex") == 0) {
+ TrackerProperty *property, *secondary_index;
+
+ property = tracker_ontology_get_property_by_uri (subject);
+ if (property == NULL) {
+ g_critical ("%s: Unknown property %s", ontology_file, subject);
+ continue;
+ }
+
+ secondary_index = tracker_ontology_get_property_by_uri (object);
+ if (secondary_index == NULL) {
+ g_critical ("%s: Unknown property %s", ontology_file, object);
+ continue;
+ }
+
+ tracker_property_set_secondary_index (property, secondary_index);
} else if (g_strcmp0 (predicate, TRACKER_PREFIX "transient") == 0) {
TrackerProperty *property;
@@ -628,6 +644,7 @@ db_get_static_data (TrackerDBInterface *iface)
"(SELECT Uri FROM \"rdfs:Resource\" WHERE ID = \"rdfs:range\"), "
"\"nrl:maxCardinality\", "
"\"tracker:indexed\", "
+ "(SELECT Uri FROM \"rdfs:Resource\" WHERE ID = \"tracker:secondaryIndex\"), "
"\"tracker:fulltextIndexed\", "
"\"tracker:transient\", "
"\"tracker:isAnnotation\", "
@@ -642,7 +659,7 @@ db_get_static_data (TrackerDBInterface *iface)
while (tracker_db_cursor_iter_next (cursor)) {
GValue value = { 0 };
TrackerProperty *property;
- const gchar *uri, *domain_uri, *range_uri;
+ const gchar *uri, *domain_uri, *range_uri, *secondary_index_uri;
gboolean multi_valued, indexed, fulltext_indexed;
gboolean transient, annotation, is_inverse_functional_property;
gint id;
@@ -675,7 +692,9 @@ db_get_static_data (TrackerDBInterface *iface)
indexed = FALSE;
}
- tracker_db_cursor_get_value (cursor, 6, &value);
+ secondary_index_uri = tracker_db_cursor_get_string (cursor, 6);
+
+ tracker_db_cursor_get_value (cursor, 7, &value);
if (G_VALUE_TYPE (&value) != 0) {
fulltext_indexed = (g_value_get_int (&value) == 1);
@@ -685,7 +704,7 @@ db_get_static_data (TrackerDBInterface *iface)
fulltext_indexed = FALSE;
}
- tracker_db_cursor_get_value (cursor, 7, &value);
+ tracker_db_cursor_get_value (cursor, 8, &value);
if (G_VALUE_TYPE (&value) != 0) {
transient = (g_value_get_int (&value) == 1);
@@ -695,7 +714,7 @@ db_get_static_data (TrackerDBInterface *iface)
transient = FALSE;
}
- tracker_db_cursor_get_value (cursor, 8, &value);
+ tracker_db_cursor_get_value (cursor, 9, &value);
if (G_VALUE_TYPE (&value) != 0) {
annotation = (g_value_get_int (&value) == 1);
@@ -705,7 +724,7 @@ db_get_static_data (TrackerDBInterface *iface)
annotation = FALSE;
}
- tracker_db_cursor_get_value (cursor, 9, &value);
+ tracker_db_cursor_get_value (cursor, 10, &value);
if (G_VALUE_TYPE (&value) != 0) {
is_inverse_functional_property = TRUE;
@@ -722,6 +741,9 @@ db_get_static_data (TrackerDBInterface *iface)
tracker_property_set_range (property, tracker_ontology_get_class_by_uri (range_uri));
tracker_property_set_multiple_values (property, multi_valued);
tracker_property_set_indexed (property, indexed);
+ if (secondary_index_uri) {
+ tracker_property_set_secondary_index (property, tracker_ontology_get_property_by_uri (secondary_index_uri));
+ }
tracker_property_set_fulltext_indexed (property, fulltext_indexed);
tracker_property_set_embedded (property, !annotation);
tracker_property_set_is_inverse_functional_property (property, is_inverse_functional_property);
@@ -914,7 +936,7 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
/* create index for single-valued fields */
for (field_it = class_properties; field_it != NULL; field_it = field_it->next) {
- TrackerProperty *field;
+ TrackerProperty *field, *secondary_index;
const char *field_name;
field = field_it->data;
@@ -922,12 +944,23 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
if (!tracker_property_get_multiple_values (field)
&& tracker_property_get_indexed (field)) {
field_name = tracker_property_get_name (field);
- tracker_db_interface_execute_query (iface, NULL,
- "CREATE INDEX \"%s_%s\" ON \"%s\" (\"%s\")",
- service_name,
- field_name,
- service_name,
- field_name);
+ secondary_index = tracker_property_get_secondary_index (field);
+ if (secondary_index == NULL) {
+ tracker_db_interface_execute_query (iface, NULL,
+ "CREATE INDEX \"%s_%s\" ON \"%s\" (\"%s\")",
+ service_name,
+ field_name,
+ service_name,
+ field_name);
+ } else {
+ tracker_db_interface_execute_query (iface, NULL,
+ "CREATE INDEX \"%s_%s\" ON \"%s\" (\"%s\", \"%s\")",
+ service_name,
+ field_name,
+ service_name,
+ field_name,
+ tracker_property_get_name (secondary_index));
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]