UBER-1143: additional skill parsing, increase timeout for filter (#3933)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
Vyacheslav Tumanov 2023-11-03 12:22:28 +05:00 committed by GitHub
parent eafc8f66de
commit 273ecb42ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 3 deletions

View File

@ -346,9 +346,55 @@
const categoriesMap = toIdMap(categories)
const newSkills: TagReference[] = []
const formattedSkills = (doc.skills.map((s) => s.toLowerCase()) ?? []).filter(
(skill) => !namedElements.has(skill)
)
const refactoredSkills = []
if (formattedSkills.length > 0) {
const existingTags = Array.from(namedElements.keys()).filter((x) => x.length > 2)
const regex = /\S+(?:[-+]\S+)+/g
const regexForEmpty = /^((?![a-zA-Zа-яА-Я]).)*$/g
for (let sk of formattedSkills) {
sk = sk.toLowerCase()
const toReplace = [...new Set([...existingTags, ...refactoredSkills])]
.filter((s) => sk.includes(s))
.sort((a, b) => b.length - a.length)
if (toReplace.length > 0) {
for (const replacing of toReplace) {
if (namedElements.has(replacing)) {
refactoredSkills.push(replacing)
sk = sk.replace(replacing, '').trim()
}
}
}
if (sk.includes(' ')) {
const skSplit = sk.split(' ')
for (const spl of skSplit) {
const fixedTitle = regex.test(spl) ? spl.replaceAll(/[+-]/g, '') : spl
if (namedElements.has(fixedTitle)) {
refactoredSkills.push(fixedTitle)
sk = sk.replace(spl, '').trim()
}
if ([...doc.skills, ...refactoredSkills].includes(fixedTitle)) {
sk = sk.replace(spl, '').trim()
}
}
}
if (regex.test(sk)) {
const fixedTitle = sk.replaceAll(/[+-]/g, '')
if (namedElements.has(fixedTitle)) {
refactoredSkills.push(fixedTitle)
sk = ''
}
}
if (!regexForEmpty.test(sk) && !refactoredSkills.includes(sk)) {
refactoredSkills.push(sk)
}
}
}
const skillsToAdd = [...new Set([...doc.skills.map((s) => s.toLowerCase()), ...refactoredSkills])]
// Create missing tag elemnts
for (const s of doc.skills ?? []) {
for (const s of skillsToAdd) {
const title = s.trim().toLowerCase()
let e = namedElements.get(title)
if (e === undefined && shouldCreateNewSkills) {

View File

@ -28,7 +28,7 @@
loc.path[3] = 'talents'
loc.path.length = 4
navigate(loc)
setTimeout(() => setFilterTag(tag), 50)
setTimeout(() => setFilterTag(tag), 200)
}
</script>