[beagle] Fix uri escaping once again. QueryPart_Uri now stores the uri in escaped form. To remove ambiguity,



commit 64097cd827e68c8db0353db652e3ca8cf2108e15
Author: D Bera <dbera web gmail com>
Date:   Thu Jun 18 21:30:19 2009 -0400

    Fix uri escaping once again. QueryPart_Uri now stores the uri in escaped form. To remove ambiguity, add an option --raw-uri to beagle-query which prints the raw uri; this raw uri can then be used in further uri queries. Fix uri queries for child-indexables.

 beagle/BeagleClient/QueryPart.cs                   |    1 +
 beagle/Util/UriFu.cs                               |   20 ++++++++++++++------
 beagle/beagled/DumpIndex.cs                        |    7 +++----
 .../FileSystemQueryable/FileSystemQueryable.cs     |    2 ++
 beagle/beagled/LuceneCommon.cs                     |    2 +-
 beagle/beagled/LuceneQueryingDriver.cs             |    8 ++++----
 beagle/beagled/QueryStringParser.cs                |    3 ++-
 beagle/tools/Query.cs                              |   11 +++++++++--
 beagle/tools/beagle-query.1                        |    6 +++++-
 9 files changed, 41 insertions(+), 19 deletions(-)
---
diff --git a/beagle/BeagleClient/QueryPart.cs b/beagle/BeagleClient/QueryPart.cs
index 6dae575..8a605c1 100644
--- a/beagle/BeagleClient/QueryPart.cs
+++ b/beagle/BeagleClient/QueryPart.cs
@@ -273,6 +273,7 @@ namespace Beagle {
 	/* Get all indexed data about some uri. */
 	public class QueryPart_Uri : QueryPart {
 
+		// The Uri should be always escaped
 		private Uri uri;
 
 		public QueryPart_Uri ()
diff --git a/beagle/Util/UriFu.cs b/beagle/Util/UriFu.cs
index b7c95e3..e41336a 100644
--- a/beagle/Util/UriFu.cs
+++ b/beagle/Util/UriFu.cs
@@ -125,12 +125,8 @@ namespace Beagle.Util {
 		// Basically hex-escape the path, query and the fragment
 		static public Uri UserUritoEscapedUri (string user_uri)
 		{
-			Uri uri;
-			try {
-				uri = new Uri (user_uri);
-			} catch {
-				return null;
-			}
+			// We hex escape explicitly later
+			Uri uri = new Uri (user_uri, true); // This is deprecated in .Net-2.0 - need new strategy to create custom Uris
 
 			UriBuilder new_uri = new UriBuilder ();
 			new_uri.Scheme = uri.Scheme;
@@ -157,6 +153,18 @@ namespace Beagle.Util {
 			return new_uri.Uri;
 		}
 
+		static public string EscapedUriToString (Uri uri)
+		{
+		    if (! uri.UserEscaped)
+			    return uri.AbsoluteUri;
+
+		    UriBuilder new_uri = new UriBuilder (uri);
+		    new_uri.Path = StringFu.HexUnescape (uri.AbsolutePath);
+		    if (! String.IsNullOrEmpty(new_uri.Fragment))
+			    new_uri.Fragment = StringFu.HexUnescape (uri.Fragment.Substring (1)); // remove leading '#'
+		    return new_uri.Uri.ToString();
+		}
+
 		//////////////////////////////////
 
 		// Uri.ToString() should not be used. Use Uri.AbsoluteUri
diff --git a/beagle/beagled/DumpIndex.cs b/beagle/beagled/DumpIndex.cs
index 1206630..e8a6079 100644
--- a/beagle/beagled/DumpIndex.cs
+++ b/beagle/beagled/DumpIndex.cs
@@ -393,14 +393,13 @@ Usage: beagle-dump-index [options] [[file or URI to match] ...]
 					index_names.Add (arg.Remove (0, 8));
 				else {
 					Uri uri;
-					
+
 					try {
-						uri = UriFu.UserUritoEscapedUri (arg);
+						uris.Add (new Uri(arg, true));
 					} catch (UriFormatException) {
-						uri = UriFu.PathToFileUri (arg);
+						uris.Add(UriFu.PathToFileUri (arg));
 					}
 
-					uris.Add (uri);
 				}
 				break;
 			}
diff --git a/beagle/beagled/FileSystemQueryable/FileSystemQueryable.cs b/beagle/beagled/FileSystemQueryable/FileSystemQueryable.cs
index 81adb0f..e50bc51 100644
--- a/beagle/beagled/FileSystemQueryable/FileSystemQueryable.cs
+++ b/beagle/beagled/FileSystemQueryable/FileSystemQueryable.cs
@@ -2020,6 +2020,8 @@ namespace Beagle.Daemon.FileSystemQueryable {
 				return null;
 
 			Uri internal_uri = GuidFu.ToUri (attr.UniqueId);
+			if (! String.IsNullOrEmpty (external_uri.Fragment))
+			    internal_uri = UriFu.AddFragment (internal_uri, external_uri.Fragment, true);
 
 			return internal_uri;
 		}
diff --git a/beagle/beagled/LuceneCommon.cs b/beagle/beagled/LuceneCommon.cs
index a8a9b4e..3422105 100644
--- a/beagle/beagled/LuceneCommon.cs
+++ b/beagle/beagled/LuceneCommon.cs
@@ -1765,7 +1765,7 @@ namespace Beagle.Daemon {
 				// but this is required for the query API where the uri query
 				// can be part of a prohibited query or a boolean or query.
 				Term term;
-				term = new Term ("Uri", UriFu.UriToEscapedString (part.Uri));
+				term = new Term ("Uri", part.Uri.OriginalString);
 				if (term_list != null)
 					term_list.Add (term);
 				primary_query = new LNS.TermQuery (term);
diff --git a/beagle/beagled/LuceneQueryingDriver.cs b/beagle/beagled/LuceneQueryingDriver.cs
index 46a5c18..fc67f4a 100644
--- a/beagle/beagled/LuceneQueryingDriver.cs
+++ b/beagle/beagled/LuceneQueryingDriver.cs
@@ -392,7 +392,7 @@ namespace Beagle.Daemon {
 			// Return if the URI exists
 			if (subject != String.Empty && predicate == String.Empty && _object == String.Empty) {
 				QueryPart_Uri part = new QueryPart_Uri ();
-				part.Uri = UriFu.UserUritoEscapedUri (subject); // better be URI!
+				part.Uri = new Uri (subject, true); // better be URI!
 				query.AddPart (part);
 				// FIXME: Which properties to return in the hit? All or none ?
 				return DoLowLevelRDFQuery (query, pred_type, predicate, null, text_cache);
@@ -401,7 +401,7 @@ namespace Beagle.Daemon {
 			// Normal query in the document with this URI
 			if (subject != String.Empty && predicate == String.Empty && _object != String.Empty) {
 				QueryPart_Uri uri_part = new QueryPart_Uri ();
-				uri_part.Uri = UriFu.UserUritoEscapedUri (subject); // better be URI!
+				uri_part.Uri = new Uri (subject, true); // better be URI!
 				query.AddPart (uri_part);
 
 				QueryPart_Text part = new QueryPart_Text ();
@@ -417,7 +417,7 @@ namespace Beagle.Daemon {
 				ArrayList returned_uris = new ArrayList (1);
 
 				ArrayList uri_list = new ArrayList (1);
-				uri_list.Add (UriFu.UserUritoEscapedUri (subject));
+				uri_list.Add (new Uri (subject, true));
 
 				string field_name = PropertyToFieldName (pred_type, predicate);
 				FieldSelector fields = new MapFieldSelector (new string[] { "Uri", "Timestamp", field_name });
@@ -434,7 +434,7 @@ namespace Beagle.Daemon {
 			// Property query in the document with this URI
 			if (subject != String.Empty && predicate != String.Empty && _object != String.Empty) {
 				QueryPart_Uri uri_part = new QueryPart_Uri ();
-				uri_part.Uri = UriFu.UserUritoEscapedUri (subject); // better be URI!
+				uri_part.Uri = new Uri (subject, true); // better be URI!
 				query.AddPart (uri_part);
 
 				QueryPart_Property part = new QueryPart_Property ();
diff --git a/beagle/beagled/QueryStringParser.cs b/beagle/beagled/QueryStringParser.cs
index 4051371..df3557c 100644
--- a/beagle/beagled/QueryStringParser.cs
+++ b/beagle/beagled/QueryStringParser.cs
@@ -213,7 +213,8 @@ namespace Beagle.Daemon {
 				try {
 					QueryPart_Uri part = new QueryPart_Uri ();
 					part.Logic = (IsProhibited ? QueryPartLogic.Prohibited : QueryPartLogic.Required);
-					part.Uri = UriFu.UserUritoEscapedUri (text);
+					// uri: queries require the raw Uri as present in the index
+					part.Uri = new Uri (text, true);
 					return part;
 				} catch (System.UriFormatException) {
 					Log.Warn ("Could not parse [{0}] as uri query. Assuming text.", text);
diff --git a/beagle/tools/Query.cs b/beagle/tools/Query.cs
index faeeccc..1d4d326 100644
--- a/beagle/tools/Query.cs
+++ b/beagle/tools/Query.cs
@@ -59,6 +59,7 @@ public class QueryTool {
 	private static bool flood = false;
 	private static bool listener = false;
 	private static bool display_cached_text = false;
+	private static bool raw_uri = false;
 
 	private static void OnHitsAdded (HitsAddedResponse response)
 	{
@@ -82,10 +83,11 @@ public class QueryTool {
 		}
 
 		foreach (Hit hit in response.Hits) {
+			string uri = (raw_uri ?  hit.Uri.OriginalString : UriFu.EscapedUriToString (hit.Uri));
 			if (verbose)
-				Console.WriteLine ("  Uri: {0}", hit.Uri);
+				Console.WriteLine ("  Uri: {0}", uri);
 			else
-				Console.WriteLine (hit.Uri);
+				Console.WriteLine (uri);
 
 			if (verbose) {
 				SnippetRequest sreq = new SnippetRequest (query, hit);
@@ -180,6 +182,8 @@ public class QueryTool {
 			"              \t\tthe actual results.\n" +
 			"  --max-hits\t\tLimit number of search results per backend\n" +
 			"            \t\t(default 100)\n" +
+			"  --raw-uri\t\tDisplay the actual (unescaped) uri used internally.\n" +
+			"           \t\tOnly use this form of the uri in uri queries.\n" +
 			"\n" +
 			"  --domain <local|system|network|global|all> Specify query domain (default local + system)\n" +
 			"\n" +
@@ -278,6 +282,9 @@ public class QueryTool {
 				listener = true;
 				keep_running = true;
 				break;
+			case "--raw-uri":
+				raw_uri = true;
+				break;
 			case "--keywords":
 				PropertyKeywordFu.ReadKeywordMappings ();
 
diff --git a/beagle/tools/beagle-query.1 b/beagle/tools/beagle-query.1
index c22b038..e7b58b5 100644
--- a/beagle/tools/beagle-query.1
+++ b/beagle/tools/beagle-query.1
@@ -1,7 +1,7 @@
 .\" beagle-query(1) manpage
 .\"
 .\" Copyright (C) 2005 Novell, Inc.
-.\" Copyright (C) 2008 D Bera <dbera web gmail com>
+.\" Copyright (C) 2009 D Bera <dbera web gmail com>
 .\"
 .TH BEAGLE-QUERY "1" "July 2008" "beagle" "Linux User's Manual"
 .SH NAME
@@ -37,6 +37,10 @@ feeding new matching hits as the system gets aware of them.
 .B --stats-only
 Show only statistics on the number of search results and how long it took to
 get them, and not the results themselves.
+.TP
+.B  --raw-uri
+Display the actual (unescaped) uri used internally.
+Only use this form of the uri in uri queries.
 .SS Other options
 .TP
 .B --keywords



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