forked from AuroraMiddleware/gtk
GtkSearchEngine: Add recursive flag
Add a flag for recursive search, and implement non-recursive search in both the tracker and simple search engines. This is not currently used in the file chooser.
This commit is contained in:
parent
15a41e0bf5
commit
a3a58fa7d9
@ -41,6 +41,7 @@ struct _GtkSearchEnginePrivate {
|
||||
gchar *simple_error;
|
||||
|
||||
gboolean running;
|
||||
gboolean recursive;
|
||||
GHashTable *hits;
|
||||
};
|
||||
|
||||
@ -400,3 +401,28 @@ _gtk_search_engine_error (GtkSearchEngine *engine,
|
||||
|
||||
g_signal_emit (engine, signals[ERROR], 0, error_message);
|
||||
}
|
||||
|
||||
void
|
||||
_gtk_search_engine_set_recursive (GtkSearchEngine *engine,
|
||||
gboolean recursive)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
|
||||
|
||||
g_assert (!engine->priv->running);
|
||||
|
||||
engine->priv->recursive = recursive;
|
||||
|
||||
if (engine->priv->native)
|
||||
_gtk_search_engine_set_recursive (engine->priv->native, recursive);
|
||||
|
||||
if (engine->priv->simple)
|
||||
_gtk_search_engine_set_recursive (engine->priv->simple, recursive);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_gtk_search_engine_get_recursive (GtkSearchEngine *engine)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_SEARCH_ENGINE (engine), TRUE);
|
||||
|
||||
return engine->priv->recursive;
|
||||
}
|
||||
|
@ -84,6 +84,9 @@ void _gtk_search_engine_hits_added (GtkSearchEngine *engine,
|
||||
void _gtk_search_engine_finished (GtkSearchEngine *engine);
|
||||
void _gtk_search_engine_error (GtkSearchEngine *engine,
|
||||
const gchar *error_message);
|
||||
void _gtk_search_engine_set_recursive (GtkSearchEngine *engine,
|
||||
gboolean recursive);
|
||||
gboolean _gtk_search_engine_get_recursive (GtkSearchEngine *engine);
|
||||
|
||||
void _gtk_search_hit_free (GtkSearchHit *hit);
|
||||
GtkSearchHit *_gtk_search_hit_dup (GtkSearchHit *hit);
|
||||
|
@ -43,6 +43,7 @@ typedef struct
|
||||
GList *hits;
|
||||
|
||||
GtkQuery *query;
|
||||
gboolean recursive;
|
||||
} SearchThreadData;
|
||||
|
||||
|
||||
@ -95,6 +96,7 @@ search_thread_data_new (GtkSearchEngineSimple *engine,
|
||||
data->engine = g_object_ref (engine);
|
||||
data->directories = g_queue_new ();
|
||||
data->query = g_object_ref (query);
|
||||
data->recursive = _gtk_search_engine_get_recursive (GTK_SEARCH_ENGINE (engine));
|
||||
uri = gtk_query_get_location (query);
|
||||
if (uri != NULL)
|
||||
location = g_file_new_for_uri (uri);
|
||||
@ -225,7 +227,7 @@ visit_directory (GFile *dir, SearchThreadData *data)
|
||||
if (data->n_processed_files > BATCH_SIZE)
|
||||
send_batch (data);
|
||||
|
||||
if (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)
|
||||
g_queue_push_tail (data->directories, g_object_ref (child));
|
||||
}
|
||||
|
||||
|
@ -327,6 +327,7 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
|
||||
gchar *search_text;
|
||||
gchar *location_uri;
|
||||
GString *sparql;
|
||||
gboolean recursive;
|
||||
|
||||
tracker = GTK_SEARCH_ENGINE_TRACKER (engine);
|
||||
|
||||
@ -344,6 +345,7 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
|
||||
|
||||
search_text = gtk_query_get_text (tracker->priv->query);
|
||||
location_uri = gtk_query_get_location (tracker->priv->query);
|
||||
recursive = _gtk_search_engine_get_recursive (engine);
|
||||
|
||||
sparql = g_string_new ("SELECT nie:url(?urn) "
|
||||
"WHERE {"
|
||||
@ -356,16 +358,24 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
|
||||
sparql_append_string_literal (sparql, search_text, TRUE);
|
||||
#endif
|
||||
|
||||
g_string_append (sparql, ". FILTER (fn:contains(fn:lower-case(nfo:fileName(?urn)),");
|
||||
g_string_append (sparql, ". FILTER (");
|
||||
|
||||
g_string_append (sparql, "fn:contains(fn:lower-case(nfo:fileName(?urn)),");
|
||||
sparql_append_string_literal_lower_case (sparql, search_text);
|
||||
g_string_append (sparql, ")");
|
||||
|
||||
if (location_uri)
|
||||
{
|
||||
g_string_append (sparql, ") && fn:starts-with(nie:url(?urn),");
|
||||
g_string_append (sparql, " && ");
|
||||
if (recursive)
|
||||
g_string_append (sparql, "tracker-uri-is-descendant(");
|
||||
else
|
||||
g_string_append (sparql, "tracker-uri-is-parent(");
|
||||
sparql_append_string_literal (sparql, location_uri, FALSE);
|
||||
g_string_append (sparql, ",nie:url(?urn))");
|
||||
}
|
||||
|
||||
g_string_append (sparql, "))");
|
||||
g_string_append (sparql, ")");
|
||||
|
||||
#ifdef FTS_MATCHING
|
||||
g_string_append (sparql, " } ORDER BY DESC(fts:rank(?urn)) DESC(nie:url(?urn))");
|
||||
|
Loading…
Reference in New Issue
Block a user