From c2b08beae81bebee05ad1decf9de3cd145a55ee9 Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Fri, 15 Nov 2024 22:52:27 -0800 Subject: [PATCH 1/3] Add basic searching by source test --- osu.Game.Tests/NonVisual/Filtering/FilterMatchingTest.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game.Tests/NonVisual/Filtering/FilterMatchingTest.cs b/osu.Game.Tests/NonVisual/Filtering/FilterMatchingTest.cs index 10e0e46f4c..1efcc8542d 100644 --- a/osu.Game.Tests/NonVisual/Filtering/FilterMatchingTest.cs +++ b/osu.Game.Tests/NonVisual/Filtering/FilterMatchingTest.cs @@ -148,6 +148,7 @@ public void TestCriteriaMatchingRangeMax(bool inclusive) [TestCase("tags too", false)] [TestCase("version", false)] [TestCase("an auteur", true)] + [TestCase("unit", false)] public void TestCriteriaMatchingTerms(string terms, bool filtered) { var exampleBeatmapInfo = getExampleBeatmap(); @@ -175,6 +176,7 @@ public void TestCriteriaMatchingTerms(string terms, bool filtered) [TestCase("\"Artist\"!", true)] [TestCase("\"The Artist\"!", false)] [TestCase("\"the artist\"!", false)] + [TestCase("\"unit tests\"!", false)] [TestCase("\"\\\"", true)] // nasty case, covers properly escaping user input in underlying regex. public void TestCriteriaMatchingExactTerms(string terms, bool filtered) { From 7c94973d4a71a9c8841cde154e2c6790341c6970 Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Fri, 15 Nov 2024 22:51:36 -0800 Subject: [PATCH 2/3] Add failing source filter query test --- .../NonVisual/Filtering/FilterQueryParserTest.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/osu.Game.Tests/NonVisual/Filtering/FilterQueryParserTest.cs b/osu.Game.Tests/NonVisual/Filtering/FilterQueryParserTest.cs index c8f063719d..89743b4ea8 100644 --- a/osu.Game.Tests/NonVisual/Filtering/FilterQueryParserTest.cs +++ b/osu.Game.Tests/NonVisual/Filtering/FilterQueryParserTest.cs @@ -501,6 +501,16 @@ public void TestDifficultySearch(string query, int[] expectedBeatmapIndexes) Assert.That(visibleBeatmaps, Is.EqualTo(expectedBeatmapIndexes)); } + [Test] + public void TestApplySourceQueries() + { + const string query = "find me songs with source=\"unit tests\" please"; + var filterCriteria = new FilterCriteria(); + FilterQueryParser.ApplyQueries(filterCriteria, query); + Assert.AreEqual("find me songs with please", filterCriteria.SearchText.Trim()); + Assert.AreEqual(5, filterCriteria.SearchTerms.Length); + } + private class CustomFilterCriteria : IRulesetFilterCriteria { public string? CustomValue { get; set; } From 465cc716d3d755de90af7355c02885ffd51814e6 Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Fri, 15 Nov 2024 22:52:43 -0800 Subject: [PATCH 3/3] Add missing source query filter in song select --- osu.Game.Tests/NonVisual/Filtering/FilterQueryParserTest.cs | 2 ++ osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs | 1 + osu.Game/Screens/Select/FilterCriteria.cs | 1 + osu.Game/Screens/Select/FilterQueryParser.cs | 3 +++ 4 files changed, 7 insertions(+) diff --git a/osu.Game.Tests/NonVisual/Filtering/FilterQueryParserTest.cs b/osu.Game.Tests/NonVisual/Filtering/FilterQueryParserTest.cs index 89743b4ea8..f4e324d7ba 100644 --- a/osu.Game.Tests/NonVisual/Filtering/FilterQueryParserTest.cs +++ b/osu.Game.Tests/NonVisual/Filtering/FilterQueryParserTest.cs @@ -509,6 +509,8 @@ public void TestApplySourceQueries() FilterQueryParser.ApplyQueries(filterCriteria, query); Assert.AreEqual("find me songs with please", filterCriteria.SearchText.Trim()); Assert.AreEqual(5, filterCriteria.SearchTerms.Length); + Assert.AreEqual("unit tests", filterCriteria.Source.SearchTerm); + Assert.That(filterCriteria.Source.MatchMode, Is.EqualTo(FilterCriteria.MatchMode.IsolatedPhrase)); } private class CustomFilterCriteria : IRulesetFilterCriteria diff --git a/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs b/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs index 3947cefb91..c007fa29ed 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs @@ -81,6 +81,7 @@ private bool checkMatch(FilterCriteria criteria) match &= !criteria.Title.HasFilter || criteria.Title.Matches(BeatmapInfo.Metadata.Title) || criteria.Title.Matches(BeatmapInfo.Metadata.TitleUnicode); match &= !criteria.DifficultyName.HasFilter || criteria.DifficultyName.Matches(BeatmapInfo.DifficultyName); + match &= !criteria.Source.HasFilter || criteria.Source.Matches(BeatmapInfo.Metadata.Source); match &= !criteria.UserStarDifficulty.HasFilter || criteria.UserStarDifficulty.IsInRange(BeatmapInfo.StarRating); if (!match) return false; diff --git a/osu.Game/Screens/Select/FilterCriteria.cs b/osu.Game/Screens/Select/FilterCriteria.cs index 77d7ff0e9f..76c0f769f0 100644 --- a/osu.Game/Screens/Select/FilterCriteria.cs +++ b/osu.Game/Screens/Select/FilterCriteria.cs @@ -43,6 +43,7 @@ public class FilterCriteria public OptionalTextFilter Artist; public OptionalTextFilter Title; public OptionalTextFilter DifficultyName; + public OptionalTextFilter Source; public OptionalRange UserStarDifficulty = new OptionalRange { diff --git a/osu.Game/Screens/Select/FilterQueryParser.cs b/osu.Game/Screens/Select/FilterQueryParser.cs index ccffd34dc2..78f3bab114 100644 --- a/osu.Game/Screens/Select/FilterQueryParser.cs +++ b/osu.Game/Screens/Select/FilterQueryParser.cs @@ -113,6 +113,9 @@ private static bool tryParseKeywordCriteria(FilterCriteria criteria, string key, case "diff": return TryUpdateCriteriaText(ref criteria.DifficultyName, op, value); + case "source": + return TryUpdateCriteriaText(ref criteria.Source, op, value); + default: return criteria.RulesetCriteria?.TryParseCustomKeywordCriteria(key, op, value) ?? false; }