From 845bbf55fe5d48293afb159c603a177d00bffb65 Mon Sep 17 00:00:00 2001
From: Joseph Madamba <madamba.joehu@outlook.com>
Date: Thu, 26 Jan 2023 21:22:06 -0800
Subject: [PATCH 1/4] Add failing beatmap listing search on initial open test

---
 .../Visual/Navigation/TestSceneScreenNavigation.cs   | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs b/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs
index 7bde2e747d..0d081e8138 100644
--- a/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs
+++ b/osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs
@@ -563,6 +563,18 @@ namespace osu.Game.Tests.Visual.Navigation
             AddUntilStep("featured artist filter is off", () => !getBeatmapListingOverlay().ChildrenOfType<BeatmapSearchGeneralFilterRow>().First().Current.Contains(SearchGeneral.FeaturedArtists));
         }
 
+        [Test]
+        public void TestBeatmapListingLinkSearchOnInitialOpen()
+        {
+            BeatmapListingOverlay getBeatmapListingOverlay() => Game.ChildrenOfType<BeatmapListingOverlay>().FirstOrDefault();
+
+            AddStep("open beatmap overlay with test query", () => Game.SearchBeatmapSet("test"));
+
+            AddUntilStep("wait for beatmap overlay to load", () => getBeatmapListingOverlay()?.State.Value == Visibility.Visible);
+
+            AddAssert("beatmap overlay sorted by relevance", () => getBeatmapListingOverlay().ChildrenOfType<BeatmapListingSortTabControl>().Single().Current.Value == SortCriteria.Relevance);
+        }
+
         [Test]
         public void TestMainOverlaysClosesNotificationOverlay()
         {

From 610d2f9dc7346ba8d634670f39bb2ffeeffcd037 Mon Sep 17 00:00:00 2001
From: Joseph Madamba <madamba.joehu@outlook.com>
Date: Thu, 26 Jan 2023 21:30:51 -0800
Subject: [PATCH 2/4] Fix beatmap listing potentially not sorting by relevance
 when searching via metadata

---
 .../Overlays/BeatmapListing/BeatmapListingSortTabControl.cs  | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs
index 34e0408db6..0c2637ded3 100644
--- a/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs
+++ b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs
@@ -3,6 +3,7 @@
 
 #nullable disable
 
+using osu.Framework.Allocation;
 using osu.Framework.Bindables;
 using osu.Framework.Graphics.Sprites;
 using osu.Framework.Graphics.UserInterface;
@@ -20,9 +21,9 @@ namespace osu.Game.Overlays.BeatmapListing
         private SearchCategory? lastCategory;
         private bool? lastHasQuery;
 
-        protected override void LoadComplete()
+        [BackgroundDependencyLoader]
+        private void load()
         {
-            base.LoadComplete();
             Reset(SearchCategory.Leaderboard, false);
         }
 

From 0366a8e3482dafe4471ed4b037d84d97519a102d Mon Sep 17 00:00:00 2001
From: Joseph Madamba <madamba.joehu@outlook.com>
Date: Tue, 31 Jan 2023 12:44:44 -0800
Subject: [PATCH 3/4] Only call `Reset()` if `lastCategory` and `lastHasQuery`
 is null

---
 .../BeatmapListing/BeatmapListingSortTabControl.cs       | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs
index 0c2637ded3..a25026b781 100644
--- a/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs
+++ b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs
@@ -3,7 +3,6 @@
 
 #nullable disable
 
-using osu.Framework.Allocation;
 using osu.Framework.Bindables;
 using osu.Framework.Graphics.Sprites;
 using osu.Framework.Graphics.UserInterface;
@@ -21,10 +20,12 @@ namespace osu.Game.Overlays.BeatmapListing
         private SearchCategory? lastCategory;
         private bool? lastHasQuery;
 
-        [BackgroundDependencyLoader]
-        private void load()
+        protected override void LoadComplete()
         {
-            Reset(SearchCategory.Leaderboard, false);
+            base.LoadComplete();
+
+            if (lastCategory == null && lastHasQuery == null)
+                Reset(SearchCategory.Leaderboard, false);
         }
 
         public void Reset(SearchCategory category, bool hasQuery)

From 524aa9162d36e0e8c423f171575848b30e837139 Mon Sep 17 00:00:00 2001
From: Dean Herbert <pe@ppy.sh>
Date: Wed, 1 Feb 2023 19:38:47 +0900
Subject: [PATCH 4/4] Store search parameters as tuple

---
 .../BeatmapListing/BeatmapListingSortTabControl.cs   | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs
index a25026b781..025738710f 100644
--- a/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs
+++ b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs
@@ -17,20 +17,21 @@ namespace osu.Game.Overlays.BeatmapListing
     {
         public readonly Bindable<SortDirection> SortDirection = new Bindable<SortDirection>(Overlays.SortDirection.Descending);
 
-        private SearchCategory? lastCategory;
-        private bool? lastHasQuery;
+        private (SearchCategory category, bool hasQuery)? currentParameters;
 
         protected override void LoadComplete()
         {
             base.LoadComplete();
 
-            if (lastCategory == null && lastHasQuery == null)
+            if (currentParameters == null)
                 Reset(SearchCategory.Leaderboard, false);
         }
 
         public void Reset(SearchCategory category, bool hasQuery)
         {
-            if (category != lastCategory || hasQuery != lastHasQuery)
+            var newParameters = (category, hasQuery);
+
+            if (currentParameters != newParameters)
             {
                 TabControl.Clear();
 
@@ -65,8 +66,7 @@ namespace osu.Game.Overlays.BeatmapListing
             // see: https://github.com/ppy/osu-framework/issues/5412
             TabControl.Current.TriggerChange();
 
-            lastCategory = category;
-            lastHasQuery = hasQuery;
+            currentParameters = newParameters;
         }
 
         protected override SortTabControl CreateControl() => new BeatmapSortTabControl