diff --git a/Apis/cv-matcher-api/Services/JobTokenService.cs b/Apis/cv-matcher-api/Services/JobTokenService.cs index 37a1e36..b565071 100644 --- a/Apis/cv-matcher-api/Services/JobTokenService.cs +++ b/Apis/cv-matcher-api/Services/JobTokenService.cs @@ -138,23 +138,21 @@ public sealed class JobTokenService : IJobTokenService /// /// Extracts up to 10 meaningful keywords from the CV text using simple heuristics (no LLM). - /// Takes the first 5 usable lines, splits them into words, strips punctuation, and deduplicates. + /// Samples the first 2000 characters (where title/role/skills usually appear), splits by + /// whitespace and common delimiters, strips punctuation, and deduplicates. + /// Works regardless of whether the PDF extractor preserves newlines. /// private static string ExtractKeywords(string cvText) { - var lines = cvText - .Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries) - .Select(l => l.Trim()) - .Where(l => l.Length > 5 && l.Length < 200) - // Skip lines that are purely digits, spaces, and phone/contact punctuation (phone numbers, emails, etc.) - .Where(l => !Regex.IsMatch(l, @"^[\d\s\+\-\(\)\@\.]+$")) - .Take(5) - .ToList(); + // Focus on the header area where name/title/skills typically appear + var sample = cvText.Length > 2000 ? cvText[..2000] : cvText; - var words = lines - .SelectMany(l => l.Split(' ', StringSplitOptions.RemoveEmptyEntries)) - .Select(w => Regex.Replace(w, @"[^\w\-]", "")) + var words = sample + .Split([' ', '\n', '\r', '\t', '|', '/', ',', ';', '(', ')'], StringSplitOptions.RemoveEmptyEntries) + .Select(w => Regex.Replace(w, @"[^\w\-]", "").Trim('-')) .Where(w => w.Length > 2) + .Where(w => !Regex.IsMatch(w, @"^[\d\-]+$")) // skip phone fragments and pure numbers + .Where(w => !w.Contains('@') && !w.Contains('.')) // skip emails and URLs .Distinct(StringComparer.OrdinalIgnoreCase) .Take(10) .ToList();