[gtk+] GtkSearchEngine: Avoid crawling indexed locations



commit c7d86ef4e404e4a0e9ee9c48fa0d5e15c3f6fb6e
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jun 19 00:11:01 2015 -0400

    GtkSearchEngine: Avoid crawling indexed locations
    
    Add a framework to the simple engine that allows to skip
    locations which are indexed by the native engine.

 gtk/gtksearchenginesimple.c |   35 ++++++++++++++++++++++++++++++++++-
 gtk/gtksearchenginesimple.h |    6 ++++++
 2 files changed, 40 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtksearchenginesimple.c b/gtk/gtksearchenginesimple.c
index 769dd04..b405aef 100644
--- a/gtk/gtksearchenginesimple.c
+++ b/gtk/gtksearchenginesimple.c
@@ -54,6 +54,9 @@ struct _GtkSearchEngineSimplePrivate
   SearchThreadData *active_search;
 
   gboolean query_finished;
+
+  GtkSearchEngineSimpleIsIndexed is_indexed_callback;
+  gpointer                       is_indexed_data;
 };
 
 
@@ -179,6 +182,25 @@ send_batch (SearchThreadData *data)
   data->hits = NULL;
 }
 
+static gboolean
+is_indexed (GtkSearchEngineSimple *engine,
+            GFile                 *location)
+{
+  if (engine->priv->is_indexed_callback)
+    {
+      if (engine->priv->is_indexed_callback (location, engine->priv->is_indexed_data))
+        {
+          gchar *uri = g_file_get_uri (location);
+          g_debug ("Simple search engine: Skipping indexed location: %s\n", uri);
+          g_free (uri);
+
+          return TRUE;
+        }
+    }
+
+  return FALSE;
+}
+
 static void
 visit_directory (GFile *dir, SearchThreadData *data)
 {
@@ -227,7 +249,9 @@ visit_directory (GFile *dir, SearchThreadData *data)
       if (data->n_processed_files > BATCH_SIZE)
         send_batch (data);
 
-      if (data->recursive && g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+      if (data->recursive &&
+          g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY &&
+          !is_indexed (data->engine, child))
         g_queue_push_tail (data->directories, g_object_ref (child));
     }
 
@@ -337,3 +361,12 @@ _gtk_search_engine_simple_new (void)
 {
   return g_object_new (GTK_TYPE_SEARCH_ENGINE_SIMPLE, NULL);
 }
+
+void
+_gtk_search_engine_simple_set_indexed_cb (GtkSearchEngineSimple          *engine,
+                                          GtkSearchEngineSimpleIsIndexed  callback,
+                                          gpointer                        data)
+{
+  engine->priv->is_indexed_callback = callback;
+  engine->priv->is_indexed_data = data;
+}
diff --git a/gtk/gtksearchenginesimple.h b/gtk/gtksearchenginesimple.h
index b03366f..83a60b1 100644
--- a/gtk/gtksearchenginesimple.h
+++ b/gtk/gtksearchenginesimple.h
@@ -53,6 +53,12 @@ GType            _gtk_search_engine_simple_get_type (void);
 
 GtkSearchEngine* _gtk_search_engine_simple_new      (void);
 
+typedef gboolean (*GtkSearchEngineSimpleIsIndexed) (GFile *location, gpointer data);
+
+void             _gtk_search_engine_simple_set_indexed_cb (GtkSearchEngineSimple *engine,
+                                                           GtkSearchEngineSimpleIsIndexed callback,
+                                                           gpointer                       data);
+
 G_END_DECLS
 
 #endif /* __GTK_SEARCH_ENGINE_SIMPLE_H__ */


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