Index: ChangeLog
===================================================================
--- ChangeLog	(revision 5086)
+++ ChangeLog	(working copy)
@@ -1,3 +1,33 @@
+2009-02-27  Andrés G. Aragoneses  <aaragoneses@novell.com>
+
+	Covers BGO#573484 (Searches with multiple spaces should be shrinked to one space).
+
+	* src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs: we change
+	values that use SearchKey() function, so we do the same update as when this func was
+	introduced.
+
+	* src/Libraries/Hyena/Hyena/StringUtil.cs: In SearchKey(), trim the initial string and
+	don't append consecutive spaces inside the string.
+
+	* src/Libraries/Hyena/Hyena.Query/Tests/QueryTests.cs: Added new tests.	
+
 2009-02-27  Gabriel Burt  <gabriel.burt@gmail.com>
 
 	* src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs: Rename
Index: src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
===================================================================
--- src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs	(revision 5086)
+++ src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs	(working copy)
@@ -52,7 +52,7 @@
         // NOTE: Whenever there is a change in ANY of the database schema,
         //       this version MUST be incremented and a migration method
         //       MUST be supplied to match the new version number
-        protected const int CURRENT_VERSION = 25;
+        protected const int CURRENT_VERSION = 26;
         protected const int CURRENT_METADATA_VERSION = 5;
         
 #region Migration Driver
@@ -592,6 +592,29 @@
         
 #endregion
 
+#region Version 26
+
+        [DatabaseVersion (26)]
+        private bool Migrate_26 ()
+        {
+            //only changes values that use SearchKey() function, so we do the same update as when this func was introduced
+            return Migrate_24 ();
+        }
+        
+#endregion
+
 #pragma warning restore 0169
         
 #region Fresh database setup
Index: src/Libraries/Hyena/Hyena/StringUtil.cs
===================================================================
--- src/Libraries/Hyena/Hyena/StringUtil.cs	(revision 5086)
+++ src/Libraries/Hyena/Hyena/StringUtil.cs	(working copy)
@@ -183,23 +183,34 @@
             val = val.ToLower ();
             StringBuilder sb = new StringBuilder ();
             UnicodeCategory category;
-            bool previous_was_latin = false;
+            bool previous_was_latin = false, previous_was_space = false;
             
+
             // Normalizing to KD splits into (base, combining) so we can check for Latin
             // characters and then strip off any NonSpacingMarks following them
-            foreach (char c in val.Normalize (NormalizationForm.FormKD)) {
+            foreach (char c in val.Normalize (NormalizationForm.FormKD).Trim ()) {
                 category = Char.GetUnicodeCategory (c);
+                char? to_append = null;
 
-                if (ignored_special_cases.ContainsKey (c)) {
-                    sb.Append (ignored_special_cases[c]);
+                if (c == ' ') {
+                    if (!previous_was_space)
+                        to_append = c;
+                } else if (ignored_special_cases.ContainsKey (c)) {
+                    to_append = ignored_special_cases [c];
                 } else if (category == UnicodeCategory.OtherPunctuation) {
                     // Skip punctuation
                 } else if (!(previous_was_latin && category == UnicodeCategory.NonSpacingMark)) {
-                    sb.Append (c);
+                    to_append = c;
                 }
 
-                // Can ignore A-Z because we've already lowercased the char
-                previous_was_latin = (c >= 'a' && c <= 'z');
+                if (to_append.HasValue) {
+                    sb.Append (to_append.Value);
+
+                    // Can ignore A-Z because we've already lowercased the char
+                    previous_was_latin = (to_append.Value >= 'a' && to_append.Value <= 'z');
+
+                    previous_was_space = (to_append.Value == ' ');
+                }
             }
             
             return sb.ToString ().Normalize (NormalizationForm.FormKC);
Index: src/Libraries/Hyena/Hyena.Query/Tests/QueryTests.cs
===================================================================
--- src/Libraries/Hyena/Hyena.Query/Tests/QueryTests.cs	(revision 5086)
+++ src/Libraries/Hyena/Hyena.Query/Tests/QueryTests.cs	(working copy)
@@ -217,7 +217,31 @@
                 MimeTypeField.ToSql (StringQueryValue.Contains, val)
             );
         }
-		
+
+        [Test] // http://bugzilla.gnome.org/show_bug.cgi?id=573484
+        public void TrimMultipleSpaces ()
+        {
+            QueryValue val = new StringQueryValue ();
+            val.ParseUserQuery ("   Testing  Spaces  "); //yes, there are some spaces in purpose
+
+            Assert.AreEqual (
+                "(CoreArtists.NameLowered LIKE '%testing spaces%' ESCAPE '\\' AND CoreArtists.NameLowered IS NOT NULL)",
+                ArtistField.ToSql (StringQueryValue.Contains, val)
+            );
+        }
+
+        [Test] // http://bugzilla.gnome.org/show_bug.cgi?id=573484
+        public void TrimMultipleSpacesAndPunctuation ()
+        {
+            QueryValue val = new StringQueryValue ();
+            val.ParseUserQuery ("100 % techno"); //yes, there are some spaces in purpose
+
+            Assert.AreEqual (
+                "(CoreArtists.NameLowered LIKE '%100 techno%' ESCAPE '\\' AND CoreArtists.NameLowered IS NOT NULL)",
+                ArtistField.ToSql (StringQueryValue.Contains, val)
+            );
+        }
+
         [Test]
         // Test behavior issues described in
         // http://bugzilla.gnome.org/show_bug.cgi?id=547078
