398
return NO_ITEM_SCORE; // we need an item and query to score on at least
399
}
401
>
const label = accessor.getItemLabel(item);
402
>
if (!label) {
403
return NO_ITEM_SCORE; // we need a label at least
404
}
406
>
const description = accessor.getItemDescription(item);
407
>
408
>
// in order to speed up scoring, we cache the score with a unique hash based on:
409
>
// - label
410
>
// - description (if provided)
411
>
// - whether non-contiguous matching is enabled or not
412
>
// - hash of the query (normalized) values
413
>
const cacheHash = getCacheHash(label, description, allowNonContiguousMatches, query);
414
>
const cached = cache[cacheHash];
415
>
if (cached) {
416
return cached;
417
}
419
>
const itemScore = doScoreItemFuzzy(label, description, accessor.getItemPath(item), query, allowNonContiguousMatches);
420
>
cache[cacheHash] = itemScore;
421
>
422
>
return itemScore;
423
>
}
424
425
>
function doScoreItemFuzzy(label: string, description: string | undefined, path: string | undefined, query: IPreparedQuery, allowNonContiguousMatches: boolean): IItemScore {
fuzzyScorer.ts
426
>
const preferLabelMatches = !path || !query.containsPathSeparator;
427
>
428
>
// Treat identity matches on full path highest
429
>
if (path && (isLinux ? query.pathNormalized === path : equalsIgnoreCase(query.pathNormalized, path))) {
430
return { score: PATH_IDENTITY_SCORE, labelMatch: [{ start: 0, end: label.length }], descriptionMatch: description ? [{ start: 0, end: description.length }] : undefined };
431
}
433
>
// Score: multiple inputs
434
>
if (query.values && query.values.length > 1) {
435
return doScoreItemFuzzyMultiple(label, description, path, query.values, preferLabelMatches, allowNonContiguousMatches);
436
}