[nautilus/wip/alexpandelea/fts] implement fts
- From: Alexandru-Ionut Pandelea <alexpandelea src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/alexpandelea/fts] implement fts
- Date: Thu, 1 Jun 2017 09:27:38 +0000 (UTC)
commit e5172914279e32be36fb373ffe8f98d1baa70bee
Author: Alexandru Pandelea <alexandru pandelea gmail com>
Date: Fri May 26 23:22:12 2017 +0300
implement fts
src/nautilus-file-private.h | 1 +
src/nautilus-file.c | 18 +++++++
src/nautilus-file.h | 4 ++
src/nautilus-list-view.c | 66 ++++++++++++++++++++++++++-
src/nautilus-query-editor.c | 26 +++++++++++
src/nautilus-search-directory.c | 1 +
src/nautilus-search-engine-tracker.c | 20 +++++++--
src/nautilus-search-hit.c | 28 +++++++++++
src/nautilus-search-hit.h | 4 +-
src/nautilus-search-popover.c | 46 +++++++++++++++++++
src/nautilus-search-popover.h | 2 +
src/resources/ui/nautilus-search-popover.ui | 4 ++
12 files changed, 213 insertions(+), 7 deletions(-)
---
diff --git a/src/nautilus-file-private.h b/src/nautilus-file-private.h
index d040a51..adcfacf 100644
--- a/src/nautilus-file-private.h
+++ b/src/nautilus-file-private.h
@@ -208,6 +208,7 @@ struct NautilusFileDetails
time_t recency; /* 0 is unknown */
gdouble search_relevance;
+ gchar *fts_snippet;
guint64 free_space; /* (guint)-1 for unknown */
time_t free_space_read; /* The time free_space was updated, or 0 for never */
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index e7e96dc..f448287 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -922,6 +922,11 @@ finalize (GObject *object)
metadata_hash_free (file->details->metadata);
}
+ if (file->details->fts_snippet)
+ {
+ g_free (file->details->fts_snippet);
+ }
+
G_OBJECT_CLASS (nautilus_file_parent_class)->finalize (object);
}
@@ -6149,6 +6154,19 @@ nautilus_file_set_search_relevance (NautilusFile *file,
file->details->search_relevance = relevance;
}
+void
+nautilus_file_set_search_fts_snippet (NautilusFile *file,
+ gchar *fts_snippet)
+{
+ file->details->fts_snippet = g_strdup (fts_snippet);
+}
+
+gchar*
+nautilus_file_get_search_fts_snippet (NautilusFile *file)
+{
+ return file->details->fts_snippet;
+}
+
/**
* nautilus_file_can_get_permissions:
*
diff --git a/src/nautilus-file.h b/src/nautilus-file.h
index e941e7a..62c6017 100644
--- a/src/nautilus-file.h
+++ b/src/nautilus-file.h
@@ -237,6 +237,10 @@ gboolean nautilus_file_should_show_directory_item_count (Nautilu
void nautilus_file_set_search_relevance (NautilusFile
*file,
gdouble
relevance);
+void nautilus_file_set_search_fts_snippet (NautilusFile
*file,
+ gchar
*fts_snippet);
+gchar* nautilus_file_get_search_fts_snippet (NautilusFile
*file);
+
void nautilus_file_set_attributes (NautilusFile
*file,
GFileInfo
*attributes,
NautilusFileOperationCallback
callback,
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index aa0e5a3..95aa2a6 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -37,6 +37,7 @@
#include <eel/eel-vfs-extensions.h>
#include <eel/eel-gdk-extensions.h>
#include <eel/eel-glib-extensions.h>
+#include <eel/eel-string.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
@@ -1552,13 +1553,35 @@ filename_cell_data_func (GtkTreeViewColumn *column,
NautilusListView *view)
{
char *text;
+ g_autofree gchar *escaped_text = NULL;
+ g_autofree gchar *replaced_text = NULL;
GtkTreePath *path;
PangoUnderline underline;
+ GString *display_text;
+ NautilusDirectory *directory;
+ NautilusQuery *query = NULL;
+ NautilusQuerySearchContent content;
+ NautilusFile *file;
+ gchar *snippet;
gtk_tree_model_get (model, iter,
view->details->file_name_column_num, &text,
-1);
+ display_text = g_string_new(text);
+
+ directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (view));
+
+ if (NAUTILUS_IS_SEARCH_DIRECTORY (directory))
+ {
+ query = nautilus_search_directory_get_query (NAUTILUS_SEARCH_DIRECTORY (directory));
+ }
+
+ if (query)
+ {
+ content = nautilus_query_get_search_content (query);
+ }
+
if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
{
path = gtk_tree_model_get_path (model, iter);
@@ -1580,11 +1603,30 @@ filename_cell_data_func (GtkTreeViewColumn *column,
underline = PANGO_UNDERLINE_NONE;
}
+ if (query && content == NAUTILUS_QUERY_SEARCH_CONTENT_FULL_TEXT)
+ {
+ gtk_tree_model_get (model, iter,
+ NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
+ -1);
+
+ snippet = nautilus_file_get_search_fts_snippet (file);
+ if (snippet)
+ {
+ replaced_text = eel_str_replace_substring (snippet, "\n", "");
+ escaped_text = g_markup_escape_text (replaced_text, g_utf8_strlen (replaced_text, -1));
+ g_string_append_printf (display_text, "\n<small><span color='grey'>%s</span></small>",
escaped_text);
+ }
+
+ nautilus_file_unref (file);
+ }
+
g_object_set (G_OBJECT (renderer),
- "text", text,
+ "markup", display_text->str,
"underline", underline,
NULL);
+
g_free (text);
+ g_string_free (display_text, TRUE);
}
static void
@@ -1798,6 +1840,9 @@ create_and_set_up_tree_view (NautilusListView *view)
GList *l;
gchar **default_column_order, **default_visible_columns;
GtkWidget *content_widget;
+ NautilusDirectory *directory = NULL;
+ NautilusQuery *query = NULL;
+ NautilusQuerySearchContent content;
content_widget = nautilus_files_view_get_content_widget (NAUTILUS_FILES_VIEW (view));
view->details->tree_view = GTK_TREE_VIEW (gtk_tree_view_new ());
@@ -1953,11 +1998,28 @@ create_and_set_up_tree_view (NautilusListView *view)
view->details->file_name_cell = (GtkCellRendererText *) cell;
g_object_set (cell,
"ellipsize", PANGO_ELLIPSIZE_END,
- "single-paragraph-mode", TRUE,
+ "single-paragraph-mode", FALSE,
"width-chars", 30,
"xpad", 5,
NULL);
+ directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (view));
+ if (NAUTILUS_IS_SEARCH_DIRECTORY (directory))
+ {
+ query = nautilus_search_directory_get_query (NAUTILUS_SEARCH_DIRECTORY (directory));
+ }
+
+ if (query)
+ {
+ content = nautilus_query_get_search_content (query);
+ }
+
+ if (query && content == NAUTILUS_QUERY_SEARCH_CONTENT_FULL_TEXT)
+ {
+ gtk_cell_renderer_text_set_fixed_height_from_font (GTK_CELL_RENDERER_TEXT (cell), 2);
+ g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_MIDDLE, NULL);
+ }
+
gtk_tree_view_column_pack_start (view->details->file_name_column, cell, TRUE);
gtk_tree_view_column_set_cell_data_func (view->details->file_name_column, cell,
(GtkTreeCellDataFunc) filename_cell_data_func,
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c
index 5d9eca9..869e2e7 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -376,14 +376,19 @@ create_query (NautilusQueryEditor *editor)
NautilusQuery *query;
NautilusFile *file;
gboolean recursive;
+ gboolean fts_enabled;
priv = nautilus_query_editor_get_instance_private (editor);
g_return_if_fail (!priv->query);
+ fts_enabled = nautilus_search_popover_get_fts_enabled (NAUTILUS_SEARCH_POPOVER (priv->popover));
+
file = nautilus_file_get (priv->location);
query = nautilus_query_new ();
+ nautilus_query_set_search_content (query, fts_enabled);
+
recursive = settings_search_is_recursive (editor);
nautilus_query_set_text (query, gtk_entry_get_text (GTK_ENTRY (priv->entry)));
@@ -571,6 +576,25 @@ search_popover_time_type_changed_cb (NautilusSearchPopover *popover,
}
static void
+search_popover_fts_changed_cb (NautilusSearchPopover *popover,
+ NautilusQuerySearchContent content,
+ NautilusQueryEditor *editor)
+{
+ NautilusQueryEditorPrivate *priv;
+
+ priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
+
+ if (!priv->query)
+ {
+ create_query (editor);
+ }
+
+ nautilus_query_set_search_content (priv->query, content);
+
+ nautilus_query_editor_changed (editor);
+}
+
+static void
entry_tag_clicked (NautilusQueryEditor *editor)
{
NautilusQueryEditorPrivate *priv;
@@ -672,6 +696,8 @@ setup_widgets (NautilusQueryEditor *editor)
G_CALLBACK (search_popover_mime_type_changed_cb), editor);
g_signal_connect (priv->popover, "time-type",
G_CALLBACK (search_popover_time_type_changed_cb), editor);
+ g_signal_connect (priv->popover, "fts-change",
+ G_CALLBACK (search_popover_fts_changed_cb), editor);
/* show everything */
gtk_widget_show_all (vbox);
diff --git a/src/nautilus-search-directory.c b/src/nautilus-search-directory.c
index 959193b..d51f4f8 100644
--- a/src/nautilus-search-directory.c
+++ b/src/nautilus-search-directory.c
@@ -628,6 +628,7 @@ search_engine_hits_added (NautilusSearchEngine *engine,
file = nautilus_file_get_by_uri (uri);
nautilus_file_set_search_relevance (file, nautilus_search_hit_get_relevance (hit));
+ nautilus_file_set_search_fts_snippet (file, nautilus_search_hit_get_fts_snippet (hit));
for (monitor_list = search->details->monitor_list; monitor_list; monitor_list = monitor_list->next)
{
diff --git a/src/nautilus-search-engine-tracker.c b/src/nautilus-search-engine-tracker.c
index 38126bb..1914a22 100644
--- a/src/nautilus-search-engine-tracker.c
+++ b/src/nautilus-search-engine-tracker.c
@@ -41,6 +41,7 @@ struct NautilusSearchEngineTrackerDetails
GQueue *hits_pending;
gboolean recursive;
+ gboolean fts_enabled;
GCancellable *cancellable;
};
@@ -174,6 +175,7 @@ cursor_callback (GObject *object,
const char *uri;
const char *mtime_str;
const char *atime_str;
+ const gchar *snippet;
GTimeVal tv;
gdouble rank, match;
gboolean success;
@@ -199,6 +201,7 @@ cursor_callback (GObject *object,
rank = tracker_sparql_cursor_get_double (cursor, 1);
mtime_str = tracker_sparql_cursor_get_string (cursor, 2, NULL);
atime_str = tracker_sparql_cursor_get_string (cursor, 3, NULL);
+ snippet = tracker_sparql_cursor_get_string (cursor, 4, NULL);
basename = g_path_get_basename (uri);
hit = nautilus_search_hit_new (uri);
@@ -206,6 +209,11 @@ cursor_callback (GObject *object,
nautilus_search_hit_set_fts_rank (hit, rank + match);
g_free (basename);
+ if (tracker->details->fts_enabled)
+ {
+ nautilus_search_hit_set_fts_snippet (hit, snippet);
+ }
+
if (g_time_val_from_iso8601 (mtime_str, &tv))
{
GDateTime *date;
@@ -311,6 +319,8 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
g_settings_get_enum (nautilus_preferences, "recursive-search") ==
NAUTILUS_SPEED_TRADEOFF_ALWAYS;
tracker->details->recursive = recursive;
+ tracker->details->fts_enabled = nautilus_query_get_search_content (tracker->details->query);
+
query_text = nautilus_query_get_text (tracker->details->query);
downcase = g_utf8_strdown (query_text, -1);
search_text = tracker_sparql_escape_string (downcase);
@@ -322,14 +332,13 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
mimetypes = nautilus_query_get_mime_types (tracker->details->query);
mime_count = g_list_length (mimetypes);
- sparql = g_string_new ("SELECT DISTINCT nie:url(?urn) fts:rank(?urn) nfo:fileLastModified(?urn)
nfo:fileLastAccessed(?urn)\n"
+ sparql = g_string_new ("SELECT DISTINCT nie:url(?urn) fts:rank(?urn) nfo:fileLastModified(?urn)
nfo:fileLastAccessed(?urn) fts:snippet(?urn)\n"
"WHERE {"
" ?urn a nfo:FileDataObject;"
" nfo:fileLastModified ?mtime;"
" nfo:fileLastAccessed ?atime;"
" tracker:available true;"
" nie:url ?url");
-
if (*search_text)
{
g_string_append_printf (sparql, "; fts:match '\"%s\"*'", search_text);
@@ -348,10 +357,13 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
}
else
{
- g_string_append_printf (sparql, "tracker:uri-is-descendant('%s', ?url) && ", location_uri);
+ g_string_append_printf (sparql, "tracker:uri-is-descendant('%s', ?url)", location_uri);
}
- g_string_append_printf (sparql, "fn:contains(fn:lower-case(nfo:fileName(?urn)), '%s')", search_text);
+ if (!tracker->details->fts_enabled)
+ {
+ g_string_append_printf (sparql, " && fn:contains(fn:lower-case(nfo:fileName(?urn)), '%s')",
search_text);
+ }
date_range = nautilus_query_get_date_range (tracker->details->query);
if (date_range)
diff --git a/src/nautilus-search-hit.c b/src/nautilus-search-hit.c
index 6ae9ae9..fac70e5 100644
--- a/src/nautilus-search-hit.c
+++ b/src/nautilus-search-hit.c
@@ -36,6 +36,7 @@ struct _NautilusSearchHit
GDateTime *modification_time;
GDateTime *access_time;
gdouble fts_rank;
+ gchar *fts_snippet;
gdouble relevance;
};
@@ -47,6 +48,7 @@ enum
PROP_MODIFICATION_TIME,
PROP_ACCESS_TIME,
PROP_FTS_RANK,
+ PROP_FTS_SNIPPET,
NUM_PROPERTIES
};
@@ -158,6 +160,12 @@ nautilus_search_hit_get_relevance (NautilusSearchHit *hit)
return hit->relevance;
}
+gchar *
+nautilus_search_hit_get_fts_snippet (NautilusSearchHit *hit)
+{
+ return hit->fts_snippet;
+}
+
static void
nautilus_search_hit_set_uri (NautilusSearchHit *hit,
const char *uri)
@@ -209,6 +217,18 @@ nautilus_search_hit_set_access_time (NautilusSearchHit *hit,
}
}
+void
+nautilus_search_hit_set_fts_snippet (NautilusSearchHit *hit,
+ const gchar *snippet)
+{
+ if (hit->fts_snippet)
+ {
+ g_free (hit->fts_snippet);
+ }
+
+ hit->fts_snippet = g_strdup (snippet);
+}
+
static void
nautilus_search_hit_set_property (GObject *object,
guint arg_id,
@@ -301,6 +321,11 @@ nautilus_search_hit_get_property (GObject *object,
}
break;
+ case PROP_FTS_SNIPPET:
+ {
+ g_value_set_string (value, hit->fts_snippet);
+ }
+
default:
{
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, arg_id, pspec);
@@ -325,6 +350,9 @@ nautilus_search_hit_finalize (GObject *object)
g_date_time_unref (hit->modification_time);
}
+ if (hit->fts_snippet)
+ g_free (hit->fts_snippet);
+
G_OBJECT_CLASS (nautilus_search_hit_parent_class)->finalize (object);
}
diff --git a/src/nautilus-search-hit.h b/src/nautilus-search-hit.h
index 100c7da..0b82af7 100644
--- a/src/nautilus-search-hit.h
+++ b/src/nautilus-search-hit.h
@@ -37,12 +37,14 @@ void nautilus_search_hit_set_modification_time (NautilusSearchHit
GDateTime *date);
void nautilus_search_hit_set_access_time (NautilusSearchHit *hit,
GDateTime *date);
-
+void nautilus_search_hit_set_fts_snippet (NautilusSearchHit *hit,
+ const gchar *snippet);
void nautilus_search_hit_compute_scores (NautilusSearchHit *hit,
NautilusQuery *query);
const char * nautilus_search_hit_get_uri (NautilusSearchHit *hit);
gdouble nautilus_search_hit_get_relevance (NautilusSearchHit *hit);
+gchar * nautilus_search_hit_get_fts_snippet (NautilusSearchHit *hit);
G_END_DECLS
diff --git a/src/nautilus-search-popover.c b/src/nautilus-search-popover.c
index db95a2b..2fc5d30 100644
--- a/src/nautilus-search-popover.c
+++ b/src/nautilus-search-popover.c
@@ -45,8 +45,12 @@ struct _NautilusSearchPopover
GtkWidget *type_stack;
GtkWidget *last_used_button;
GtkWidget *last_modified_button;
+ GtkWidget *full_text_search_button;
+ GtkWidget *filename_search_button;
NautilusQuery *query;
+
+ gboolean fts_enabled;
};
static void show_date_selection_widgets (NautilusSearchPopover *popover,
@@ -71,6 +75,7 @@ enum
MIME_TYPE,
TIME_TYPE,
DATE_RANGE,
+ FTS_CHANGE,
LAST_SIGNAL
};
@@ -346,6 +351,24 @@ search_time_type_changed (GtkToggleButton *button,
g_signal_emit_by_name (popover, "time-type", type, NULL);
}
+static void
+search_fts_mode_changed (GtkToggleButton *button,
+ NautilusSearchPopover *popover)
+{
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (popover->full_text_search_button)) &&
+ popover->fts_enabled == FALSE)
+ {
+ popover->fts_enabled = TRUE;
+ g_signal_emit_by_name(popover, "fts-change", popover->fts_enabled);
+ }
+ else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (popover->filename_search_button)) &&
+ popover->fts_enabled == TRUE)
+ {
+ popover->fts_enabled = FALSE;
+ g_signal_emit_by_name(popover, "fts-change", popover->fts_enabled);
+ }
+}
+
/* Auxiliary methods */
static GtkWidget *
@@ -765,6 +788,17 @@ nautilus_search_popover_class_init (NautilusSearchPopoverClass *klass)
1,
G_TYPE_INT);
+ signals[FTS_CHANGE] = g_signal_new ("fts-change",
+ NAUTILUS_TYPE_SEARCH_POPOVER,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_BOOLEAN);
+
/**
* NautilusSearchPopover::query:
*
@@ -794,6 +828,8 @@ nautilus_search_popover_class_init (NautilusSearchPopoverClass *klass)
gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, type_stack);
gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, last_used_button);
gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, last_modified_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, full_text_search_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, filename_search_button);
gtk_widget_class_bind_template_callback (widget_class, calendar_day_selected);
gtk_widget_class_bind_template_callback (widget_class, clear_date_button_clicked);
@@ -804,6 +840,7 @@ nautilus_search_popover_class_init (NautilusSearchPopoverClass *klass)
gtk_widget_class_bind_template_callback (widget_class, toggle_calendar_icon_clicked);
gtk_widget_class_bind_template_callback (widget_class, types_listbox_row_activated);
gtk_widget_class_bind_template_callback (widget_class, search_time_type_changed);
+ gtk_widget_class_bind_template_callback (widget_class, search_fts_mode_changed);
}
static void
@@ -840,6 +877,9 @@ nautilus_search_popover_init (NautilusSearchPopover *self)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_modified_button), FALSE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_used_button), TRUE);
}
+
+
+ self->fts_enabled = FALSE;
}
GtkWidget *
@@ -937,3 +977,9 @@ nautilus_search_popover_reset_date_range (NautilusSearchPopover *popover)
show_date_selection_widgets (popover, FALSE);
g_signal_emit_by_name (popover, "date-range", NULL);
}
+
+gboolean
+nautilus_search_popover_get_fts_enabled (NautilusSearchPopover *popover)
+{
+ return popover->fts_enabled;
+}
diff --git a/src/nautilus-search-popover.h b/src/nautilus-search-popover.h
index 1d872f1..9631ad2 100644
--- a/src/nautilus-search-popover.h
+++ b/src/nautilus-search-popover.h
@@ -46,6 +46,8 @@ void nautilus_search_popover_set_query (NautilusSearch
void nautilus_search_popover_reset_date_range (NautilusSearchPopover *popover);
void nautilus_search_popover_reset_mime_types (NautilusSearchPopover *popover);
+gboolean nautilus_search_popover_get_fts_enabled (NautilusSearchPopover *popover);
+
G_END_DECLS
#endif /* NAUTILUS_SEARCH_POPOVER_H */
diff --git a/src/resources/ui/nautilus-search-popover.ui b/src/resources/ui/nautilus-search-popover.ui
index 72fd99d..82a948a 100644
--- a/src/resources/ui/nautilus-search-popover.ui
+++ b/src/resources/ui/nautilus-search-popover.ui
@@ -354,6 +354,7 @@
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="hexpand">True</property>
+ <property name="visible">True</property>
<child>
<object class="GtkRadioButton" id="full_text_search_button">
<property name="label" translatable="yes">Full Text</property>
@@ -365,6 +366,7 @@
<property name="xalign">0</property>
<property name="active">True</property>
<property name="draw_indicator">False</property>
+ <signal name="toggled" handler="search_fts_mode_changed" object="NautilusSearchPopover"
swapped="no" />
</object>
<packing>
<property name="expand">False</property>
@@ -383,6 +385,8 @@
<property name="xalign">0</property>
<property name="draw_indicator">False</property>
<property name="group">full_text_search_button</property>
+ <property name="active">True</property>
+ <signal name="toggled" handler="search_fts_mode_changed" object="NautilusSearchPopover"
swapped="no" />
</object>
<packing>
<property name="expand">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]