summaryrefslogtreecommitdiff
path: root/gtk/gtksearchenginetracker.c
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2015-02-28 22:59:36 +0100
committerMatthias Clasen <mclasen@redhat.com>2015-02-28 21:19:47 -0500
commitfc838cefbf3bbcb50497ca3a6fc37fd2d71cb6e6 (patch)
tree06faf91b97f58c5b5b6a12fb7386bfa69a077bb8 /gtk/gtksearchenginetracker.c
parentd87041bfe38368982b6b72f6812972b6a1d29a21 (diff)
downloadgtk+-fc838cefbf3bbcb50497ca3a6fc37fd2d71cb6e6.tar.gz
searchenginetracker: Unify fts/non-fts query
This makes sure we use location_uri for both types of query, and the fts query has been made more similar to the one used by nautilus.
Diffstat (limited to 'gtk/gtksearchenginetracker.c')
-rw-r--r--gtk/gtksearchenginetracker.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/gtk/gtksearchenginetracker.c b/gtk/gtksearchenginetracker.c
index f5a428cfb2..9102eb538b 100644
--- a/gtk/gtksearchenginetracker.c
+++ b/gtk/gtksearchenginetracker.c
@@ -245,7 +245,8 @@ sparql_escape_string (const gchar *literal)
static void
sparql_append_string_literal (GString *sparql,
- const gchar *str)
+ const gchar *str,
+ gboolean glob)
{
gchar *s;
@@ -253,6 +254,9 @@ sparql_append_string_literal (GString *sparql,
g_string_append_c (sparql, '"');
g_string_append (sparql, s);
+
+ if (glob)
+ g_string_append_c (sparql, '*');
g_string_append_c (sparql, '"');
g_free (s);
@@ -265,7 +269,7 @@ sparql_append_string_literal_lower_case (GString *sparql,
gchar *s;
s = g_utf8_strdown (str, -1);
- sparql_append_string_literal (sparql, s);
+ sparql_append_string_literal (sparql, s, FALSE);
g_free (s);
}
@@ -337,9 +341,7 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
{
GtkSearchEngineTracker *tracker;
gchar *search_text;
-#ifdef FTS_MATCHING
gchar *location_uri;
-#endif
GString *sparql;
tracker = GTK_SEARCH_ENGINE_TRACKER (engine);
@@ -357,37 +359,34 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
}
search_text = _gtk_query_get_text (tracker->priv->query);
-
-#ifdef FTS_MATCHING
location_uri = _gtk_query_get_location (tracker->priv->query);
- /* Using FTS: */
+
sparql = g_string_new ("SELECT nie:url(?urn) "
"WHERE {"
" ?urn a nfo:FileDataObject ;"
- " tracker:available true ; "
- " fts:match ");
- sparql_append_string_literal (sparql, search_text);
+ " tracker:available true ; ");
+
+#ifdef FTS_MATCHING
+ /* Using FTS: */
+ g_string_append (sparql, "fts:match ");
+ sparql_append_string_literal (sparql, search_text, TRUE);
+#endif
+
+ g_string_append (sparql, ". FILTER (fn:contains(fn:lower-case(nfo:fileName(?urn)),");
+ sparql_append_string_literal_lower_case (sparql, search_text);
if (location_uri)
{
- g_string_append (sparql, " . FILTER (fn:starts-with(nie:url(?urn),");
- sparql_append_string_literal (sparql, location_uri);
- g_string_append (sparql, "))");
+ g_string_append (sparql, ") && fn:starts-with(nie:url(?urn),");
+ sparql_append_string_literal (sparql, location_uri, FALSE);
}
- g_string_append (sparql, " } ORDER BY DESC(fts:rank(?urn)) ASC(nie:url(?urn))");
-#else /* FTS_MATCHING */
- /* Using filename matching: */
- sparql = g_string_new ("SELECT nie:url(?urn) "
- "WHERE {"
- " ?urn a nfo:FileDataObject ;"
- " tracker:available true ."
- " FILTER (fn:contains(fn:lower-case(nfo:fileName(?urn)),");
- sparql_append_string_literal_lower_case (sparql, search_text);
+ g_string_append (sparql, "))");
- g_string_append (sparql,
- "))"
- "} ORDER BY DESC(nie:url(?urn)) DESC(nfo:fileName(?urn))");
+#ifdef FTS_MATCHING
+ g_string_append (sparql, " } ORDER BY DESC(fts:rank(?urn)) DESC(nie:url(?urn))");
+#else /* FTS_MATCHING */
+ g_string_append (sparql, "} ORDER BY DESC(nie:url(?urn)) DESC(nfo:fileName(?urn))");
#endif /* FTS_MATCHING */
tracker->priv->query_pending = TRUE;