feat(search): add search type filters for refined results

Backend:
- Add search_type parameter to search_albums, search_tracks, search_artists
- Pass optional type filter to Qobuz API (Performer, Composer, Label, ReleaseName)

Frontend:
- Add SearchFilterType to search state management
- Add filter radio buttons in SearchView (visible when results exist)
- Remove redundant counts from tabs
- Add Clear filter button independent from Clear search
- Filters reset automatically when starting new search or clearing

Filters allow finding performers, composers, and labels that default
search misses (e.g., searching "Nicko McBrain" with Performer filter
shows Iron Maiden tracks)
This commit is contained in:
vicrodh committed 2026-01-25 12:04:49 -06:00
1 parent 6467ca038e
commit 2136a2a0e7
7 files changed
+268 -92

No files matched your search

+66 -18
View File
@@ -195,17 +195,33 @@ impl QobuzClient {
// === Search endpoints ===
/// Search for albums
pub async fn search_albums(&self, query: &str, limit: u32, offset: u32) -> Result<SearchResultsPage<Album>> {
/// Optional search_type: "MainArtist", "Performer", "Composer", "Label", "ReleaseName"
pub async fn search_albums(
&self,
query: &str,
limit: u32,
offset: u32,
search_type: Option<&str>,
) -> Result<SearchResultsPage<Album>> {
let url = endpoints::build_url(paths::ALBUM_SEARCH);
let limit_str = limit.to_string();
let offset_str = offset.to_string();
let mut params: Vec<(&str, &str)> = vec![
("query", query),
("limit", &limit_str),
("offset", &offset_str),
];
if let Some(st) = search_type {
params.push(("type", st));
}
let response: Value = self
.http
.get(&url)
.header("X-App-Id", self.app_id().await?)
.query(&[
("query", query),
("limit", &limit.to_string()),
("offset", &offset.to_string()),
])
.query(&params)
.send()
.await?
.json()
@@ -219,17 +235,33 @@ impl QobuzClient {
}
/// Search for tracks
pub async fn search_tracks(&self, query: &str, limit: u32, offset: u32) -> Result<SearchResultsPage<Track>> {
/// Optional search_type: "MainArtist", "Performer", "Composer", "Label", "ReleaseName"
pub async fn search_tracks(
&self,
query: &str,
limit: u32,
offset: u32,
search_type: Option<&str>,
) -> Result<SearchResultsPage<Track>> {
let url = endpoints::build_url(paths::TRACK_SEARCH);
let limit_str = limit.to_string();
let offset_str = offset.to_string();
let mut params: Vec<(&str, &str)> = vec![
("query", query),
("limit", &limit_str),
("offset", &offset_str),
];
if let Some(st) = search_type {
params.push(("type", st));
}
let response: Value = self
.http
.get(&url)
.header("X-App-Id", self.app_id().await?)
.query(&[
("query", query),
("limit", &limit.to_string()),
("offset", &offset.to_string()),
])
.query(&params)
.send()
.await?
.json()
@@ -243,17 +275,33 @@ impl QobuzClient {
}
/// Search for artists
pub async fn search_artists(&self, query: &str, limit: u32, offset: u32) -> Result<SearchResultsPage<Artist>> {
/// Optional search_type: "MainArtist", "Performer", "Composer", "Label", "ReleaseName"
pub async fn search_artists(
&self,
query: &str,
limit: u32,
offset: u32,
search_type: Option<&str>,
) -> Result<SearchResultsPage<Artist>> {
let url = endpoints::build_url(paths::ARTIST_SEARCH);
let limit_str = limit.to_string();
let offset_str = offset.to_string();
let mut params: Vec<(&str, &str)> = vec![
("query", query),
("limit", &limit_str),
("offset", &offset_str),
];
if let Some(st) = search_type {
params.push(("type", st));
}
let response: Value = self
.http
.get(&url)
.header("X-App-Id", self.app_id().await?)
.query(&[
("query", query),
("limit", &limit.to_string()),
("offset", &offset.to_string()),
])
.query(&params)
.send()
.await?
.json()
+12 -7
View File
@@ -19,11 +19,12 @@ pub async fn search_albums(
query: String,
limit: Option<u32>,
offset: Option<u32>,
search_type: Option<String>,
state: State<'_, AppState>,
) -> Result<SearchResultsPage<Album>, String> {
let client = state.client.lock().await;
client
.search_albums(&query, limit.unwrap_or(20), offset.unwrap_or(0))
.search_albums(&query, limit.unwrap_or(20), offset.unwrap_or(0), search_type.as_deref())
.await
.map_err(|e| e.to_string())
}
@@ -33,11 +34,12 @@ pub async fn search_tracks(
query: String,
limit: Option<u32>,
offset: Option<u32>,
search_type: Option<String>,
state: State<'_, AppState>,
) -> Result<SearchResultsPage<Track>, String> {
let client = state.client.lock().await;
client
.search_tracks(&query, limit.unwrap_or(20), offset.unwrap_or(0))
.search_tracks(&query, limit.unwrap_or(20), offset.unwrap_or(0), search_type.as_deref())
.await
.map_err(|e| e.to_string())
}
@@ -47,11 +49,12 @@ pub async fn search_artists(
query: String,
limit: Option<u32>,
offset: Option<u32>,
search_type: Option<String>,
state: State<'_, AppState>,
) -> Result<SearchResultsPage<Artist>, String> {
let client = state.client.lock().await;
client
.search_artists(&query, limit.unwrap_or(20), offset.unwrap_or(0))
.search_artists(&query, limit.unwrap_or(20), offset.unwrap_or(0), search_type.as_deref())
.await
.map_err(|e| e.to_string())
}
@@ -59,14 +62,16 @@ pub async fn search_artists(
#[tauri::command]
pub async fn search_all(
query: String,
search_type: Option<String>,
state: State<'_, AppState>,
) -> Result<SearchAllResults, String> {
let client = state.client.lock().await;
let st = search_type.as_deref();
let (albums_result, tracks_result, artists_result) = tokio::join!(
client.search_albums(&query, 30, 0),
client.search_tracks(&query, 8, 0),
client.search_artists(&query, 12, 0)
client.search_albums(&query, 30, 0, st),
client.search_tracks(&query, 8, 0, st),
client.search_artists(&query, 12, 0, st)
);
Ok(SearchAllResults {
+2 -2
View File
@@ -329,7 +329,7 @@ async fn search_artist_tracks(
) -> Result<Vec<u64>, String> {
// Search for the artist
let search_results = client
.search_artists(artist_name, 5, 0)
.search_artists(artist_name, 5, 0, None)
.await
.map_err(|e| format!("Search failed: {}", e))?;
@@ -352,7 +352,7 @@ async fn search_artist_tracks(
// Get the artist's top tracks by searching with artist name
let track_results = client
.search_tracks(artist_name, max_tracks as u32, 0)
.search_tracks(artist_name, max_tracks as u32, 0, None)
.await
.map_err(|e| format!("Track search failed: {}", e))?;
+1 -1
View File
@@ -20,7 +20,7 @@ pub async fn match_tracks(
for track in tracks {
let query = format!("{} {}", track.artist, track.title);
let search = client
.search_tracks(&query, SEARCH_LIMIT, 0)
.search_tracks(&query, SEARCH_LIMIT, 0, None)
.await
.map_err(|e| PlaylistImportError::Qobuz(e.to_string()))?;