From 702266198b011734a5b679f08d079d4e352331d9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 27 Jun 2023 15:21:13 +0900 Subject: [PATCH 1/2] Add missing "title=" search support at song select --- .../NonVisual/Filtering/FilterMatchingTest.cs | 23 ++++++++++++++++++- .../Select/Carousel/CarouselBeatmap.cs | 2 ++ osu.Game/Screens/Select/FilterCriteria.cs | 1 + osu.Game/Screens/Select/FilterQueryParser.cs | 3 +++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/NonVisual/Filtering/FilterMatchingTest.cs b/osu.Game.Tests/NonVisual/Filtering/FilterMatchingTest.cs index d8a56ea478..fe5511add1 100644 --- a/osu.Game.Tests/NonVisual/Filtering/FilterMatchingTest.cs +++ b/osu.Game.Tests/NonVisual/Filtering/FilterMatchingTest.cs @@ -33,7 +33,7 @@ public class FilterMatchingTest Artist = "The Artist", ArtistUnicode = "check unicode too", Title = "Title goes here", - TitleUnicode = "Title goes here", + TitleUnicode = "TitleUnicode goes here", Author = { Username = "The Author" }, Source = "unit tests", Tags = "look for tags too", @@ -204,6 +204,27 @@ public void TestCriteriaMatchingCreator(string creatorName, bool filtered) Assert.AreEqual(filtered, carouselItem.Filtered.Value); } + [Test] + [TestCase("", false)] + [TestCase("Goes", false)] + [TestCase("GOES", false)] + [TestCase("goes", false)] + [TestCase("title goes", false)] + [TestCase("title goes AND then something else", true)] + [TestCase("titleunicode", false)] + [TestCase("unknown", true)] + public void TestCriteriaMatchingTitle(string titleName, bool filtered) + { + var exampleBeatmapInfo = getExampleBeatmap(); + var criteria = new FilterCriteria + { + Title = new FilterCriteria.OptionalTextFilter { SearchTerm = titleName } + }; + var carouselItem = new CarouselBeatmap(exampleBeatmapInfo); + carouselItem.Filter(criteria); + Assert.AreEqual(filtered, carouselItem.Filtered.Value); + } + [Test] [TestCase("", false)] [TestCase("The", false)] diff --git a/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs b/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs index 18931c462f..6917bd1da2 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs @@ -57,6 +57,8 @@ private bool checkMatch(FilterCriteria criteria) match &= !criteria.Creator.HasFilter || criteria.Creator.Matches(BeatmapInfo.Metadata.Author.Username); match &= !criteria.Artist.HasFilter || criteria.Artist.Matches(BeatmapInfo.Metadata.Artist) || criteria.Artist.Matches(BeatmapInfo.Metadata.ArtistUnicode); + match &= !criteria.Title.HasFilter || criteria.Title.Matches(BeatmapInfo.Metadata.Title) || + criteria.Title.Matches(BeatmapInfo.Metadata.TitleUnicode); match &= !criteria.UserStarDifficulty.HasFilter || criteria.UserStarDifficulty.IsInRange(BeatmapInfo.StarRating); diff --git a/osu.Game/Screens/Select/FilterCriteria.cs b/osu.Game/Screens/Select/FilterCriteria.cs index 22780acfc3..680da21dbc 100644 --- a/osu.Game/Screens/Select/FilterCriteria.cs +++ b/osu.Game/Screens/Select/FilterCriteria.cs @@ -31,6 +31,7 @@ public class FilterCriteria public OptionalRange OnlineStatus; public OptionalTextFilter Creator; public OptionalTextFilter Artist; + public OptionalTextFilter Title; public OptionalRange UserStarDifficulty = new OptionalRange { diff --git a/osu.Game/Screens/Select/FilterQueryParser.cs b/osu.Game/Screens/Select/FilterQueryParser.cs index 474a9fdfea..20a5d5d1a6 100644 --- a/osu.Game/Screens/Select/FilterQueryParser.cs +++ b/osu.Game/Screens/Select/FilterQueryParser.cs @@ -73,6 +73,9 @@ private static bool tryParseKeywordCriteria(FilterCriteria criteria, string key, case "artist": return TryUpdateCriteriaText(ref criteria.Artist, op, value); + case "title": + return TryUpdateCriteriaText(ref criteria.Title, op, value); + default: return criteria.RulesetCriteria?.TryParseCustomKeywordCriteria(key, op, value) ?? false; } From 11577d1df08e96008ec9764ea731c5747ae20996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 27 Jun 2023 20:41:03 +0200 Subject: [PATCH 2/2] Add test coverage for title query parsing --- .../NonVisual/Filtering/FilterQueryParserTest.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/osu.Game.Tests/NonVisual/Filtering/FilterQueryParserTest.cs b/osu.Game.Tests/NonVisual/Filtering/FilterQueryParserTest.cs index 46f91f9a67..9f7ba9ac24 100644 --- a/osu.Game.Tests/NonVisual/Filtering/FilterQueryParserTest.cs +++ b/osu.Game.Tests/NonVisual/Filtering/FilterQueryParserTest.cs @@ -251,6 +251,18 @@ public void TestApplyCreatorQueries() Assert.AreEqual("my_fav", filterCriteria.Creator.SearchTerm); } + [Test] + public void TestApplyTitleQueries() + { + const string query = "find me songs with title=\"a certain title\" 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); + Assert.AreEqual("a certain title", filterCriteria.Title.SearchTerm); + Assert.That(filterCriteria.Title.Exact, Is.True); + } + [Test] public void TestApplyArtistQueries() {