After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 573484 - Searches with multiple spaces should be shrinked to one space
Searches with multiple spaces should be shrinked to one space
Status: RESOLVED FIXED
Product: banshee
Classification: Other
Component: general
unspecified
Other All
: Normal minor
: 1.x
Assigned To: Banshee Maintainers
Banshee Maintainers
Depends on:
Blocks:
 
 
Reported: 2009-02-27 22:37 UTC by Andrés G. Aragoneses (IRC: knocte)
Modified: 2009-03-21 01:42 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
fix (3.65 KB, patch)
2009-02-27 22:41 UTC, Andrés G. Aragoneses (IRC: knocte)
needs-work Details | Review
fix v2 (5.68 KB, patch)
2009-02-28 21:19 UTC, Andrés G. Aragoneses (IRC: knocte)
none Details | Review
Collapse spaces in `SearchKey()` (3.12 KB, patch)
2009-03-01 02:51 UTC, John Millikin
none Details | Review
Collapse spaces in `SearchKey()` (v2) (3.60 KB, patch)
2009-03-01 20:11 UTC, John Millikin
none Details | Review
Collapse spaces in `SearchKey()` (v3) (5.16 KB, patch)
2009-03-21 01:23 UTC, John Millikin
committed Details | Review

Description Andrés G. Aragoneses (IRC: knocte) 2009-02-27 22:37:10 UTC
Please describe the problem:
While discussing on bug 570312, we found out a special case that would be interesting to fix on string searches.

Steps to reproduce:
1. Have an album called "A B".
2. Create a new smartplaylist with the album filter to be "A  B " (yes, two spaces in between and a space at the end).



Actual results:
The search doesn't yield results.

Expected results:
Banshee should be a bit smarter.

Does this happen every time?
Yes.

Other information:
Comment 1 Andrés G. Aragoneses (IRC: knocte) 2009-02-27 22:41:59 UTC
Created attachment 129692 [details] [review]
fix

Includes unit tests.
Comment 2 Bertrand Lorentz 2009-02-27 23:20:23 UTC
Why are you incrementing the database version ?
Re-running Migrate_23 will probably just fail.
Comment 3 Andrés G. Aragoneses (IRC: knocte) 2009-02-28 01:22:06 UTC
(In reply to comment #2)
> Why are you incrementing the database version ?

Because if the SearchKey() function changes, the StringQueryValue fields change as well. Look at the patch committed in bug for an example 528498.

> Re-running Migrate_23 will probably just fail.

Why? Migrate_26 does exactly the same operation as Mig_23, because the fields that use SearchKey are the same. So I thought it would be better to reuse.
Comment 4 Andrés G. Aragoneses (IRC: knocte) 2009-02-28 01:23:11 UTC
> (In reply to comment #2)
> ... Look at the patch committed in bug for an example 528498.

Sorry, I meant to say  "Look at the patch committed in bug 528498 for an example".
Comment 5 Bertrand Lorentz 2009-02-28 10:20:27 UTC
Ah, got it : you actually want to call Migrate_24, that's the one which does the updates using HYENA_SEARCH_KEY.
The version number got changed when the patch in bug #528498 was committed.
Comment 6 Andrés G. Aragoneses (IRC: knocte) 2009-02-28 21:19:35 UTC
Created attachment 129751 [details] [review]
fix v2

(In reply to comment #5)
> Ah, got it : you actually want to call Migrate_24, that's the one which does
> the updates using HYENA_SEARCH_KEY.
> The version number got changed when the patch in bug #528498 was committed.
> 

Oh, that's true! Thanks for catching that.
I've updated the patch fixing this and adding one more test (which caused me to change slightly the algorithm again!) :)
Comment 7 John Millikin 2009-03-01 02:51:28 UTC
Created attachment 129767 [details] [review]
Collapse spaces in `SearchKey()`

The tests would be better placed in `Hyena/Hyena/Tests/StringUtilTests.cs` with the other `SearchKey`-related tests. This will also let you avoid mixing unrelated SQL stuff into the test.

Did you mix in another change to `SearchKey()` in your patch? The actual changes required are minimal, and I don't understand what's going on in your version.
Comment 8 Andrés G. Aragoneses (IRC: knocte) 2009-03-01 18:02:49 UTC
(In reply to comment #7)
> Created an attachment (id=129767) [edit]
> Collapse spaces in `SearchKey()`

Thanks for your patch!


> The tests would be better placed in `Hyena/Hyena/Tests/StringUtilTests.cs` with
> the other `SearchKey`-related tests. This will also let you avoid mixing
> unrelated SQL stuff into the test.

Mmm, agreed.

> Did you mix in another change to `SearchKey()` in your patch? The actual
> changes required are minimal, and I don't understand what's going on in your
> version.

What happened is that I implemented it firstly (v1) using the "previous_was_space" bool, then I realised the patch v1 didn't trim spaces if there was punctuation character stripped in between ("a % b" would result in "a  b" instead of "a b"), so I refactored it and found myself setting the previous_was_space in all the places where there was an Append operation, so I decided to centralized the Append operation in just one place, using a helper "to_append" nullable var.

But, now that I see your version, I like your approach better :) The only disadvantage of your version is that it wouldn't work if someone in the future adds a space or a tab as a value of an entry in the ignored_special_cases dictionary. So maybe Gabriel will combine our patches again to cover this hypothetical case? :)
Comment 9 John Millikin 2009-03-01 19:25:41 UTC
> The only disadvantage of your version is that it wouldn't work if someone in
> the future adds a space or a tab as a value of an entry in the
> ignored_special_cases dictionary. So maybe Gabriel will combine our patches
> again to cover this hypothetical case? :)
I don't think this would be a problem. Remember that "continue" will cause the rest of the loop body to be skipped. Spaces and tab characters would never be checked against `ignored_special_cases`.
Comment 10 Andrés G. Aragoneses (IRC: knocte) 2009-03-01 19:38:49 UTC
(In reply to comment #9)
> > The only disadvantage of your version is that it wouldn't work if someone in
> > the future adds a space or a tab as a value of an entry in the
> > ignored_special_cases dictionary. So maybe Gabriel will combine our patches
> > again to cover this hypothetical case? :)
> I don't think this would be a problem. Remember that "continue" will cause the
> rest of the loop body to be skipped. Spaces and tab characters would never be
> checked against `ignored_special_cases`.

I don't mean spaces/tabs as keys of `ignored_special_cases`, but *values* (so, not checked, but returned).
Comment 11 John Millikin 2009-03-01 20:11:50 UTC
Created attachment 129802 [details] [review]
Collapse spaces in `SearchKey()` (v2)

> I don't mean spaces/tabs as keys of `ignored_special_cases`, but *values* (so,
> not checked, but returned).
Ah, good point. New patch to fix this potential issue.
Comment 12 Andrés G. Aragoneses (IRC: knocte) 2009-03-20 21:28:39 UTC
It looks good to me. Should it be committed or we need more reviews?
Comment 13 John Millikin 2009-03-21 01:23:38 UTC
Created attachment 131060 [details] [review]
Collapse spaces in `SearchKey()` (v3)

* Change Trim() to TrimStart().
* Update the database migration for new behavior of Title/Name database fields introduced in bug 528493.
* Add a comment for the interaction of special case and whitespace detection.
Comment 14 Gabriel Burt 2009-03-21 01:38:22 UTC
Thanks John, looks good.