[nautilus/sam/tracker-3: 2/7] search: Remove special characters from FTS searches
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/sam/tracker-3: 2/7] search: Remove special characters from FTS searches
- Date: Wed, 2 Sep 2020 15:28:46 +0000 (UTC)
commit 81ddd3b77f65a0913c2e732b0f6dddf750269b1c
Author: Sam Thursfield <sam afuera me uk>
Date: Wed Sep 2 17:27:22 2020 +0200
search: Remove special characters from FTS searches
This fixes warnings that would appear of this form:
** (org.gnome.Nautilus:662563): WARNING **: 17:11:13.712: Provider NautilusSearchEngineTracker failed
with error fts5: syntax error near "."
src/nautilus-search-engine-tracker.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-search-engine-tracker.c b/src/nautilus-search-engine-tracker.c
index 44f4a9cf6..77a9193c1 100644
--- a/src/nautilus-search-engine-tracker.c
+++ b/src/nautilus-search-engine-tracker.c
@@ -294,6 +294,27 @@ search_finished_idle (gpointer user_data)
*/
#define FILENAME_RANK "5.0"
+static gchar *
+filter_alnum_strdup (gchar *string)
+{
+ GString *filtered;
+ gchar *c;
+
+ filtered = g_string_new ("");
+ for (c = string; *c; c = g_utf8_next_char (c))
+ {
+ gunichar uc;
+
+ uc = g_utf8_get_char (c);
+ if (g_unichar_isalnum (uc))
+ g_string_append_unichar (filtered, uc);
+ else
+ g_string_append_c (filtered, ' ');
+ }
+
+ return g_string_free (filtered, FALSE);
+}
+
static void
nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
{
@@ -371,13 +392,16 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
if (tracker->fts_enabled)
{
/* Use fts:match only for content search to not lose some filename results due to stop words. */
+ g_autofree gchar *filtered_search_text;
+
+ filtered_search_text = filter_alnum_strdup (search_text);
g_string_append_printf (sparql,
" { "
" ?content nie:isStoredAs ?file ."
" ?content fts:match \"%s*\" ."
" BIND(fts:rank(?content) AS ?rank1) ."
" } UNION",
- search_text);
+ filtered_search_text);
}
g_string_append_printf (sparql,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]