Commit c7d86ef4 authored by Matthias Clasen's avatar Matthias Clasen

GtkSearchEngine: Avoid crawling indexed locations

Add a framework to the simple engine that allows to skip
locations which are indexed by the native engine.
parent 33e2d12e
...@@ -54,6 +54,9 @@ struct _GtkSearchEngineSimplePrivate ...@@ -54,6 +54,9 @@ struct _GtkSearchEngineSimplePrivate
SearchThreadData *active_search; SearchThreadData *active_search;
gboolean query_finished; gboolean query_finished;
GtkSearchEngineSimpleIsIndexed is_indexed_callback;
gpointer is_indexed_data;
}; };
...@@ -179,6 +182,25 @@ send_batch (SearchThreadData *data) ...@@ -179,6 +182,25 @@ send_batch (SearchThreadData *data)
data->hits = NULL; 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 static void
visit_directory (GFile *dir, SearchThreadData *data) visit_directory (GFile *dir, SearchThreadData *data)
{ {
...@@ -227,7 +249,9 @@ visit_directory (GFile *dir, SearchThreadData *data) ...@@ -227,7 +249,9 @@ visit_directory (GFile *dir, SearchThreadData *data)
if (data->n_processed_files > BATCH_SIZE) if (data->n_processed_files > BATCH_SIZE)
send_batch (data); 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)); g_queue_push_tail (data->directories, g_object_ref (child));
} }
...@@ -337,3 +361,12 @@ _gtk_search_engine_simple_new (void) ...@@ -337,3 +361,12 @@ _gtk_search_engine_simple_new (void)
{ {
return g_object_new (GTK_TYPE_SEARCH_ENGINE_SIMPLE, NULL); 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;
}
...@@ -53,6 +53,12 @@ GType _gtk_search_engine_simple_get_type (void); ...@@ -53,6 +53,12 @@ GType _gtk_search_engine_simple_get_type (void);
GtkSearchEngine* _gtk_search_engine_simple_new (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 G_END_DECLS
#endif /* __GTK_SEARCH_ENGINE_SIMPLE_H__ */ #endif /* __GTK_SEARCH_ENGINE_SIMPLE_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment