fix: find the exact title/author match before the fuzzy candidate cap #56
No reviewers
Labels
No labels
bug
critical
ebook-branch
high
low
main
medium
release-blocker
security
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
jfro/fuzzy_catalog!56
Loading…
Reference in a new issue
No description provided.
Delete branch "jtk/book-matcher-exact"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
BookMatcherran its normalized title/author match over the fuzzy candidate set, which is capped at 200 rows ordered by id and pulls in any book that shares the longest author word or the longest title word. In a catalog with lots of "Love …" books, the real match could land past row 200, and the ebook would then create a duplicate book or link a weaker fuzzy match.Change
exact_candidates/2query, used first. It returns books with the exact raw title and author, or books whose title contains every word of the normalized title and whose author contains the surname (longest word) of any of the ebook's authors. ANDing the words keeps the result small, so the cap here is a generous 1,000 rather than 200.ilikeovertranslate(...), which folds common Latin accents. That way "bronte" still finds "Brontë", the same asnormalize/1does in Elixir, and nounaccentextension or migration is needed.find_normalized/3in Elixir, so what counts as a match hasn't changed. Only the set of books it looks at is bigger and narrower.Tests (210 filler "Love Story N" books by other authors)
mix precommitpasses.Fixes #23
Review from Nye (changes requested)
Blocker:
Should fix (medium, same root cause):
2. With fuzzy off, the old capped candidates/2 + find_normalized fallback is gone, so anything the SQL fold doesn't cover regresses vs main. Example: catalog "Karel Čapek" / ebook "Karel Capek", title "War with the Newts": main finds it via the "newts" title word; this PR returns nil (Č isn't in the list; verified ILIKE '%capek%' on translate('Karel Čapek') = false) -> duplicate book. Same for Czech/Polish/Hungarian/Romanian/Turkish accents. Simplest: on an exact_candidates miss, always run find_normalized over candidates/2 (fuzzy on or off), then find_similar only when fuzzy. One extra query, only on a miss. Add a Čapek-style test.
Nit:
3. translate()+ILIKE '%..%' is a seq scan per ebook (candidates/2 already is). Fine at catalog sizes.
Review from Nye (approved) — re-review at
f7248ccThe blocker is fixed. Ø/ø are out of the SQL translate list, so the DB fold now matches
normalize/1. On an exact_candidates miss,find_normalizednow runs overcandidates/2whether fuzzy is on or off, which restores main's behavior for Č/Ł accents. I traced both new tests: they fail without the fix and pass with it. CI run 71 is green.candidates/2, so an unfolded-accent match behind 200 rows sharing its longest word is still missed. Same as main.normalize/1and the SQL list, so 'Nesbo' matches 'Nesbø' without fuzzy.