mirror of https://github.com/ppy/osu
Merge pull request #30684 from Joehuu/source-filter
Add missing source query filter in song select
This commit is contained in:
commit
5276f77ebd
|
@ -148,6 +148,7 @@ public void TestCriteriaMatchingRangeMax(bool inclusive)
|
||||||
[TestCase("tags too", false)]
|
[TestCase("tags too", false)]
|
||||||
[TestCase("version", false)]
|
[TestCase("version", false)]
|
||||||
[TestCase("an auteur", true)]
|
[TestCase("an auteur", true)]
|
||||||
|
[TestCase("unit", false)]
|
||||||
public void TestCriteriaMatchingTerms(string terms, bool filtered)
|
public void TestCriteriaMatchingTerms(string terms, bool filtered)
|
||||||
{
|
{
|
||||||
var exampleBeatmapInfo = getExampleBeatmap();
|
var exampleBeatmapInfo = getExampleBeatmap();
|
||||||
|
@ -175,6 +176,7 @@ public void TestCriteriaMatchingTerms(string terms, bool filtered)
|
||||||
[TestCase("\"Artist\"!", true)]
|
[TestCase("\"Artist\"!", true)]
|
||||||
[TestCase("\"The Artist\"!", false)]
|
[TestCase("\"The Artist\"!", false)]
|
||||||
[TestCase("\"the artist\"!", false)]
|
[TestCase("\"the artist\"!", false)]
|
||||||
|
[TestCase("\"unit tests\"!", false)]
|
||||||
[TestCase("\"\\\"", true)] // nasty case, covers properly escaping user input in underlying regex.
|
[TestCase("\"\\\"", true)] // nasty case, covers properly escaping user input in underlying regex.
|
||||||
public void TestCriteriaMatchingExactTerms(string terms, bool filtered)
|
public void TestCriteriaMatchingExactTerms(string terms, bool filtered)
|
||||||
{
|
{
|
||||||
|
|
|
@ -501,6 +501,18 @@ public void TestDifficultySearch(string query, int[] expectedBeatmapIndexes)
|
||||||
Assert.That(visibleBeatmaps, Is.EqualTo(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);
|
||||||
|
Assert.AreEqual("unit tests", filterCriteria.Source.SearchTerm);
|
||||||
|
Assert.That(filterCriteria.Source.MatchMode, Is.EqualTo(FilterCriteria.MatchMode.IsolatedPhrase));
|
||||||
|
}
|
||||||
|
|
||||||
private class CustomFilterCriteria : IRulesetFilterCriteria
|
private class CustomFilterCriteria : IRulesetFilterCriteria
|
||||||
{
|
{
|
||||||
public string? CustomValue { get; set; }
|
public string? CustomValue { get; set; }
|
||||||
|
|
|
@ -81,6 +81,7 @@ private bool checkMatch(FilterCriteria criteria)
|
||||||
match &= !criteria.Title.HasFilter || criteria.Title.Matches(BeatmapInfo.Metadata.Title) ||
|
match &= !criteria.Title.HasFilter || criteria.Title.Matches(BeatmapInfo.Metadata.Title) ||
|
||||||
criteria.Title.Matches(BeatmapInfo.Metadata.TitleUnicode);
|
criteria.Title.Matches(BeatmapInfo.Metadata.TitleUnicode);
|
||||||
match &= !criteria.DifficultyName.HasFilter || criteria.DifficultyName.Matches(BeatmapInfo.DifficultyName);
|
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);
|
match &= !criteria.UserStarDifficulty.HasFilter || criteria.UserStarDifficulty.IsInRange(BeatmapInfo.StarRating);
|
||||||
|
|
||||||
if (!match) return false;
|
if (!match) return false;
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class FilterCriteria
|
||||||
public OptionalTextFilter Artist;
|
public OptionalTextFilter Artist;
|
||||||
public OptionalTextFilter Title;
|
public OptionalTextFilter Title;
|
||||||
public OptionalTextFilter DifficultyName;
|
public OptionalTextFilter DifficultyName;
|
||||||
|
public OptionalTextFilter Source;
|
||||||
|
|
||||||
public OptionalRange<double> UserStarDifficulty = new OptionalRange<double>
|
public OptionalRange<double> UserStarDifficulty = new OptionalRange<double>
|
||||||
{
|
{
|
||||||
|
|
|
@ -113,6 +113,9 @@ private static bool tryParseKeywordCriteria(FilterCriteria criteria, string key,
|
||||||
case "diff":
|
case "diff":
|
||||||
return TryUpdateCriteriaText(ref criteria.DifficultyName, op, value);
|
return TryUpdateCriteriaText(ref criteria.DifficultyName, op, value);
|
||||||
|
|
||||||
|
case "source":
|
||||||
|
return TryUpdateCriteriaText(ref criteria.Source, op, value);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return criteria.RulesetCriteria?.TryParseCustomKeywordCriteria(key, op, value) ?? false;
|
return criteria.RulesetCriteria?.TryParseCustomKeywordCriteria(key, op, value) ?? false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue