mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-07-11 15:21:12 +00:00
fix: CamelCase author names fail automatic search matching (#219)
Co-authored-by: rinseaid <rinseaid@rinseaid.net>
This commit is contained in:
@@ -389,11 +389,12 @@ export class RankingAlgorithm {
|
|||||||
|
|
||||||
// Parse authors from RAW string first (preserving commas for splitting)
|
// Parse authors from RAW string first (preserving commas for splitting)
|
||||||
// Then normalize individual authors for matching
|
// Then normalize individual authors for matching
|
||||||
const requestAuthorRaw = audiobook.author.toLowerCase().replace(/\s+/g, ' ').trim();
|
const parsedAuthors = audiobook.author
|
||||||
const parsedAuthors = requestAuthorRaw
|
.replace(/\s+/g, ' ')
|
||||||
.split(/,|&| and | - /)
|
.trim()
|
||||||
|
.split(/,|&| and | - /i)
|
||||||
.map(a => a.trim())
|
.map(a => a.trim())
|
||||||
.filter(a => a.length > 2 && !['translator', 'narrator'].includes(a));
|
.filter(a => a.length > 2 && !['translator', 'narrator'].includes(a.toLowerCase()));
|
||||||
|
|
||||||
// Normalize parsed authors for matching (handles CamelCase in author names)
|
// Normalize parsed authors for matching (handles CamelCase in author names)
|
||||||
const normalizedAuthors = parsedAuthors.map(a => this.normalizeForMatching(a, characterReplacements));
|
const normalizedAuthors = parsedAuthors.map(a => this.normalizeForMatching(a, characterReplacements));
|
||||||
|
|||||||
@@ -1348,6 +1348,36 @@ describe('ranking-algorithm', () => {
|
|||||||
// Gets partial score from fuzzy matching (title words + author words present)
|
// Gets partial score from fuzzy matching (title words + author words present)
|
||||||
expect(breakdown.matchScore).toBeGreaterThan(30);
|
expect(breakdown.matchScore).toBeGreaterThan(30);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('matches CamelCase author prefix "McGowan" in request author field', () => {
|
||||||
|
const torrent = {
|
||||||
|
...baseTorrent,
|
||||||
|
title: 'The Housekeeper by Suellen McGowan [M4B]',
|
||||||
|
};
|
||||||
|
|
||||||
|
const breakdown = algorithm.getScoreBreakdown(torrent, {
|
||||||
|
title: 'The Housekeeper',
|
||||||
|
author: 'Suellen McGowan',
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
// "McGowan" must survive into normalizeForMatching as "Mc Gowan"
|
||||||
|
// With requireAuthor: true, author presence check must pass
|
||||||
|
expect(breakdown.matchScore).toBeGreaterThanOrEqual(50);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('matches CamelCase author prefix "McFadden" in request author field', () => {
|
||||||
|
const torrent = {
|
||||||
|
...baseTorrent,
|
||||||
|
title: 'The Housemaid - Freida McFadden [M4B]',
|
||||||
|
};
|
||||||
|
|
||||||
|
const breakdown = algorithm.getScoreBreakdown(torrent, {
|
||||||
|
title: 'The Housemaid',
|
||||||
|
author: 'Freida McFadden',
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
expect(breakdown.matchScore).toBeGreaterThanOrEqual(50);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Legacy API Compatibility', () => {
|
describe('Legacy API Compatibility', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user