Skip to content

Fix novelty join on search results and make provider aware - #118

Merged
errkk merged 3 commits into
masterfrom
claude/novelty-search-scoring-lj99mr
Aug 20, 2026
Merged

Fix novelty join on search results and make provider aware#118
errkk merged 3 commits into
masterfrom
claude/novelty-search-scoring-lj99mr

Conversation

@errkk

@errkk errkk commented Aug 20, 2026

Copy link
Copy Markdown
Owner

No description provided.

claude and others added 3 commits August 20, 2026 13:30
get_novelty_for_search_results/1 joins the novelty views onto a raw SQL
VALUES list and zips the rows back onto the track list by position. The
query has no ORDER BY, so Postgres returns rows in join order and every
score lands on the wrong track. Reproduced on PG16.

Writes up the cause, the reproduction, four secondary problems in the
same function (empty result set is a syntax error, hand-rolled quoting,
nil artist raises, view schemas carry an implicit id primary key), the
keyed-lookup replacement, and the test cases to add.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015yYk8F9wZPwjLtc5yNgWn6
get_novelty_for_search_results/1 built a raw SQL VALUES list from the
search results, left joined the novelty views onto it, selected only the
two novelty columns, then zipped the rows back onto the track list by
position. The query has no ORDER BY, so Postgres returns rows in join
order rather than input order and every score lands on the wrong track.
Because the planner probes the VALUES list from the view side, the
low-scoring rows come back first and the brand new tracks systematically
collect them.

Replace it with two keyed lookups merged in Elixir. Association is now by
(provider, external_id) and artist rather than by row position, so result
ordering cannot matter. This also clears four other problems in the same
function: an empty result set built "VALUES )" and was a syntax error, a
nil artist raised in the hand-rolled quoting, escape_quotes/1 was the only
thing separating provider-supplied text from the query, and the view
schemas carried an implicit id primary key that the views do not have.

Also make track novelty provider-aware. recent_plays already carried
provider but track_novelty grouped by external_id alone, so tracks sharing
an id across providers pooled their play counts, and both join sites
matched on external_id alone. Recreate the view grouped by
(external_id, provider) and join on both.

Adds novelty coverage to queue_test, which had none.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015yYk8F9wZPwjLtc5yNgWn6
@errkk
errkk merged commit 62821e9 into master Aug 20, 2026
10 checks passed
@errkk
errkk deleted the claude/novelty-search-scoring-lj99mr branch August 20, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants