Introducing position-based weight calculation

This commit is contained in:
Milorad FIlipović 2024-12-23 17:06:21 +01:00
parent 006e7a07a6
commit e4998dab7e
2 changed files with 9 additions and 2 deletions

View file

@ -236,7 +236,14 @@ export function sublimeSearch<T extends object>(
keys.forEach(({ key, weight }) => { keys.forEach(({ key, weight }) => {
const value = getValue(item, key); const value = getValue(item, key);
if (Array.isArray(value)) { if (Array.isArray(value)) {
values = values.concat(value.map((v) => ({ value: v, weight }))); // Reduce the weight by 10% for subsequent value in the array so we promote results based on the order of values
// e.g. if node has multiple aliases, we want to promote the first alias over the second
values = values.concat(
value.map((v, i) => ({
value: v,
weight: i <= 1 ? weight : weight * (1 - (i - 1) * 0.1),
})),
);
} else if (typeof value === 'string') { } else if (typeof value === 'string') {
values.push({ values.push({
value, value,

View file

@ -11,7 +11,7 @@
} }
] ]
}, },
"alias": ["cpde", "Javascript", "JS", "Python", "Script", "Custom Code", "Function"], "alias": ["cpde", "Function", "Javascript", "JS", "Python", "Script", "Custom Code"],
"subcategories": { "subcategories": {
"Core Nodes": ["Helpers", "Data Transformation"] "Core Nodes": ["Helpers", "Data Transformation"]
} }