fix(qt): local sections match the query, and the ranking learns from the page
Three ranking/search defects, two of them found by the owner driving the app.
1. LOCAL sections showed groups that do not match the query.
Searching "Iro" listed Cynic and Die Toten Hosen under "Artists on Local
Library", and their records under "Albums on Local Library". Neither name nor
album title contains "iro". The cause: the SQL matches at TRACK level -
title OR artist OR album - and the album/artist sections are DERIVED by
grouping the matched tracks, so one track-title hit drags its whole album and
its artist into sections that are supposed to be about albums and artists.
The Qobuz sections beside them do not behave that way, so the local block was
lying about what it was showing. Derived rows are now kept only when the
group itself matches: album title or album artist for albums, name for
artists. The TRACKS section is untouched - a track matching on its title is
exactly what that section is for.
The reference has the same flaw; this is a deliberate divergence from it, on
the owner's report. Recorded as such so no future audit "restores parity" by
putting the noise back.
2. The results page taught the ranking nothing.
The port had exactly ONE record site, the cortinilla row click. The reference
has two - the second fires on any media action while the Search view is
current. Without it the case the whole feature exists for is broken:
search "one metallica" -> right track first -> click. Learned.
search "one" -> Qobuz buries it, so it is not in the dropdown ->
"View more" -> click it on the page -> NOTHING is
learned, and the next "one" is just as bad.
record_page_interaction is gated exactly like the reference: Search view
current, module enabled, non-empty query, and the query is the PAGE's, which
is committed by definition. Hooked into the four crate-level media routers,
each self-gated so every other caller is unaffected.
3. Prefix attribution (contract S-N4, owner ruling R8 option ii).
A cortinilla click was learned against the PAYLOAD's query, which lags what
the user has typed: they keep typing while the previous payload is shown,
then click. That teaches a bucket named after a half-typed word - "annen"
learning from a click made while typing "annenmaykantereit". On the owner's
real store, 25 of 143 buckets are typing prefixes like that, and none will
ever be typed again as a whole query, so the score is simply lost.
The promotion is deliberately narrow: only when the payload's query is a
STRICT PREFIX of the live one. Anything else - box cleared, unrelated text,
a narrowing rather than an extension - is attributed as before, because a
broader rule would start moving interactions between unrelated buckets.
DECAY IS NOT IMPLEMENTED and that is the ruling, not an omission: the max
observed score on a real machine is 6 against a cap of 1000, so nothing is
saturating, and decay would add a tunable constant calibrated on nothing
while visibly reordering results.
Contract: qbz-nix-docs/qt-frontend/2026-08-03-cortinilla-parity, commit S-N4
plus two owner-reported defects.
Gate: build clean, 261/261 tests (3 new pinning the owner's exact "Iro" case).
cc
This commit is contained in:
3 files changed
+188
-7
No files matched your search
@@ -828,6 +828,10 @@ pub(crate) fn sidebar_artwork_window(urls_json: String) {
|
||||
|
||||
/// Open the album detail view: push the nav entry, then fetch + publish.
|
||||
pub(crate) fn open_album(album_id: String) {
|
||||
// Learn from results-page interactions too, not only from the
|
||||
// cortinilla. Self-gated on the Search view being current, so every other
|
||||
// caller of this router is unaffected.
|
||||
search_qt::record_page_interaction("album", &album_id, search_qt::InteractionAction::Open);
|
||||
// A LOCAL or Plex album id is a group key or a path, never a Qobuz catalog
|
||||
// id. Sending one to /album/get returns 404 and the view lands empty — the
|
||||
// mixed Library "All" feed hands both kinds to the same card, so the routing
|
||||
@@ -869,6 +873,10 @@ pub(crate) fn open_album(album_id: String) {
|
||||
|
||||
/// Open the artist detail view: push the nav entry, then fetch + publish.
|
||||
pub(crate) fn open_artist(artist_id: String) {
|
||||
// Learn from results-page interactions too, not only from the
|
||||
// cortinilla. Self-gated on the Search view being current, so every other
|
||||
// caller of this router is unaffected.
|
||||
search_qt::record_page_interaction("artist", &artist_id, search_qt::InteractionAction::Open);
|
||||
if offline_fwd::engine().status().is_offline() {
|
||||
return;
|
||||
}
|
||||
@@ -1217,6 +1225,7 @@ pub(crate) fn enqueue_artist_top() {
|
||||
|
||||
/// Track-row click (Library tracks): one-track queue through the core.
|
||||
pub(crate) fn play_track(track_id: u64) {
|
||||
search_qt::record_page_interaction("track", &track_id.to_string(), search_qt::InteractionAction::Play);
|
||||
let runtime = app();
|
||||
spawn(async move {
|
||||
if let Err(e) = playback_qt::play_single_track(&runtime, track_id).await {
|
||||
@@ -1229,6 +1238,10 @@ pub(crate) fn play_track(track_id: u64) {
|
||||
|
||||
/// Open the playlist detail view (sidebar row / playlist card click).
|
||||
pub(crate) fn open_playlist(playlist_id: String) {
|
||||
// Learn from results-page interactions too, not only from the
|
||||
// cortinilla. Self-gated on the Search view being current, so every other
|
||||
// caller of this router is unaffected.
|
||||
search_qt::record_page_interaction("playlist", &playlist_id, search_qt::InteractionAction::Open);
|
||||
// LOCAL playlists (`local:<uuid>`) route to their own loader and open
|
||||
// REGARDLESS of connectivity. They are the whole feature for people using
|
||||
// QBZ as a player without Qobuz — refusing them while offline would gate
|
||||
|
||||
@@ -109,6 +109,19 @@ pub(crate) fn local_art_split(path: Option<&str>) -> (String, String) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Does any of `fields` contain the (already lowercased) needle?
|
||||
///
|
||||
/// Mirrors what the SQL does — a case-insensitive substring — so the derived
|
||||
/// sections agree with the query that produced the rows. An empty needle
|
||||
/// matches everything, which keeps the function honest for callers that do not
|
||||
/// filter.
|
||||
fn group_matches(needle: &str, fields: &[&str]) -> bool {
|
||||
if needle.is_empty() {
|
||||
return true;
|
||||
}
|
||||
fields.iter().any(|f| f.to_lowercase().contains(needle))
|
||||
}
|
||||
|
||||
/// Group local TRACK rows into local ALBUM rows (`source = "local"`,
|
||||
/// `kind = "album"`).
|
||||
///
|
||||
@@ -120,7 +133,9 @@ pub(crate) fn local_art_split(path: Option<&str>) -> (String, String) {
|
||||
pub(crate) fn derive_local_album_rows(
|
||||
rows: &[qbz_library::LocalTrack],
|
||||
cap: usize,
|
||||
query: &str,
|
||||
) -> (Vec<CortRow>, bool) {
|
||||
let needle = query.trim().to_lowercase();
|
||||
let mut seen: HashSet<String> = HashSet::new();
|
||||
let mut out: Vec<CortRow> = Vec::new();
|
||||
let mut total = 0usize;
|
||||
@@ -138,6 +153,14 @@ pub(crate) fn derive_local_album_rows(
|
||||
} else {
|
||||
t.album_group_title.clone()
|
||||
};
|
||||
// The SQL matches at TRACK level (title OR artist OR album), so a
|
||||
// track-title hit drags its whole album in. Without this the Albums
|
||||
// section lists records whose title and artist have nothing to do with
|
||||
// the query — the section would be lying about what it is showing, and
|
||||
// the Qobuz Albums section beside it does not behave that way.
|
||||
if !group_matches(&needle, &[&title, &local_album_artist(t)]) {
|
||||
continue;
|
||||
}
|
||||
let (art_url, art_path) = local_art_split(t.artwork_path.as_deref());
|
||||
out.push(CortRow {
|
||||
kind: "album".into(),
|
||||
@@ -168,7 +191,9 @@ pub(crate) fn derive_local_album_rows(
|
||||
pub(crate) fn derive_local_artist_rows(
|
||||
rows: &[qbz_library::LocalTrack],
|
||||
cap: usize,
|
||||
query: &str,
|
||||
) -> (Vec<CortRow>, bool) {
|
||||
let needle = query.trim().to_lowercase();
|
||||
let mut seen: HashSet<String> = HashSet::new();
|
||||
let mut out: Vec<CortRow> = Vec::new();
|
||||
let mut total = 0usize;
|
||||
@@ -177,6 +202,12 @@ pub(crate) fn derive_local_artist_rows(
|
||||
if name.is_empty() || !seen.insert(name.to_lowercase()) {
|
||||
continue;
|
||||
}
|
||||
// Same reason as the album section: an artist whose NAME does not
|
||||
// match has no business in an Artists list, however one of their
|
||||
// tracks got matched.
|
||||
if !group_matches(&needle, &[&name]) {
|
||||
continue;
|
||||
}
|
||||
total += 1;
|
||||
if out.len() >= cap {
|
||||
continue;
|
||||
@@ -247,11 +278,12 @@ pub(crate) fn append_local_sections(
|
||||
data: &mut CortinillaData,
|
||||
rows: &[qbz_library::LocalTrack],
|
||||
caps: LocalCaps,
|
||||
query: &str,
|
||||
) {
|
||||
if rows.is_empty() {
|
||||
return;
|
||||
}
|
||||
let (album_rows, albums_more) = derive_local_album_rows(rows, caps.albums);
|
||||
let (album_rows, albums_more) = derive_local_album_rows(rows, caps.albums, query);
|
||||
if !album_rows.is_empty() {
|
||||
data.sections.push(CortSection {
|
||||
title: qbz_i18n::t("Albums on Local Library"),
|
||||
@@ -260,7 +292,7 @@ pub(crate) fn append_local_sections(
|
||||
has_more: albums_more,
|
||||
});
|
||||
}
|
||||
let (artist_rows, artists_more) = derive_local_artist_rows(rows, caps.artists);
|
||||
let (artist_rows, artists_more) = derive_local_artist_rows(rows, caps.artists, query);
|
||||
if !artist_rows.is_empty() {
|
||||
data.sections.push(CortSection {
|
||||
title: qbz_i18n::t("Artists on Local Library"),
|
||||
@@ -293,11 +325,12 @@ pub(crate) fn append_immersive_local_albums(
|
||||
data: &mut CortinillaData,
|
||||
rows: &[qbz_library::LocalTrack],
|
||||
cap: usize,
|
||||
query: &str,
|
||||
) {
|
||||
if rows.is_empty() {
|
||||
return;
|
||||
}
|
||||
let (album_rows, has_more) = derive_local_album_rows(rows, cap);
|
||||
let (album_rows, has_more) = derive_local_album_rows(rows, cap, query);
|
||||
if album_rows.is_empty() {
|
||||
return;
|
||||
}
|
||||
@@ -393,3 +426,66 @@ pub(crate) async fn load_cortinilla_local(
|
||||
);
|
||||
rows
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn track(title: &str, artist: &str, album: &str) -> qbz_library::LocalTrack {
|
||||
let mut t = qbz_library::LocalTrack::default();
|
||||
t.title = title.into();
|
||||
t.artist = artist.into();
|
||||
t.album = album.into();
|
||||
t.album_group_key = format!("{artist}|{album}");
|
||||
t.album_group_title = album.into();
|
||||
t
|
||||
}
|
||||
|
||||
/// The owner's real report: searching "Iro" showed Cynic and Die Toten
|
||||
/// Hosen under "Artists on Local Library", and their records under
|
||||
/// "Albums on Local Library". Neither name contains "iro" - a TRACK of
|
||||
/// theirs matched, and the derivation dragged the whole group in.
|
||||
#[test]
|
||||
fn derived_sections_only_keep_groups_that_match_the_query() {
|
||||
let rows = vec![
|
||||
// Matches on the TRACK title only. Must NOT produce an album or
|
||||
// artist row: neither "Cynic" nor "Uroboric Forms" contains "iro".
|
||||
track("Iroquois Dawn", "Cynic", "Uroboric Forms"),
|
||||
// Matches on the ARTIST name -> belongs in both derived sections.
|
||||
track("Run to the Hills", "Iron Maiden", "The Number of the Beast"),
|
||||
// Matches on the ALBUM title -> album row yes, artist row no.
|
||||
track("Some Song", "El Consorcio", "Iron Canciones"),
|
||||
];
|
||||
|
||||
let (albums, _) = derive_local_album_rows(&rows, 10, "Iro");
|
||||
let album_titles: Vec<&str> = albums.iter().map(|r| r.title.as_str()).collect();
|
||||
assert!(
|
||||
!album_titles.contains(&"Uroboric Forms"),
|
||||
"a track-title match must not pull its album in: {album_titles:?}"
|
||||
);
|
||||
assert!(album_titles.contains(&"The Number of the Beast"), "album-artist match");
|
||||
assert!(album_titles.contains(&"Iron Canciones"), "album-title match");
|
||||
|
||||
let (artists, _) = derive_local_artist_rows(&rows, 10, "Iro");
|
||||
let names: Vec<&str> = artists.iter().map(|r| r.title.as_str()).collect();
|
||||
assert_eq!(names, vec!["Iron Maiden"], "only NAME matches belong here");
|
||||
}
|
||||
|
||||
/// The TRACKS section is unaffected - a track that matched on its title is
|
||||
/// exactly what that section is for.
|
||||
#[test]
|
||||
fn track_rows_are_not_filtered_by_the_group_rule() {
|
||||
let t = track("Iroquois Dawn", "Cynic", "Uroboric Forms");
|
||||
let row = map_local_track_to_cort_row(&t);
|
||||
assert_eq!(row.title, "Iroquois Dawn");
|
||||
assert_eq!(row.kind, "track");
|
||||
assert_eq!(row.source, "local");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_query_filters_nothing() {
|
||||
let rows = vec![track("A", "B", "C")];
|
||||
let (albums, _) = derive_local_album_rows(&rows, 10, "");
|
||||
assert_eq!(albums.len(), 1, "an empty needle must not empty the section");
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,8 @@ use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use cxx_qt_lib::QString;
|
||||
use qbz_app::settings::search_service::{InteractionAction, SearchService};
|
||||
pub(crate) use qbz_app::settings::search_service::InteractionAction;
|
||||
use qbz_app::settings::search_service::SearchService;
|
||||
use qbz_app::shell::AppRuntime;
|
||||
use qbz_core::LoggingAdapter;
|
||||
use qbz_models::{Album, Artist, MostPopularItem, Playlist, SearchAllResults, Track};
|
||||
@@ -865,7 +866,7 @@ pub async fn live(runtime: &Arc<AppRuntime<LoggingAdapter>>, query: &str) {
|
||||
// The on-device sections go LAST, after every Qobuz category, and the
|
||||
// append re-runs assign_flat_indices so their rows get contiguous flat
|
||||
// indices after the Qobuz ones.
|
||||
crate::search_local::append_local_sections(&mut data, &local_rows, caps);
|
||||
crate::search_local::append_local_sections(&mut data, &local_rows, caps, &q);
|
||||
// The RAW rows, kept in lockstep with the payload: the click router plays
|
||||
// the concrete LocalTrack from this snapshot rather than re-resolving an
|
||||
// id, because local artist rows have no id at all.
|
||||
@@ -1044,7 +1045,7 @@ pub fn row_clicked(flat_index: i32) {
|
||||
} else {
|
||||
InteractionAction::Open
|
||||
};
|
||||
record(&data.query, &row.kind, &row.id, action);
|
||||
record(&attribution_query(&data.query), &row.kind, &row.id, action);
|
||||
}
|
||||
// LOCAL rows route through the local seams, never the Qobuz ones: their
|
||||
// ids live in a different space entirely (an album id is a group key, an
|
||||
@@ -1075,6 +1076,77 @@ pub fn row_clicked(flat_index: i32) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Record an interaction made on the SEARCH RESULTS PAGE.
|
||||
///
|
||||
/// The port had exactly ONE record site — the cortinilla row click — so
|
||||
/// anything the user did on the results page taught the ranking nothing. That
|
||||
/// is a bigger hole than it sounds, because it breaks the case the whole
|
||||
/// feature exists for:
|
||||
///
|
||||
/// Search "one metallica" -> the right track is first -> click. Learned.
|
||||
/// Search "one" -> Qobuz buries it among hundreds of "One"s, so it is not
|
||||
/// in the dropdown -> "View more" -> click it on the page -> NOTHING is
|
||||
/// learned, so the next "one" is just as bad.
|
||||
///
|
||||
/// With this, that page click teaches the bucket "one", and the next "one"
|
||||
/// gets the track pulled to the front by `rank_within` before truncation, or
|
||||
/// promoted outright as the top result by `top_for_query`.
|
||||
///
|
||||
/// Gated exactly like the reference (`record_search_interaction`): only while
|
||||
/// the SEARCH view is current, only while the module is enabled, only with a
|
||||
/// non-empty query. The query is the PAGE's, which is the committed one by
|
||||
/// definition — the user pressed Enter or followed a "View more" to get here.
|
||||
///
|
||||
/// LOCAL entities never reach this path: local rows do not appear on the
|
||||
/// results page, and their ids are a different space.
|
||||
pub(crate) fn record_page_interaction(kind: &str, id: &str, action: InteractionAction) {
|
||||
if crate::nav_qt::current_view() != "search" {
|
||||
return;
|
||||
}
|
||||
if !is_enabled() {
|
||||
return;
|
||||
}
|
||||
let query = PAGE
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.as_ref()
|
||||
.map(|p| p.doc.query.clone())
|
||||
.unwrap_or_default();
|
||||
if query.trim().is_empty() {
|
||||
return;
|
||||
}
|
||||
record(&query, kind, id, action);
|
||||
}
|
||||
|
||||
/// Which query a click should be LEARNED against.
|
||||
///
|
||||
/// The payload's query is what produced the rows on screen, but it can lag
|
||||
/// what the user has typed: they keep typing while the previous payload is
|
||||
/// still shown, then click. Attributing to the payload teaches a bucket named
|
||||
/// after a half-typed word — `annen` learning from a click the user made while
|
||||
/// typing `annenmaykantereit`. On the owner's real store, 25 of 143 buckets
|
||||
/// are typing prefixes like that, and none of them will ever be typed again as
|
||||
/// a whole query, so the score is simply lost.
|
||||
///
|
||||
/// The rule is deliberately narrow: promote to the live query ONLY when the
|
||||
/// payload's query is a STRICT PREFIX of it. Anything else — the user cleared
|
||||
/// the box, typed something unrelated, or narrowed rather than extended — is
|
||||
/// attributed as before. A broader rule would start moving interactions
|
||||
/// between unrelated buckets, which is worse than the problem.
|
||||
fn attribution_query(payload_query: &str) -> String {
|
||||
let live = crate::search_bridge::cortinilla_query();
|
||||
let live_key = live.trim();
|
||||
if !live_key.is_empty()
|
||||
&& live_key.len() > payload_query.len()
|
||||
&& live_key
|
||||
.to_lowercase()
|
||||
.starts_with(&payload_query.to_lowercase())
|
||||
{
|
||||
return live_key.to_string();
|
||||
}
|
||||
payload_query.to_string()
|
||||
}
|
||||
|
||||
/// Play a local cortinilla track row from the per-query snapshot.
|
||||
///
|
||||
/// The row id is NOT re-resolved against the database: the snapshot is the
|
||||
@@ -1403,7 +1475,7 @@ async fn imm_load(
|
||||
}
|
||||
}
|
||||
};
|
||||
crate::search_local::append_immersive_local_albums(&mut data, &local_rows, caps.albums);
|
||||
crate::search_local::append_immersive_local_albums(&mut data, &local_rows, caps.albums, &q);
|
||||
|
||||
// Artwork: disk hits inline; misses (Qobuz CDN + Plex thumbs) download in
|
||||
// the background and republish the SAME payload, version-guarded
|
||||
|
||||
Reference in new issue
Block a user