fix(hldp): rank Chinese causal branch queries
This commit is contained in:
parent
a483b2a1b9
commit
fb1096c5ec
2 changed files with 18 additions and 1 deletions
|
|
@ -56,7 +56,18 @@ export function verifyTree(tree) {
|
|||
}
|
||||
|
||||
function terms(query) {
|
||||
return [...new Set(query.toLowerCase().match(/[\p{L}\p{N}_-]+/gu) ?? [])];
|
||||
const raw = query.toLowerCase().match(/[\p{L}\p{N}_-]+/gu) ?? [];
|
||||
const expanded = [];
|
||||
for (const token of raw) {
|
||||
expanded.push(token);
|
||||
const characters = [...token];
|
||||
if (/\p{Script=Han}/u.test(token) && characters.length > 1) {
|
||||
for (let i = 0; i < characters.length - 1; i += 1) {
|
||||
expanded.push(characters.slice(i, i + 2).join(""));
|
||||
}
|
||||
}
|
||||
}
|
||||
return [...new Set(expanded)];
|
||||
}
|
||||
|
||||
export function route(tree, query, max = 3, from = tree.root) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue