-
Notifications
You must be signed in to change notification settings - Fork 27
Develop #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop #65
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,5 @@ | ||
| { | ||
| "KEYWORDS": [ | ||
| "Java", | ||
| "Spring", | ||
| "RabbitMQ", | ||
| "Docker" | ||
| "Java" | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,55 +10,138 @@ function normalizeJob(job, keyword, adapter) { | |||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| function mergeKeywords(existing, incoming) { | ||||||||||||||||||||||||||||||||||||||||
| const keywords = new Set([ | ||||||||||||||||||||||||||||||||||||||||
| ...(existing.keywords || []), | ||||||||||||||||||||||||||||||||||||||||
| ...(existing.keyword ? [existing.keyword] : []), | ||||||||||||||||||||||||||||||||||||||||
| ...(existing.palavraChave ? [existing.palavraChave] : []), | ||||||||||||||||||||||||||||||||||||||||
| ...(incoming.keywords || []), | ||||||||||||||||||||||||||||||||||||||||
| ...(incoming.keyword ? [incoming.keyword] : []), | ||||||||||||||||||||||||||||||||||||||||
| ...(incoming.palavraChave ? [incoming.palavraChave] : []), | ||||||||||||||||||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||||||||||||||||||
| function normalizeComparableText(value) { | ||||||||||||||||||||||||||||||||||||||||
| return String(value || "") | ||||||||||||||||||||||||||||||||||||||||
| .normalize("NFD") | ||||||||||||||||||||||||||||||||||||||||
| .replace(/\p{Diacritic}/gu, "") | ||||||||||||||||||||||||||||||||||||||||
| .toLowerCase() | ||||||||||||||||||||||||||||||||||||||||
| .replace(/[^\p{L}\p{N}]+/gu, " ") | ||||||||||||||||||||||||||||||||||||||||
| .trim() | ||||||||||||||||||||||||||||||||||||||||
| .replace(/\s+/g, " "); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| function normalizeComparableUrl(value) { | ||||||||||||||||||||||||||||||||||||||||
| const rawValue = String(value || "").trim(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if (!rawValue) { | ||||||||||||||||||||||||||||||||||||||||
| return ""; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||
| const parsedUrl = new URL(rawValue); | ||||||||||||||||||||||||||||||||||||||||
| parsedUrl.search = ""; | ||||||||||||||||||||||||||||||||||||||||
| parsedUrl.hash = ""; | ||||||||||||||||||||||||||||||||||||||||
| return `${parsedUrl.origin}${parsedUrl.pathname}`.replace(/\/+$/, ""); | ||||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||||
| return rawValue.split(/[?#]/)[0].replace(/\/+$/, ""); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| function getMergedKeywords(...jobs) { | ||||||||||||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||||||||||||
| ...new Set( | ||||||||||||||||||||||||||||||||||||||||
| jobs.flatMap((job) => | ||||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||||
| ...(Array.isArray(job.keywords) ? job.keywords : []), | ||||||||||||||||||||||||||||||||||||||||
| job.keyword, | ||||||||||||||||||||||||||||||||||||||||
| job.palavraChave, | ||||||||||||||||||||||||||||||||||||||||
| job.palavra, | ||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||
| .filter(Boolean) | ||||||||||||||||||||||||||||||||||||||||
| .map((keyword) => String(keyword).trim()), | ||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const mergedKeywords = [...keywords].filter(Boolean); | ||||||||||||||||||||||||||||||||||||||||
| function getMergedSources(...jobs) { | ||||||||||||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||||||||||||
| ...new Set( | ||||||||||||||||||||||||||||||||||||||||
| jobs.flatMap((job) => | ||||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||||
| ...(Array.isArray(job.sources) ? job.sources : []), | ||||||||||||||||||||||||||||||||||||||||
| job.source, | ||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||
| .filter(Boolean) | ||||||||||||||||||||||||||||||||||||||||
| .map((source) => String(source).trim()), | ||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+60
to
+67
|
||||||||||||||||||||||||||||||||||||||||
| jobs.flatMap((job) => | |
| [ | |
| ...(Array.isArray(job.sources) ? job.sources : []), | |
| job.source, | |
| ] | |
| .filter(Boolean) | |
| .map((source) => String(source).trim()), | |
| ), | |
| jobs.flatMap((job) => { | |
| const normalizedSources = Array.isArray(job.sources) | |
| ? job.sources.flatMap((source) => String(source || "").split(",")) | |
| : []; | |
| const normalizedSource = String(job.source || "").split(","); | |
| return [...normalizedSources, ...normalizedSource] | |
| .map((source) => String(source).trim()) | |
| .filter(Boolean); | |
| }), |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,135 @@ | ||
| import type { Job } from "@/types/jobs"; | ||
| import { useMemo, useState } from "react"; | ||
|
|
||
| function normalizeComparableText(value?: string | null) { | ||
| return String(value || "") | ||
| .normalize("NFD") | ||
| .replace(/\p{Diacritic}/gu, "") | ||
| .toLowerCase() | ||
| .replace(/[^\p{L}\p{N}]+/gu, " ") | ||
| .trim() | ||
| .replace(/\s+/g, " "); | ||
| } | ||
|
|
||
| function normalizeComparableLink(value?: string | null) { | ||
| const rawValue = String(value || "").trim(); | ||
|
|
||
| if (!rawValue) { | ||
| return ""; | ||
| } | ||
|
|
||
| try { | ||
| const parsedUrl = new URL(rawValue); | ||
| parsedUrl.search = ""; | ||
| parsedUrl.hash = ""; | ||
| return `${parsedUrl.origin}${parsedUrl.pathname}`.replace(/\/+$/, ""); | ||
| } catch { | ||
| return rawValue.split(/[?#]/)[0].replace(/\/+$/, ""); | ||
| } | ||
| } | ||
|
|
||
| function splitJobKeywords(job: Job) { | ||
| return [ | ||
| ...new Set( | ||
| [ | ||
| ...(Array.isArray(job.keywords) ? job.keywords : []), | ||
| ...String(job.palavra || "") | ||
| .split(/[,;|]+/) | ||
| .map((keyword) => keyword.trim()), | ||
| ].filter(Boolean), | ||
| ), | ||
| ]; | ||
| } | ||
|
|
||
| function pickPreferredValue(...values: Array<string | null | undefined>) { | ||
| return ( | ||
| values | ||
| .map((value) => String(value || "").trim()) | ||
| .filter(Boolean) | ||
| .sort((left, right) => right.length - left.length)[0] || "" | ||
| ); | ||
| } | ||
|
|
||
| function buildDedupKey(job: Job) { | ||
| const title = normalizeComparableText(job.titulo); | ||
| const company = normalizeComparableText(job.empresa); | ||
| const location = normalizeComparableText(job.local); | ||
|
|
||
| if (title && company && location) { | ||
| return `identity:${title}|${company}|${location}`; | ||
| } | ||
|
|
||
| if (title && company) { | ||
| return `identity:${title}|${company}|${location || "sem-local"}`; | ||
| } | ||
|
|
||
| const link = normalizeComparableLink(job.link); | ||
|
|
||
| if (link) { | ||
| return `url:${link}`; | ||
| } | ||
|
|
||
| return `fallback:${title}|${company}|${location}|${normalizeComparableText(job.source)}`; | ||
| } | ||
|
|
||
| function dedupeJobs(jobs: Job[]) { | ||
| const unique = new Map<string, Job>(); | ||
|
|
||
| for (const job of jobs) { | ||
| const key = buildDedupKey(job); | ||
| const existing = unique.get(key); | ||
|
|
||
| if (!existing) { | ||
| unique.set(key, { | ||
| ...job, | ||
| palavra: splitJobKeywords(job).join(", "), | ||
| }); | ||
| continue; | ||
| } | ||
|
|
||
| const mergedKeywords = [...new Set([...splitJobKeywords(existing), ...splitJobKeywords(job)])]; | ||
| const mergedSources = [ | ||
| ...new Set( | ||
| [...(existing.sources ?? []), ...(job.sources ?? []), existing.source, job.source] | ||
| .map((source) => String(source || "").trim()) | ||
| .filter(Boolean), | ||
| ), | ||
| ]; | ||
|
Comment on lines
+90
to
+97
|
||
|
|
||
| unique.set(key, { | ||
| ...existing, | ||
| ...job, | ||
| titulo: pickPreferredValue(existing.titulo, job.titulo), | ||
| empresa: pickPreferredValue(existing.empresa, job.empresa), | ||
| local: pickPreferredValue(existing.local, job.local), | ||
| link: pickPreferredValue(existing.link, job.link), | ||
| source: mergedSources.join(", ") || existing.source || job.source || "", | ||
| palavra: mergedKeywords.join(", "), | ||
| keywords: mergedKeywords, | ||
| sources: mergedSources.length > 0 ? mergedSources : undefined, | ||
| }); | ||
| } | ||
|
|
||
| return [...unique.values()]; | ||
| } | ||
|
|
||
| export function useJobsFiltering(jobs: Job[]) { | ||
| const [search, setSearch] = useState(""); | ||
| const [keywordFilter, setKeywordFilter] = useState<string[]>([]); | ||
|
|
||
| const dedupedJobs = useMemo(() => dedupeJobs(jobs), [jobs]); | ||
|
|
||
| const keywords = useMemo(() => { | ||
| const values = Array.from(new Set(jobs.map((job) => String(job.palavra || "").trim()).filter(Boolean))); | ||
| const values = Array.from(new Set(dedupedJobs.flatMap((job) => splitJobKeywords(job)))); | ||
| return values.sort((a, b) => a.localeCompare(b)); | ||
| }, [jobs]); | ||
| }, [dedupedJobs]); | ||
|
|
||
| const filteredJobs = useMemo(() => { | ||
| const term = search.trim().toLowerCase(); | ||
| const term = normalizeComparableText(search); | ||
|
|
||
| return jobs.filter((job) => { | ||
| const currentKeyword = String(job.palavra || "").trim(); | ||
| const byKeyword = keywordFilter.length === 0 || keywordFilter.includes(currentKeyword); | ||
| return dedupedJobs.filter((job) => { | ||
| const currentKeywords = splitJobKeywords(job); | ||
| const byKeyword = keywordFilter.length === 0 || keywordFilter.some((keyword) => currentKeywords.includes(keyword)); | ||
| if (!byKeyword) { | ||
| return false; | ||
| } | ||
|
|
@@ -24,13 +138,13 @@ export function useJobsFiltering(jobs: Job[]) { | |
| return true; | ||
| } | ||
|
|
||
| const text = [job.titulo, job.empresa, job.local, job.link, job.palavra] | ||
| .map((value) => String(value || "").toLowerCase()) | ||
| .join(" "); | ||
| const text = normalizeComparableText( | ||
| [job.titulo, job.empresa, job.local, job.link, job.palavra, ...(job.keywords || [])].join(" "), | ||
| ); | ||
|
|
||
| return text.includes(term); | ||
| }); | ||
| }, [jobs, search, keywordFilter]); | ||
| }, [dedupedJobs, search, keywordFilter]); | ||
|
|
||
| return { | ||
| search, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O arquivo versionado
environment.jsonpassa a inicializarKEYWORDScom apenas "Java". ComoparseKeywords()prefere o conteúdo desse arquivo quando existe e não está vazio, isso muda o comportamento padrão do scraper/app para buscar somente uma keyword (em vez do fallbackDEFAULT_KEYWORDSem backend/src/config.js). Se a intenção não é limitar o padrão, considere manter a lista anterior ou deixarKEYWORDSvazio/ausente para permitir o fallback.