[tracker-miners/wip/carlosg/tracker-3.0-api-breaks: 37/40] data: Add FTS config gschemas here



commit 076e06a34c0953f41629c9589ae0023713a2363e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Feb 12 14:32:30 2020 +0100

    data: Add FTS config gschemas here
    
    The tracker repo no longer deals with GSettings by itself, add
    the FTS schema here, so miners can honor the settings themselves.
    
    The corresponding TrackerFTSConfig object has been added to
    libtracker-miners-common, in order to help deal with those settings.

 data/meson.build                                  |   1 +
 data/org.freedesktop.Tracker.FTS.gschema.xml      |  48 ++++
 po/POTFILES.in                                    |   1 +
 src/libtracker-miners-common/meson.build          |   1 +
 src/libtracker-miners-common/tracker-common.h     |   1 +
 src/libtracker-miners-common/tracker-fts-config.c | 321 ++++++++++++++++++++++
 src/libtracker-miners-common/tracker-fts-config.h |  66 +++++
 7 files changed, 439 insertions(+)
---
diff --git a/data/meson.build b/data/meson.build
index fc9cc68f8..559144b9c 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -1,5 +1,6 @@
 schemas = [
   'org.freedesktop.Tracker.Extract.gschema.xml',
+  'org.freedesktop.Tracker.FTS.gschema.xml',
   'org.freedesktop.Tracker.Miner.Files.gschema.xml',
   'org.freedesktop.Tracker.Writeback.gschema.xml',
 ]
diff --git a/data/org.freedesktop.Tracker.FTS.gschema.xml b/data/org.freedesktop.Tracker.FTS.gschema.xml
new file mode 100644
index 000000000..8129ca735
--- /dev/null
+++ b/data/org.freedesktop.Tracker.FTS.gschema.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (C) 2011, Nokia <ivan frade nokia com>
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA  02110-1301, USA.
+-->
+<schemalist>
+  <schema id="org.freedesktop.Tracker.FTS" path="/org/freedesktop/tracker/fts/" 
gettext-domain="tracker-miners">
+
+    <key name="enable-stemmer" type="b">
+      <summary>Enable stemmer</summary>
+      <description>Simplify the words to their root to provide more results. E.g. “shelves” and “shelf” to 
“shel”</description>
+      <default>false</default>
+    </key>
+
+    <key name="enable-unaccent" type="b">
+      <summary>Enable unaccent</summary>
+      <description>Translate accented characters to the equivalent unaccented. E.g. “Idéa” to “Idea” for 
improved matching. </description>
+      <default>true</default>
+    </key>
+
+    <key name="ignore-numbers" type="b">
+      <summary>Ignore numbers</summary>
+      <description>If enabled, numbers will not be indexed.</description>
+      <default>true</default>
+    </key>
+
+    <key name="ignore-stop-words" type="b">
+      <summary>Ignore stop words</summary>
+      <description>If enabled, the words listed in the stop-words list are ignored. E.g. common words like 
“the”, “yes”, “no”, etc.</description>
+      <default>true</default>
+    </key>
+
+  </schema>
+</schemalist>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1eee717b8..1863c61f9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,6 +1,7 @@
 # List of source files containing translatable strings.
 # Please keep this file sorted alphabetically.
 data/org.freedesktop.Tracker.Extract.gschema.xml
+data/org.freedesktop.Tracker.FTS.gschema.xml
 data/org.freedesktop.Tracker.Miner.Files.gschema.xml
 data/org.freedesktop.Tracker.Writeback.gschema.xml
 src/libtracker-miners-common/tracker-dbus.c
diff --git a/src/libtracker-miners-common/meson.build b/src/libtracker-miners-common/meson.build
index 096639eac..441209439 100644
--- a/src/libtracker-miners-common/meson.build
+++ b/src/libtracker-miners-common/meson.build
@@ -11,6 +11,7 @@ tracker_miners_common_sources = [
   'tracker-dbus.c',
   'tracker-domain-ontology.c',
   'tracker-file-utils.c',
+  'tracker-fts-config.c',
   'tracker-ioprio.c',
   'tracker-log.c',
   'tracker-sched.c',
diff --git a/src/libtracker-miners-common/tracker-common.h b/src/libtracker-miners-common/tracker-common.h
index ed9bcad06..65f2542d9 100644
--- a/src/libtracker-miners-common/tracker-common.h
+++ b/src/libtracker-miners-common/tracker-common.h
@@ -32,6 +32,7 @@
 #include "tracker-dbus.h"
 #include "tracker-domain-ontology.h"
 #include "tracker-file-utils.h"
+#include "tracker-fts-config.h"
 #include "tracker-ioprio.h"
 #include "tracker-log.h"
 #include "tracker-sched.h"
diff --git a/src/libtracker-miners-common/tracker-fts-config.c 
b/src/libtracker-miners-common/tracker-fts-config.c
new file mode 100644
index 000000000..a8df15cd8
--- /dev/null
+++ b/src/libtracker-miners-common/tracker-fts-config.c
@@ -0,0 +1,321 @@
+/*
+ * Copyright (C) 2009, Nokia <ivan frade nokia com>
+ * Copyright (C) 2014, Lanedo <martyn lanedo com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301  USA
+ */
+
+#include "config-miners.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define G_SETTINGS_ENABLE_BACKEND
+#include <gio/gsettingsbackend.h>
+
+#include "tracker-fts-config.h"
+
+#define CONFIG_SCHEMA "org.freedesktop.Tracker.FTS"
+#define CONFIG_PATH   "/org/freedesktop/tracker/fts/"
+
+/* Default values */
+#define DEFAULT_IGNORE_NUMBERS       TRUE
+#define DEFAULT_IGNORE_STOP_WORDS    TRUE
+#define DEFAULT_ENABLE_STEMMER       FALSE  /* As per GB#526346, disabled */
+#define DEFAULT_ENABLE_UNACCENT      TRUE
+
+static void config_set_property         (GObject       *object,
+                                         guint          param_id,
+                                         const GValue  *value,
+                                         GParamSpec    *pspec);
+static void config_get_property         (GObject       *object,
+                                         guint          param_id,
+                                         GValue        *value,
+                                         GParamSpec    *pspec);
+static void config_finalize             (GObject       *object);
+static void config_constructed          (GObject       *object);
+
+enum {
+       PROP_0,
+
+       /* Indexing */
+       PROP_ENABLE_STEMMER,
+       PROP_ENABLE_UNACCENT,
+       PROP_IGNORE_NUMBERS,
+       PROP_IGNORE_STOP_WORDS,
+};
+
+G_DEFINE_TYPE (TrackerFTSConfig, tracker_fts_config, G_TYPE_SETTINGS);
+
+static void
+tracker_fts_config_class_init (TrackerFTSConfigClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->set_property = config_set_property;
+       object_class->get_property = config_get_property;
+       object_class->finalize     = config_finalize;
+       object_class->constructed  = config_constructed;
+
+       /* Indexing */
+       g_object_class_install_property (object_class,
+                                        PROP_ENABLE_STEMMER,
+                                        g_param_spec_boolean ("enable-stemmer",
+                                                              "Enable Stemmer",
+                                                              " Flag to enable word stemming utility 
(default=FALSE)",
+                                                              DEFAULT_ENABLE_STEMMER,
+                                                              G_PARAM_READWRITE));
+       g_object_class_install_property (object_class,
+                                        PROP_ENABLE_UNACCENT,
+                                        g_param_spec_boolean ("enable-unaccent",
+                                                              "Enable Unaccent",
+                                                              " Flag to enable word unaccenting 
(default=TRUE)",
+                                                              DEFAULT_ENABLE_UNACCENT,
+                                                              G_PARAM_READWRITE));
+       g_object_class_install_property (object_class,
+                                        PROP_IGNORE_NUMBERS,
+                                        g_param_spec_boolean ("ignore-numbers",
+                                                              "Ignore numbers",
+                                                              " Flag to ignore numbers in FTS 
(default=TRUE)",
+                                                              DEFAULT_IGNORE_NUMBERS,
+                                                              G_PARAM_READWRITE));
+       g_object_class_install_property (object_class,
+                                        PROP_IGNORE_STOP_WORDS,
+                                        g_param_spec_boolean ("ignore-stop-words",
+                                                              "Ignore stop words",
+                                                              " Flag to ignore stop words in FTS 
(default=TRUE)",
+                                                              DEFAULT_IGNORE_STOP_WORDS,
+                                                              G_PARAM_READWRITE));
+}
+
+static void
+tracker_fts_config_init (TrackerFTSConfig *object)
+{
+}
+
+static void
+config_set_property (GObject      *object,
+                     guint         param_id,
+                     const GValue *value,
+                     GParamSpec   *pspec)
+{
+       switch (param_id) {
+               /* Indexing */
+       case PROP_ENABLE_STEMMER:
+               tracker_fts_config_set_enable_stemmer (TRACKER_FTS_CONFIG (object),
+                                                      g_value_get_boolean (value));
+               break;
+       case PROP_ENABLE_UNACCENT:
+               tracker_fts_config_set_enable_unaccent (TRACKER_FTS_CONFIG (object),
+                                                       g_value_get_boolean (value));
+               break;
+       case PROP_IGNORE_NUMBERS:
+               tracker_fts_config_set_ignore_numbers (TRACKER_FTS_CONFIG (object),
+                                                      g_value_get_boolean (value));
+               break;
+       case PROP_IGNORE_STOP_WORDS:
+               tracker_fts_config_set_ignore_stop_words (TRACKER_FTS_CONFIG (object),
+                                                         g_value_get_boolean (value));
+               break;
+
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+               break;
+       };
+}
+
+static void
+config_get_property (GObject    *object,
+                     guint       param_id,
+                     GValue     *value,
+                     GParamSpec *pspec)
+{
+        TrackerFTSConfig *config = TRACKER_FTS_CONFIG (object);
+
+       switch (param_id) {
+               /* Indexing */
+       case PROP_ENABLE_STEMMER:
+               g_value_set_boolean (value, tracker_fts_config_get_enable_stemmer (config));
+               break;
+       case PROP_ENABLE_UNACCENT:
+               g_value_set_boolean (value, tracker_fts_config_get_enable_unaccent (config));
+               break;
+       case PROP_IGNORE_NUMBERS:
+               g_value_set_boolean (value, tracker_fts_config_get_ignore_numbers (config));
+               break;
+       case PROP_IGNORE_STOP_WORDS:
+               g_value_set_boolean (value, tracker_fts_config_get_ignore_stop_words (config));
+               break;
+
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+               break;
+       };
+}
+
+static void
+config_finalize (GObject *object)
+{
+       /* For now we do nothing here, we left this override in for
+        * future expansion.
+        */
+
+       (G_OBJECT_CLASS (tracker_fts_config_parent_class)->finalize) (object);
+}
+
+static void
+config_constructed (GObject *object)
+{
+       GSettings *settings;
+
+       (G_OBJECT_CLASS (tracker_fts_config_parent_class)->constructed) (object);
+
+       settings = G_SETTINGS (object);
+
+       if (G_LIKELY (!g_getenv ("TRACKER_USE_CONFIG_FILES"))) {
+               g_settings_delay (settings);
+       }
+
+       g_settings_bind (settings, "enable-stemmer", object, "enable-stemmer", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
+       g_settings_bind (settings, "enable-unaccent", object, "enable-unaccent", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
+       g_settings_bind (settings, "ignore-numbers", object, "ignore-numbers", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
+       g_settings_bind (settings, "ignore-stop-words", object, "ignore-stop-words", G_SETTINGS_BIND_GET | 
G_SETTINGS_BIND_GET_NO_CHANGES);
+}
+
+TrackerFTSConfig *
+tracker_fts_config_new (void)
+{
+       TrackerFTSConfig *config = NULL;
+
+       /* FIXME: should we unset GSETTINGS_BACKEND env var? */
+
+       if (G_UNLIKELY (g_getenv ("TRACKER_USE_CONFIG_FILES"))) {
+               GSettingsBackend *backend;
+               gchar *filename;
+               gboolean need_to_save;
+
+               filename = g_build_filename (g_get_user_config_dir (), "tracker", "tracker-fts.cfg", NULL);
+
+               need_to_save = g_file_test (filename, G_FILE_TEST_EXISTS) == FALSE;
+
+               backend = g_keyfile_settings_backend_new (filename, CONFIG_PATH, "General");
+               g_info ("Using config file '%s'", filename);
+               g_free (filename);
+
+               config = g_object_new (TRACKER_TYPE_FTS_CONFIG,
+                                      "backend", backend,
+                                      "schema-id", CONFIG_SCHEMA,
+                                      "path", CONFIG_PATH,
+                                      NULL);
+               g_object_unref (backend);
+
+               if (need_to_save) {
+                       g_info ("  Config file does not exist, using default values...");
+               }
+       } else {
+               config = g_object_new (TRACKER_TYPE_FTS_CONFIG,
+                                      "schema-id", CONFIG_SCHEMA,
+                                      "path", CONFIG_PATH,
+                                      NULL);
+       }
+
+       return config;
+}
+
+gboolean
+tracker_fts_config_save (TrackerFTSConfig *config)
+{
+       g_return_val_if_fail (TRACKER_IS_FTS_CONFIG (config), FALSE);
+
+        g_settings_apply (G_SETTINGS (config));
+
+       return TRUE;
+}
+
+gboolean
+tracker_fts_config_get_enable_stemmer (TrackerFTSConfig *config)
+{
+       g_return_val_if_fail (TRACKER_IS_FTS_CONFIG (config), DEFAULT_ENABLE_STEMMER);
+
+       return g_settings_get_boolean (G_SETTINGS (config), "enable-stemmer");
+}
+
+gboolean
+tracker_fts_config_get_enable_unaccent (TrackerFTSConfig *config)
+{
+       g_return_val_if_fail (TRACKER_IS_FTS_CONFIG (config), DEFAULT_ENABLE_UNACCENT);
+
+       return g_settings_get_boolean (G_SETTINGS (config), "enable-unaccent");
+}
+
+gboolean
+tracker_fts_config_get_ignore_numbers (TrackerFTSConfig *config)
+{
+       g_return_val_if_fail (TRACKER_IS_FTS_CONFIG (config), DEFAULT_IGNORE_NUMBERS);
+
+       return g_settings_get_boolean (G_SETTINGS (config), "ignore-numbers");
+}
+
+gboolean
+tracker_fts_config_get_ignore_stop_words (TrackerFTSConfig *config)
+{
+       g_return_val_if_fail (TRACKER_IS_FTS_CONFIG (config), DEFAULT_IGNORE_STOP_WORDS);
+
+       return g_settings_get_boolean (G_SETTINGS (config),  "ignore-stop-words");
+}
+
+void
+tracker_fts_config_set_enable_stemmer (TrackerFTSConfig *config,
+                                       gboolean          value)
+{
+       g_return_if_fail (TRACKER_IS_FTS_CONFIG (config));
+
+        g_settings_set_boolean (G_SETTINGS (config), "enable-stemmer", value);
+       g_object_notify (G_OBJECT (config), "enable-stemmer");
+}
+
+void
+tracker_fts_config_set_enable_unaccent (TrackerFTSConfig *config,
+                                       gboolean          value)
+{
+       g_return_if_fail (TRACKER_IS_FTS_CONFIG (config));
+
+        g_settings_set_boolean (G_SETTINGS (config), "enable-unaccent", value);
+       g_object_notify (G_OBJECT (config), "enable-unaccent");
+}
+
+void
+tracker_fts_config_set_ignore_numbers (TrackerFTSConfig *config,
+                                       gboolean          value)
+{
+       g_return_if_fail (TRACKER_IS_FTS_CONFIG (config));
+
+        g_settings_set_boolean (G_SETTINGS (config), "ignore-numbers", value);
+       g_object_notify (G_OBJECT (config), "ignore-numbers");
+}
+
+void
+tracker_fts_config_set_ignore_stop_words (TrackerFTSConfig *config,
+                                          gboolean          value)
+{
+       g_return_if_fail (TRACKER_IS_FTS_CONFIG (config));
+
+        g_settings_set_boolean (G_SETTINGS (config), "ignore-stop-words", value);
+       g_object_notify (G_OBJECT (config), "ignore-stop-words");
+}
diff --git a/src/libtracker-miners-common/tracker-fts-config.h 
b/src/libtracker-miners-common/tracker-fts-config.h
new file mode 100644
index 000000000..3c02cc530
--- /dev/null
+++ b/src/libtracker-miners-common/tracker-fts-config.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2009, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301  USA
+ */
+
+#ifndef __TRACKER_FTS_CONFIG_H__
+#define __TRACKER_FTS_CONFIG_H__
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_FTS_CONFIG         (tracker_fts_config_get_type ())
+#define TRACKER_FTS_CONFIG(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_FTS_CONFIG, 
TrackerFTSConfig))
+#define TRACKER_FTS_CONFIG_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_FTS_CONFIG, 
TrackerFTSConfigClass))
+#define TRACKER_IS_FTS_CONFIG(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_FTS_CONFIG))
+#define TRACKER_IS_FTS_CONFIG_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_FTS_CONFIG))
+#define TRACKER_FTS_CONFIG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_FTS_CONFIG, 
TrackerFTSConfigClass))
+
+typedef struct TrackerFTSConfig              TrackerFTSConfig;
+typedef struct TrackerFTSConfigClass TrackerFTSConfigClass;
+
+struct TrackerFTSConfig {
+        GSettings parent;
+};
+
+struct TrackerFTSConfigClass {
+        GSettingsClass parent_class;
+};
+
+GType             tracker_fts_config_get_type               (void) G_GNUC_CONST;
+
+TrackerFTSConfig *tracker_fts_config_new                    (void);
+gboolean          tracker_fts_config_save                   (TrackerFTSConfig *config);
+gboolean          tracker_fts_config_get_enable_stemmer     (TrackerFTSConfig *config);
+gboolean          tracker_fts_config_get_enable_unaccent    (TrackerFTSConfig *config);
+gboolean          tracker_fts_config_get_ignore_numbers     (TrackerFTSConfig *config);
+gboolean          tracker_fts_config_get_ignore_stop_words  (TrackerFTSConfig *config);
+void              tracker_fts_config_set_enable_stemmer     (TrackerFTSConfig *config,
+                                                             gboolean          value);
+void              tracker_fts_config_set_enable_unaccent    (TrackerFTSConfig *config,
+                                                             gboolean          value);
+void              tracker_fts_config_set_ignore_numbers     (TrackerFTSConfig *config,
+                                                             gboolean          value);
+void              tracker_fts_config_set_ignore_stop_words  (TrackerFTSConfig *config,
+                                                             gboolean          value);
+
+G_END_DECLS
+
+#endif /* __TRACKER_FTS_CONFIG_H__ */
+


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