[Tracker] [PATCH 2/2] tracker-search-tool: allow restrict search to a path
- From: "Juan A. Suarez Romero" <jasuarez igalia com>
- To: tracker-list gnome org
- Subject: [Tracker] [PATCH 2/2] tracker-search-tool: allow restrict search to a path
- Date: Mon, 2 Nov 2009 16:02:21 +0100
When entering search words, if "path:<the path>" is enter, then search is
restricted to <the path>.
As example, entering "offspring path:/home/user/Videos" will search "offspring"
in container "/home/user/Videos".
Some of current restrictions:
- Only one path is used
- Path must be absolute
- There is no recursive searching.
---
src/tracker-search-tool/tracker-entry.gs | 3 +--
src/tracker-search-tool/tracker-query.gs | 20 ++++++++++++++++++--
src/tracker-search-tool/tracker-utils.gs | 28 ++++++++++++++++++++++------
3 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/src/tracker-search-tool/tracker-entry.gs b/src/tracker-search-tool/tracker-entry.gs
index 5f02004..39bf8e5 100644
--- a/src/tracker-search-tool/tracker-entry.gs
+++ b/src/tracker-search-tool/tracker-entry.gs
@@ -22,7 +22,6 @@
uses
Gtk
- TrackerUtils
const static RUN_DELAY : int = 500
@@ -64,6 +63,6 @@ class TrackerSearchEntry : Gtk.Entry
Query.SearchTerms = ""
else
set_icon_sensitive (EntryIconPosition.SECONDARY, true)
- Query.SearchTerms = EscapeSparql (text, true)
+ Query.SearchTerms = text
return false
diff --git a/src/tracker-search-tool/tracker-query.gs b/src/tracker-search-tool/tracker-query.gs
index e504da2..89bfc4e 100644
--- a/src/tracker-search-tool/tracker-query.gs
+++ b/src/tracker-search-tool/tracker-query.gs
@@ -20,6 +20,10 @@
*/
+uses
+ TrackerUtils
+
+
[DBus (name = "org.freedesktop.Tracker1.Resources")]
interface Resources : GLib.Object
def abstract SparqlQuery (query : string) : array of string[,] raises DBus.Error
@@ -75,13 +79,25 @@ class TrackerQuery : Object
def Search () : array of string[,]
cat, query : string
+ terms_to_search : string
+ restrict_path : string
+ uri : string
+ escaped_terms : string
if Category is null or Category is "All"
cat = "nfo:FileDataObject"
else
cat = Category
-
- query = "SELECT ?s WHERE { ?s fts:match \"%s\". ?s a %s } limit 100 ".printf (SearchTerms, cat)
+
+ escaped_terms = EscapeSparql (SearchTerms, false)
+ terms_to_search = GetSearchWords (escaped_terms)
+ restrict_path = GetPath (escaped_terms)
+
+ if restrict_path is null
+ query = "SELECT ?s WHERE { ?s fts:match \"%s*\". ?s a %s } limit 100 ".printf (terms_to_search,
cat)
+ else
+ uri = Filename.to_uri (restrict_path)
+ query = "SELECT ?s WHERE { ?s fts:match \"%s*\". ?s a %s. ?s nfo:belongsToContainer <%s> } limit
100 ".printf (terms_to_search, cat, uri)
// to do : add Fields, Category and SortField
try
diff --git a/src/tracker-search-tool/tracker-utils.gs b/src/tracker-search-tool/tracker-utils.gs
index 33835db..ea48c56 100644
--- a/src/tracker-search-tool/tracker-utils.gs
+++ b/src/tracker-search-tool/tracker-utils.gs
@@ -57,11 +57,6 @@ class TrackerUtils
if sparql is null
return ""
- var len = sparql.length
-
- if len < 3
- return sparql
-
p : char* = sparql
while *p is not '\0'
@@ -80,9 +75,30 @@ class TrackerUtils
return str.str
-
+ def static GetPath (raw_search : string) : string
+ path : string = null
+
+ var search_split = raw_search.split (" ")
+
+ for word in search_split
+ if word.has_prefix ("path:") && word.length > 5
+ path = word.substring (5)
+ break
+
+ return path
+
+ def static GetSearchWords (raw_search : string) : string
+ buffer : StringBuilder = new StringBuilder ("")
+
+ var search_split = raw_search.split (" ")
+
+ for word in search_split
+ if word.has_prefix ("path:") is false or word.length <= 5
+ buffer.append_printf (" %s", word)
+
+ return buffer.str
def static OpenUri (uri : string, is_dir :bool) : bool
command : string
--
1.6.0.4
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]