beagle r4845 - trunk/beagle/beagled



Author: dbera
Date: Sat Jul 19 14:41:10 2008
New Revision: 4845
URL: http://svn.gnome.org/viewvc/beagle?rev=4845&view=rev

Log:
Fixes #543635. Handle quoted queries like artist:abcd"1234 578" or even better example keyword:fixme:folder="my inbox".


Modified:
   trunk/beagle/beagled/PropertyKeywordFu.cs
   trunk/beagle/beagled/QueryStringParser.cs

Modified: trunk/beagle/beagled/PropertyKeywordFu.cs
==============================================================================
--- trunk/beagle/beagled/PropertyKeywordFu.cs	(original)
+++ trunk/beagle/beagled/PropertyKeywordFu.cs	Sat Jul 19 14:41:10 2008
@@ -37,13 +37,10 @@
 
 namespace Beagle.Daemon {
 
-	public class PropertyKeywordFu {
+	public static class PropertyKeywordFu {
 		// mapping
 		private static Hashtable property_table;
 
-		// static class
-		private PropertyKeywordFu () { }
-
 		public static IEnumerable Keys {
 			get { return property_table.Keys; }
 		}

Modified: trunk/beagle/beagled/QueryStringParser.cs
==============================================================================
--- trunk/beagle/beagled/QueryStringParser.cs	(original)
+++ trunk/beagle/beagled/QueryStringParser.cs	Sat Jul 19 14:41:10 2008
@@ -29,14 +29,11 @@
 using System.Text.RegularExpressions;
 
 using Beagle.Util;
-using FSQ=Beagle.Daemon.FileSystemQueryable;
 
 namespace Beagle.Daemon {
 
-	public class QueryStringParser {
+	public static class QueryStringParser {
 		
-		private QueryStringParser () { } // a static class
-
 		private static Regex query_string_regex;
 		private static Regex extension_re;
 
@@ -52,11 +49,11 @@
 				(		# Query Text
 				 (\"([^\"]*)\"?)#  quoted
 				 |		#  or
-				 ([^\s\"]+)	#  unquoted
+				 (([^\s\"]+)(\"([^\"]*)\"?)?) # unquoted followed by optional quoted
 				)
 				";
 			 */
-			string Pattern = "(?<pm>[+-]?) ( (?<key>\\w+) :)? ( (\"(?<quote>[^\"]*)\"?) | (?<unquote>[^\\s\"]+) )";
+			string Pattern = "(?<pm>[+-]?) ( (?<key>\\w+) :)? ( (\"(?<quote>[^\"]*)\"?) | ((?<midquote1>[^\\s\"]+) (\"(?<midquote2>[^\"]*)\"?)?) )";
 	
 			query_string_regex = new Regex (Pattern, RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
 
@@ -91,7 +88,7 @@
 				// ahead to the next part.
 				if ( next.Success
 				    && (next.Groups ["key"].ToString () == "")
-				    && (next.Groups ["unquote"].ToString ().ToUpper () == "OR") ) {
+				    && (next.Groups ["midquote1"].ToString ().ToUpper () == "OR") ) {
 
 					if (or_list == null) {
 						or_list = new ArrayList ();
@@ -159,13 +156,13 @@
 			// m.Groups["pm"]	plus or minus sign 
 			// m.Groups["key"]	keyname
 			// m.Groups["quote"]	quoted string
-			// m.Groups["unquote"]	unquoted string
+			// m.Groups["midquote1"] + m.Groups["midquote2"] quoted midway string also represents unquoted string
 			
 			string query = m.ToString ();
-			string unquote = m.Groups["unquote"].ToString ();
-			string text = m.Groups ["quote"].ToString () + m.Groups ["unquote"].ToString ();	// only one of both is set.
+			// Either quote is set or midquote1 and (optionally) midquote2 is set
+			string text = m.Groups ["quote"].ToString () + m.Groups ["midquote1"].ToString () + m.Groups ["midquote2"].ToString ();
 			string key = m.Groups ["key"].ToString ();
-			
+
 			bool IsProhibited = (m.Groups ["pm"].ToString () == "-");
 				
 
@@ -424,6 +421,24 @@
 
 			return dt_query;
 		}
+
+#if false
+// gmcs QueryStringParser.cs -r:../Util/Util.dll -r:../BeagleClient/Beagle.dll PropertyKeywordFu.cs
+		public static void Main ()
+		{
+			PropertyKeywordFu.ReadKeywordMappings ();
+
+			while (true) {
+				string input = Console.ReadLine ();
+				if (input == String.Empty)
+					continue;
+
+				Console.WriteLine ("Parsing query string '{0}'", input);
+				foreach (QueryPart part in Parse (input))
+					Console.WriteLine (part.ToString ());
+			}
+		}
+#endif
 	}
 }
 



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