[nautilus/wip/antoniof/search-list-redesign: 3/3] search-engine-tracker: Elaborate snippet




commit ffeaa03e03ae5f344e27b79ad95175599f5bdb00
Author: António Fernandes <antoniof gnome org>
Date:   Wed Aug 3 10:03:05 2022 +0100

    search-engine-tracker: Elaborate snippet
    
    Extend snippet up to 20 words ("tokens" in database parlance).
    
    Highlight matching word using pango markup.

 src/nautilus-name-cell.c             |  2 +-
 src/nautilus-search-engine-tracker.c | 19 +++++++++++++++++--
 2 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/src/nautilus-name-cell.c b/src/nautilus-name-cell.c
index 9ee18c95a..7919a5282 100644
--- a/src/nautilus-name-cell.c
+++ b/src/nautilus-name-cell.c
@@ -113,7 +113,7 @@ update_labels (NautilusNameCell *self)
 
     gtk_label_set_text (GTK_LABEL (self->label), display_name);
     gtk_label_set_text (GTK_LABEL (self->path), path_text);
-    gtk_label_set_text (GTK_LABEL (self->snippet), fts_snippet);
+    gtk_label_set_markup (GTK_LABEL (self->snippet), fts_snippet);
 
     gtk_widget_set_visible (self->path, (path_text != NULL));
     gtk_widget_set_visible (self->snippet_button, (fts_snippet != NULL));
diff --git a/src/nautilus-search-engine-tracker.c b/src/nautilus-search-engine-tracker.c
index e0c2c8c8d..ef9a8a91d 100644
--- a/src/nautilus-search-engine-tracker.c
+++ b/src/nautilus-search-engine-tracker.c
@@ -217,7 +217,18 @@ cursor_callback (GObject      *object,
     if (tracker->fts_enabled)
     {
         snippet = tracker_sparql_cursor_get_string (cursor, 5, NULL);
-        nautilus_search_hit_set_fts_snippet (hit, snippet);
+        if (snippet != NULL)
+        {
+            g_autofree gchar *escaped = NULL;
+            g_autoptr (GString) buffer = NULL;
+            /* Escape for markup, before adding our own markup. */
+            escaped = g_markup_escape_text (snippet, -1);
+            buffer = g_string_new (escaped);
+            g_string_replace (buffer, "_NAUTILUS_SNIPPET_DELIM_START_", "<b>", 0);
+            g_string_replace (buffer, "_NAUTILUS_SNIPPET_DELIM_END_", "</b>", 0);
+
+            nautilus_search_hit_set_fts_snippet (hit, buffer->str);
+        }
     }
 
     if (g_time_val_from_iso8601 (mtime_str, &tv))
@@ -357,7 +368,11 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
 
     if (tracker->fts_enabled && *search_text)
     {
-        g_string_append (sparql, " fts:snippet(?content)");
+        g_string_append (sparql, " fts:snippet(?content, "
+                                               "'_NAUTILUS_SNIPPET_DELIM_START_', "
+                                               "'_NAUTILUS_SNIPPET_DELIM_END_', "
+                                               "'…', "
+                                               "20)");
     }
 
     g_string_append (sparql, "FROM tracker:FileSystem ");


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