-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to search for difficulty names using square brackets #24921
Conversation
internal static void ApplyQueries(FilterCriteria criteria, string query) | ||
{ | ||
while (true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be rewritten to avoid using while(true)
. It's just too dangerous.
I also wonder if regex should even be used for this as it obfuscates things and is likely not adding much function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. I did it without the Regex now, let me know if you think that this is a better solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. Neither solution is really appealing. Will wait for another opinion.
|
||
string performExtraction(ref string query) | ||
{ | ||
var searchTexts = new List<string>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at the point of using lists and string splitting, it's probably less efficient than regex. not sure.
I've simplified this down to something I'm willing to work with. It doesn't support one test you had, but I think that's okay because it's such an edge case already. If you need to be searching for brackets inside difficulty names you should use Will leave this open for review and self-merge at end of day if no bites. |
Just to be sure: there are actual beatmaps wherein the title of the track has square brackets (https://osu.ppy.sh/beatmapsets/355573#osu/787717). Doing what this PR does will break searching them with the square brackets:
I can't quickly check what stable does, but is this to be considered okay? |
Dunno. We could match them in addition I guess? at which point there's likely no meaning to adding the I'm fine with that direction, simplifies things further. |
I mean yes and no, you could still do things like I dunno. Current behaviour is probably fine until someone complains? |
How about diff --git a/osu.Game/Screens/Select/FilterCriteria.cs b/osu.Game/Screens/Select/FilterCriteria.cs
index 5666f9d1d4..46cc654925 100644
--- a/osu.Game/Screens/Select/FilterCriteria.cs
+++ b/osu.Game/Screens/Select/FilterCriteria.cs
@@ -69,28 +69,18 @@ public string SearchText
string remainingText = value;
- // Match either an open difficulty tag to the end of string,
- // or match a closed one with a whitespace after it.
- //
- // To keep things simple, the closing ']' may be included in the match group,
- // and is trimmer post-match.
- foreach (Match quotedSegment in Regex.Matches(value, "(^|\\s)\\[(.*)(\\]\\s|$)"))
- {
- DifficultyName = new OptionalTextFilter
- {
- SearchTerm = quotedSegment.Groups[2].Value.Trim(']')
- };
-
- remainingText = remainingText.Replace(quotedSegment.Value, string.Empty);
- }
-
// First handle quoted segments to ensure we keep inline spaces in exact matches.
- foreach (Match quotedSegment in Regex.Matches(value, "(\"[^\"]+\"[!]?)"))
+ foreach (Match quotedSegment in Regex.Matches(remainingText, "(\"[^\"]+\"[!]?)"))
{
terms.Add(new OptionalTextFilter { SearchTerm = quotedSegment.Value });
remainingText = remainingText.Replace(quotedSegment.Value, string.Empty);
}
+ remainingText =
+ remainingText
+ .Replace("]", " ")
+ .Replace("[", " ");
+
// Then handle the rest splitting on any spaces.
terms.AddRange(remainingText.Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(s => new OptionalTextFilter
{
I think this would cover most scenarios people would be searching for. Still allows searching for bracket inclusion when using quotes or a prefix. |
That would just make square brackets a dead character, wouldn't it? For instance I'd rather just keep what this branch does right now at that point. |
Closes #24855
This adds the ability to search for difficulty names using the following
Regex
:(\s|^)((\[(?>\[(?<level>)|[^[\]]+|\](?<-level>))*(?(level)(?!))\](\s|$))|(\[.*))
The syntax criteria for the difficulty search query are as follows:
[]
). If there is only an opening square bracket, it is treated as if the closing bracket was at the end of the query.Other things to note:
[
. Not sure if that's necessary.I added a bunch of
TestCase
s to make sure the RegEx actually does what it's supposed to do.